Chart.js
Chart.js copied to clipboard
[BUG] Bumpy line on smooth data set
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
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)
