chartjs / chartjs-plugin-zoom

Zoom and pan plugin for Chart.js
MIT License
598 stars 327 forks source link

Incorrect drag behavior at the edge of the canvas #897

Closed joshkel closed 1 week ago

joshkel commented 1 week ago

Using https://codepen.io/joshkel/pen/LYwKzwR as an example, if you click somewhere within the chart area and drag the rectangle to the right, then for the 1 pixel or so during which the cursor is at the right edge of the canvas, the drag rectangle's height jumps to an incorrect value.

Observed in Chrome 130.0.6723.119.

From what I can tell, the problem is within getPointPosition; at that edge, the event's target is one of the page's other HTML elements, so the offsetX and offsetY properties that getRelativePosition uses are incorrect, but _isPointInArea still passes, so the corrective of switching to clientX / clientY isn't invoked.

In looking into this, I wonder if Chart.js's getRelativePosition is actually incorrect - or, at least, if it's not intended to be used for events that don't target the canvas - but that's a much larger change. If you'd like me to investigate that further (or raise an issue within the Chart.js repo for further discussion), please let me know.