chartjs/chartjs-plugin-zoom

Stop catching scroll events when there is no zoom that

tomeronen opened this issue · 0 comments

What do you think about not catching scroll events if there is no zoom that can be done. My use case is that i have 3 charts in a single page.

When i scroll down, i want the charts to zoom in until no zoom can be done and then scroll the content.
When i scroll up, i want the charts to zoom out until no zoom can be done and then scroll the content.

I thought about maybe adding a check if the current y axis value is equal to the limit and the delta is positive/negative.

handlers.js


function wheelPreconditions(chart, event, zoomOptions) {
  // Before preventDefault, check if the modifier key required and pressed
  if (keyNotPressed(getModifierKey(zoomOptions.wheel), event)) {
    call(zoomOptions.onZoomRejected, [{chart, event}]);
    return;
  }

  if (zoomStart(chart, event, zoomOptions) === false) {
    return;
  }

  // Prevent the event from triggering the default behavior (e.g. content scrolling).
 -  if (event.cancelable) {
 -   event.preventDefault();
 - } 

 +  if (event.cancelable && chartCanScroll(chart, event, zoomOptions)) {
 +   event.preventDefault();
 + } 

  // Firefox always fires the wheel event twice:
  // First without the delta and right after that once with the delta properties.
  if (event.deltaY === undefined) {
    return;
  }
  return true;
}