Chart.js icon indicating copy to clipboard operation
Chart.js copied to clipboard

[BUG] Bumpy line on smooth data set

Open Diggsey opened this issue 9 years ago • 1 comments

Expected Behavior

The line should be smooth.

Current Behavior

The line is bumpy.

Possible Solution

Avoid rounding to pixel coordinates before drawing lines.

Steps to Reproduce (for bugs)

https://codepen.io/anon/pen/gxdzjb

Diggsey avatar Aug 26 '17 21:08 Diggsey

Like mentioned as a Possible Solution it suffices to replace the return Math.round(pixel) with return pixel in the function getPixelForValue in the file scale.linear.js. It only causes two minor side effects in the test-suite.

Two values checked in the file core.controller.tests.js (on lines: 762 and 763)

-    expect(meta.data[0]._model.y).toBe(333);
-    expect(meta.data[1]._model.y).toBe(183);
+    expect(meta.data[0]._model.y).toBeCloseToPixel(333);
+    expect(meta.data[1]._model.y).toBeCloseToPixel(183);

and one in the file core.tooltip.tests.js (on line: 806)

// mouse event won't fire as it always rounds to the whole nearest pixel
-    clientY: rect.top + firstPoint._model.y
+    clientY: rect.top + Math.ceil(firstPoint._model.y)

issue_4704

jcopperfield avatar Nov 05 '17 09:11 jcopperfield