Skip to content

Handle scales removed while panning #930

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 15, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions src/hammer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,11 @@ function handlePan(chart: Chart, state: State, e: HammerInput) {
const delta = state.delta
if (delta) {
state.panning = true
pan(chart, { x: e.deltaX - delta.x, y: e.deltaY - delta.y }, state.panScales)
pan(
chart,
{ x: e.deltaX - delta.x, y: e.deltaY - delta.y },
state.panScales && state.panScales.map((i) => chart.scales[i]).filter(Boolean)
)
state.delta = { x: e.deltaX, y: e.deltaY }
}
}
Expand All @@ -115,7 +119,7 @@ function startPan(chart: Chart, state: State, event: HammerInput) {
return onPanRejected?.({ chart, event })
}

state.panScales = getEnabledScalesByPoint(state.options.pan, point, chart)
state.panScales = getEnabledScalesByPoint(state.options.pan, point, chart).map((i) => i.id)
state.delta = { x: 0, y: 0 }
handlePan(chart, state, event)
}
Expand Down
4 changes: 2 additions & 2 deletions src/state.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Chart, Scale, type Point } from 'chart.js'
import { Chart, type Point } from 'chart.js'
import type { ZoomPluginOptions } from './options'

export type ScaleRange = { min: number; max: number }
Expand Down Expand Up @@ -36,7 +36,7 @@ export interface State {
filterNextClick?: boolean
scale?: number | null
delta?: Point | null
panScales?: Scale[]
panScales?: string[]
}

const chartStates = new WeakMap<Chart, State>()
Expand Down
Loading