@@ -57,11 +57,12 @@ function getCenter(chart) {
57
57
}
58
58
59
59
/**
60
- * @param chart The chart instance
61
- * @param {number | {x?: number, y?: number, focalPoint?: {x: number, y: number}} } amount The zoom percentage or percentages and focal point
62
- * @param {string } [transition] Which transition mode to use. Defaults to 'none'
60
+ * @param {import('chart.js').Chart } chart The Chart instance
61
+ * @param {import('../types').ZoomAmount } amount The zoom percentage or percentages and focal point
62
+ * @param {import('chart.js').UpdateMode } [transition] Which transition mode to use. Defaults to 'none'
63
+ * @param {import('../types/options').ZoomTrigger } [trigger] What triggered the zoom. Defaults to 'api'
63
64
*/
64
- export function zoom ( chart , amount , transition = 'none' ) {
65
+ export function zoom ( chart , amount , transition = 'none' , trigger = 'api' ) {
65
66
const { x = 1 , y = 1 , focalPoint = getCenter ( chart ) } = typeof amount === 'number' ? { x : amount , y : amount } : amount ;
66
67
const state = getState ( chart ) ;
67
68
const { options : { limits, zoom : zoomOptions } } = state ;
@@ -72,6 +73,7 @@ export function zoom(chart, amount, transition = 'none') {
72
73
const yEnabled = y !== 1 ;
73
74
const enabledScales = getEnabledScalesByPoint ( zoomOptions , focalPoint , chart ) ;
74
75
76
+ // @ts -expect-error No overload matches this call
75
77
each ( enabledScales || chart . scales , function ( scale ) {
76
78
if ( scale . isHorizontal ( ) && xEnabled ) {
77
79
doZoom ( scale , x , focalPoint , limits ) ;
@@ -82,10 +84,18 @@ export function zoom(chart, amount, transition = 'none') {
82
84
83
85
chart . update ( transition ) ;
84
86
85
- call ( zoomOptions . onZoom , [ { chart} ] ) ;
87
+ // @ts -expect-error args not assignable to unknown[]
88
+ call ( zoomOptions . onZoom , [ { chart, trigger} ] ) ;
86
89
}
87
90
88
- export function zoomRect ( chart , p0 , p1 , transition = 'none' ) {
91
+ /**
92
+ * @param {import('chart.js').Chart } chart The Chart instance
93
+ * @param {import('chart.js').Point } p0 First corner of the rect
94
+ * @param {import('chart.js').Point } p1 Opposite corner of the rect
95
+ * @param {import('chart.js').UpdateMode } [transition]
96
+ * @param {import('../types/options').ZoomTrigger } [trigger] What triggered the zoom. Defaults to 'api'
97
+ */
98
+ export function zoomRect ( chart , p0 , p1 , transition = 'none' , trigger = 'api' ) {
89
99
const state = getState ( chart ) ;
90
100
const { options : { limits, zoom : zoomOptions } } = state ;
91
101
const { mode = 'xy' } = zoomOptions ;
@@ -104,19 +114,32 @@ export function zoomRect(chart, p0, p1, transition = 'none') {
104
114
105
115
chart . update ( transition ) ;
106
116
107
- call ( zoomOptions . onZoom , [ { chart} ] ) ;
117
+ // @ts -expect-error args not assignable to unknown[]
118
+ call ( zoomOptions . onZoom , [ { chart, trigger} ] ) ;
108
119
}
109
120
110
- export function zoomScale ( chart , scaleId , range , transition = 'none' ) {
121
+ /**
122
+ * @param {import('chart.js').Chart } chart The Chart instance
123
+ * @param {string } scaleId
124
+ * @param {import('../types').ScaleRange } range
125
+ * @param {import('chart.js').UpdateMode } [transition]
126
+ * @param {import('../types/options').ZoomTrigger } [trigger] What triggered the zoom. Defaults to 'api'
127
+ */
128
+ export function zoomScale ( chart , scaleId , range , transition = 'none' , trigger = 'api' ) {
111
129
const state = getState ( chart ) ;
112
130
storeOriginalScaleLimits ( chart , state ) ;
113
131
const scale = chart . scales [ scaleId ] ;
114
132
updateRange ( scale , range , undefined , true ) ;
115
133
chart . update ( transition ) ;
116
134
117
- call ( state . options . zoom ?. onZoom , [ { chart} ] ) ;
135
+ // @ts -expect-error args not assignable to unknown[]
136
+ call ( state . options . zoom ?. onZoom , [ { chart, trigger} ] ) ;
118
137
}
119
138
139
+ /**
140
+ * @param {import('chart.js').Chart } chart The Chart instance
141
+ * @param {import('chart.js').UpdateMode } transition
142
+ */
120
143
export function resetZoom ( chart , transition = 'default' ) {
121
144
const state = getState ( chart ) ;
122
145
const originalScaleLimits = storeOriginalScaleLimits ( chart , state ) ;
@@ -134,6 +157,7 @@ export function resetZoom(chart, transition = 'default') {
134
157
} ) ;
135
158
chart . update ( transition ) ;
136
159
160
+ // @ts -expect-error args not assignable to unknown[]
137
161
call ( state . options . zoom . onZoomComplete , [ { chart} ] ) ;
138
162
}
139
163
@@ -146,6 +170,9 @@ function getOriginalRange(state, scaleId) {
146
170
return valueOrDefault ( max . options , max . scale ) - valueOrDefault ( min . options , min . scale ) ;
147
171
}
148
172
173
+ /**
174
+ * @param {import('chart.js').Chart } chart The Chart instance
175
+ */
149
176
export function getZoomLevel ( chart ) {
150
177
const state = getState ( chart ) ;
151
178
let min = 1 ;
@@ -178,6 +205,12 @@ function panScale(scale, delta, limits, state) {
178
205
}
179
206
}
180
207
208
+ /**
209
+ * @param {import('chart.js').Chart } chart The Chart instance
210
+ * @param {import('../types').PanAmount } delta
211
+ * @param {import('chart.js').Scale[] } [enabledScales]
212
+ * @param {import('chart.js').UpdateMode } [transition]
213
+ */
181
214
export function pan ( chart , delta , enabledScales , transition = 'none' ) {
182
215
const { x = 0 , y = 0 } = typeof delta === 'number' ? { x : delta , y : delta } : delta ;
183
216
const state = getState ( chart ) ;
@@ -189,6 +222,7 @@ export function pan(chart, delta, enabledScales, transition = 'none') {
189
222
const xEnabled = x !== 0 ;
190
223
const yEnabled = y !== 0 ;
191
224
225
+ // @ts -expect-error No overload matches this call
192
226
each ( enabledScales || chart . scales , function ( scale ) {
193
227
if ( scale . isHorizontal ( ) && xEnabled ) {
194
228
panScale ( scale , x , limits , state ) ;
@@ -199,9 +233,13 @@ export function pan(chart, delta, enabledScales, transition = 'none') {
199
233
200
234
chart . update ( transition ) ;
201
235
236
+ // @ts -expect-error args not assignable to unknown[]
202
237
call ( onPan , [ { chart} ] ) ;
203
238
}
204
239
240
+ /**
241
+ * @param {import('chart.js').Chart } chart The Chart instance
242
+ */
205
243
export function getInitialScaleBounds ( chart ) {
206
244
const state = getState ( chart ) ;
207
245
storeOriginalScaleLimits ( chart , state ) ;
@@ -214,6 +252,9 @@ export function getInitialScaleBounds(chart) {
214
252
return scaleBounds ;
215
253
}
216
254
255
+ /**
256
+ * @param {import('chart.js').Chart } chart The Chart instance
257
+ */
217
258
export function getZoomedScaleBounds ( chart ) {
218
259
const state = getState ( chart ) ;
219
260
const scaleBounds = { } ;
@@ -224,6 +265,9 @@ export function getZoomedScaleBounds(chart) {
224
265
return scaleBounds ;
225
266
}
226
267
268
+ /**
269
+ * @param {import('chart.js').Chart } chart The Chart instance
270
+ */
227
271
export function isZoomedOrPanned ( chart ) {
228
272
const scaleBounds = getInitialScaleBounds ( chart ) ;
229
273
for ( const scaleId of Object . keys ( chart . scales ) ) {
@@ -241,6 +285,9 @@ export function isZoomedOrPanned(chart) {
241
285
return false ;
242
286
}
243
287
288
+ /**
289
+ * @param {import('chart.js').Chart } chart The Chart instance
290
+ */
244
291
export function isZoomingOrPanning ( chart ) {
245
292
const state = getState ( chart ) ;
246
293
return state . panning || state . dragging ;
0 commit comments