Skip to content

Commit 679efbb

Browse files
authored
Handle scales removed while panning (#930)
1 parent a257336 commit 679efbb

File tree

2 files changed

+8
-4
lines changed

2 files changed

+8
-4
lines changed

src/hammer.ts

+6-2
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,11 @@ function handlePan(chart: Chart, state: State, e: HammerInput) {
9595
const delta = state.delta
9696
if (delta) {
9797
state.panning = true
98-
pan(chart, { x: e.deltaX - delta.x, y: e.deltaY - delta.y }, state.panScales)
98+
pan(
99+
chart,
100+
{ x: e.deltaX - delta.x, y: e.deltaY - delta.y },
101+
state.panScales && state.panScales.map((i) => chart.scales[i]).filter(Boolean)
102+
)
99103
state.delta = { x: e.deltaX, y: e.deltaY }
100104
}
101105
}
@@ -115,7 +119,7 @@ function startPan(chart: Chart, state: State, event: HammerInput) {
115119
return onPanRejected?.({ chart, event })
116120
}
117121

118-
state.panScales = getEnabledScalesByPoint(state.options.pan, point, chart)
122+
state.panScales = getEnabledScalesByPoint(state.options.pan, point, chart).map((i) => i.id)
119123
state.delta = { x: 0, y: 0 }
120124
handlePan(chart, state, event)
121125
}

src/state.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Chart, Scale, type Point } from 'chart.js'
1+
import { Chart, type Point } from 'chart.js'
22
import type { ZoomPluginOptions } from './options'
33

44
export type ScaleRange = { min: number; max: number }
@@ -36,7 +36,7 @@ export interface State {
3636
filterNextClick?: boolean
3737
scale?: number | null
3838
delta?: Point | null
39-
panScales?: Scale[]
39+
panScales?: string[]
4040
}
4141

4242
const chartStates = new WeakMap<Chart, State>()

0 commit comments

Comments
 (0)