Skip to content

Commit

Permalink
fix: filter only one click after drag/pan is completed
Browse files Browse the repository at this point in the history
  • Loading branch information
kurkle committed Nov 18, 2024
1 parent 08844c2 commit ff0a9ab
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 4 deletions.
4 changes: 2 additions & 2 deletions src/hammer.js
Original file line number Diff line number Diff line change
Expand Up @@ -107,14 +107,14 @@ function startPan(chart, state, event) {

state.panScales = getEnabledScalesByPoint(state.options.pan, point, chart);
state.delta = {x: 0, y: 0};
clearTimeout(state.panEndTimeout);
handlePan(chart, state, event);
}

function endPan(chart, state) {
state.delta = null;
if (state.panning) {
state.panEndTimeout = setTimeout(() => (state.panning = false), 500);
state.panning = false;
state.filterNextClick = true;
call(state.options.pan.onPanComplete, [{chart}]);
}
}
Expand Down
3 changes: 2 additions & 1 deletion src/handlers.js
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,8 @@ export function mouseUp(chart, event) {

zoomRect(chart, {x: rect.left, y: rect.top}, {x: rect.right, y: rect.bottom}, 'zoom');

setTimeout(() => (state.dragging = false), 500);
state.dragging = false;
state.filterNextClick = true;
call(onZoomComplete, [{chart}]);
}

Expand Down
10 changes: 9 additions & 1 deletion src/plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,11 +87,19 @@ export default {
chart.isZoomingOrPanning = () => isZoomingOrPanning(chart);
},

beforeEvent(chart) {
beforeEvent(chart, {event}) {
if (isZoomingOrPanning(chart)) {
// cancel any event handling while panning or dragging
return false;
}
// cancel the next click or mouseup after drag or pan
if (event.type === 'click' || event.type === 'mouseup') {
const state = getState(chart);
if (state.filterNextClick) {
state.filterNextClick = false;
return false;
}
}
},

beforeUpdate: function(chart, args, options) {
Expand Down

0 comments on commit ff0a9ab

Please sign in to comment.