Skip to content

Commit

Permalink
Check for filterNextClick in evaluating isZoomingOrPanning (#924)
Browse files Browse the repository at this point in the history
  • Loading branch information
joshkel authored Jan 29, 2025
1 parent cf08c6a commit a257336
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
8 changes: 7 additions & 1 deletion src/core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
5 changes: 3 additions & 2 deletions src/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
getZoomedScaleBounds,
isZoomedOrPanned,
isZoomingOrPanning,
isZoomingOrPanningState,
zoomRect,
} from './core'
import { panFunctions, zoomFunctions, zoomRectFunctions } from './scale.types'
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit a257336

Please sign in to comment.