chartjs / chartjs-plugin-zoom

Zoom and pan plugin for Chart.js
MIT License
579 stars 322 forks source link

Fix zoom outside of chart area #811

Open gopal-panigrahi opened 3 months ago

gopal-panigrahi commented 3 months ago

Fix: #770 Fix: #807

Changes:

  1. Attaches mousemove event to canvas.ownerDocument for calculating drag rectangle even when cursor is outside the chart area.
  2. checks if endpoint of drag rectangle is outside the chart area then endpoint is calculated based on clientX/Y - chartArea.left/top
  3. clips drag rectangle to the chart area.
gopal-panigrahi commented 3 months ago

Hi @kurkle, Please can you review the PR.

zloveless commented 1 month ago

Hi @gopal-panigrahi I believe this would fix an issue we're having in our charts. Is there any portable solution I can try on my end to see if it works?

gopal-panigrahi commented 1 month ago

Hi @zloveless, In our project, I had to create a patch file for these changes, you can try the same. I used the patch-package library.

zloveless commented 1 month ago

Hi @zloveless, In our project, I had to create a patch file for these changes, you can try the same. I used the patch-package library.

Thanks! I found some code in one of the tracking issues on this here... I just used added a callback to onZoomStart() to check if the zoom action is in the chart area. I still wish one of these PR's that fix it would get merged.