Skip to content

Commit

Permalink
Fix non-zoomable charts eating scroll events (chartjs#429)
Browse files Browse the repository at this point in the history
* Fix non-zoomable charts eating scroll events
  • Loading branch information
jacopotediosi authored Mar 9, 2021
1 parent 7c61ddc commit df5b65e
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 8 deletions.
1 change: 1 addition & 0 deletions .eslintrc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,4 @@ plugins: ['html', 'es']

rules:
complexity: ["warn", 10]
max-statements: ["warn", 30]
18 changes: 10 additions & 8 deletions src/plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -442,11 +442,17 @@ var zoomPlugin = {
};

if (Hammer) {
var zoomOptions = chartInstance.$zoom._options.zoom;
var panOptions = chartInstance.$zoom._options.pan;
var mc = new Hammer.Manager(node);
mc.add(new Hammer.Pinch());
mc.add(new Hammer.Pan({
threshold: panThreshold
}));
if (zoomOptions && zoomOptions.enabled) {
mc.add(new Hammer.Pinch());
}
if (panOptions && panOptions.enabled) {
mc.add(new Hammer.Pan({
threshold: panThreshold
}));
}

// Hammer reports the total scaling. We need the incremental amount
var currentPinchScaling;
Expand Down Expand Up @@ -477,7 +483,6 @@ var zoomPlugin = {

doZoom(chartInstance, diff, diff, center, xy);

var zoomOptions = chartInstance.$zoom._options.zoom;
if (typeof zoomOptions.onZoom === 'function') {
zoomOptions.onZoom({chart: chartInstance});
}
Expand All @@ -493,7 +498,6 @@ var zoomPlugin = {
mc.on('pinchend', function(e) {
handlePinch(e);
currentPinchScaling = null; // reset
var zoomOptions = chartInstance.$zoom._options.zoom;
if (typeof zoomOptions.onZoomComplete === 'function') {
zoomOptions.onZoomComplete({chart: chartInstance});
}
Expand Down Expand Up @@ -525,8 +529,6 @@ var zoomPlugin = {
setTimeout(function() {
panning = false;
}, 500);

var panOptions = chartInstance.$zoom._options.pan;
if (typeof panOptions.onPanComplete === 'function') {
panOptions.onPanComplete({chart: chartInstance});
}
Expand Down

0 comments on commit df5b65e

Please sign in to comment.