diff --git a/src/core.ts b/src/core.ts index b83d8510..1221d9cc 100644 --- a/src/core.ts +++ b/src/core.ts @@ -274,7 +274,13 @@ export function isZoomedOrPanned(chart: Chart) { return false } +export function isZoomingOrPanningState(state: State) { + return state.panning || state.dragging +} + export function isZoomingOrPanning(chart: Chart) { const state = getState(chart) - return state.panning || state.dragging + // From the perspective of outside callers, zooming and panning are still + // active if we haven't yet cleared the next click. + return !!(isZoomingOrPanningState(state) || state.filterNextClick) } diff --git a/src/plugin.ts b/src/plugin.ts index 7b2ea447..74c333be 100644 --- a/src/plugin.ts +++ b/src/plugin.ts @@ -11,6 +11,7 @@ import { getZoomedScaleBounds, isZoomedOrPanned, isZoomingOrPanning, + isZoomingOrPanningState, zoomRect, } from './core' import { panFunctions, zoomFunctions, zoomRectFunctions } from './scale.types' @@ -97,13 +98,13 @@ export default { chart: Chart, { event }: { event: ChartEvent; replay: boolean; cancelable: true; inChartArea: boolean } ): boolean | void { - if (isZoomingOrPanning(chart)) { + const state = getState(chart) + if (isZoomingOrPanningState(state)) { // 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