chartjs / chartjs-plugin-zoom

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

onZoomStart is not called for pinch #790

Closed tomeronen closed 2 weeks ago

tomeronen commented 1 year ago

if pinch is enabled, then zoom happens without the onZoomStart being called. I think this is a quick fix. Can i open a PR to add the onZoomStart function before the zoom call?

function handlePinch(chart, state, e) {
  if (state.scale) {
    const {center, pointers} = e;
    // Hammer reports the total scaling. We need the incremental amount
    const zoomPercent = 1 / state.scale * e.scale;
    const rect = e.target.getBoundingClientRect();
    const pinch = pinchAxes(pointers[0], pointers[1]);
    const mode = state.options.zoom.mode;
    const amount = {
      x: pinch.x && directionEnabled(mode, 'x', chart) ? zoomPercent : 1,
      y: pinch.y && directionEnabled(mode, 'y', chart) ? zoomPercent : 1,
      focalPoint: {
        x: center.x - rect.left,
        y: center.y - rect.top
      }
    };

    zoom(chart, amount);

    // Keep track of overall scale
    state.scale = e.scale;
  }
}
kurkle commented 2 weeks ago

Fixed by #810

romor commented 1 week ago

When returning false in the onZoomStart() callback, the zoom operation should be cancelled according documentation.

However, the pinch event is not cancelled for me and the zoom is done although it should be aborted.

Thus, I think this ticket shall not be closed as it is not completely finished.