@@ -3,7 +3,7 @@ import { panFunctions, updateRange, zoomFunctions, zoomRectFunctions } from './s
33import { getState , type OriginalScaleLimits , type ScaleRange , type State , type UpdatedScaleLimits } from './state.js'
44import { directionEnabled , getEnabledScalesByPoint } from './utils.js'
55import type { Chart , Point , Scale , UpdateMode } from 'chart.js'
6- import type { LimitOptions , ZoomTrigger } from './options.js'
6+ import type { LimitOptions , PanTrigger , ZoomTrigger } from './options.js'
77import type { ZoomAmount } from './types.js'
88
99function shouldUpdateScaleLimits (
@@ -78,18 +78,21 @@ export function zoom(chart: Chart, amount: ZoomAmount, transition: UpdateMode =
7878 const xEnabled = x !== 1
7979 const yEnabled = y !== 1
8080 const enabledScales = getEnabledScalesByPoint ( zoomOptions , focalPoint , chart )
81+ const actualAmount = { x : 1 , y : 1 }
8182
8283 for ( const scale of enabledScales ) {
8384 if ( scale . isHorizontal ( ) && xEnabled ) {
85+ actualAmount . x = x
8486 doZoom ( scale , x , focalPoint , limits )
8587 } else if ( ! scale . isHorizontal ( ) && yEnabled ) {
88+ actualAmount . y = y
8689 doZoom ( scale , y , focalPoint , limits )
8790 }
8891 }
8992
9093 chart . update ( transition )
9194
92- zoomOptions ?. onZoom ?.( { chart, trigger } )
95+ zoomOptions ?. onZoom ?.( { chart, trigger, amount : actualAmount } )
9396}
9497
9598export function zoomRect (
@@ -207,7 +210,7 @@ function panScale(scale: Scale, delta: number, limits: LimitOptions, state: Stat
207210
208211type PanAmount = number | Partial < Point >
209212
210- export function pan ( chart : Chart , delta : PanAmount , enabledScales ?: Scale [ ] , transition : UpdateMode = 'none' ) {
213+ export function pan ( chart : Chart , delta : PanAmount , enabledScales ?: Scale [ ] , transition : UpdateMode = 'none' , trigger : PanTrigger = "other" ) {
211214 const { x = 0 , y = 0 } = typeof delta === 'number' ? { x : delta , y : delta } : delta
212215 const state = getState ( chart )
213216 const {
@@ -232,7 +235,7 @@ export function pan(chart: Chart, delta: PanAmount, enabledScales?: Scale[], tra
232235
233236 chart . update ( transition )
234237
235- onPan ?.( { chart } )
238+ onPan ?.( { chart, trigger , delta } )
236239}
237240
238241export function getInitialScaleBounds ( chart : Chart ) {
0 commit comments