chartjs / chartjs/chartjs-plugin-zoom

Stop catching scroll events when there is no zoom that

Open
#787 0 comments 2 reactions 0 assignees View on GitHub
enhancement
Dominant language
JavaScript
Stars
623
Forks
331
Avg merge
7h 5m
Merged PRs (30d)
7

Description

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;
}

```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.