@@ -57,11 +57,12 @@ function getCenter(chart) {
5757}
5858
5959/**
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'
6364 */
64- export function zoom ( chart , amount , transition = 'none' ) {
65+ export function zoom ( chart , amount , transition = 'none' , trigger = 'api' ) {
6566 const { x = 1 , y = 1 , focalPoint = getCenter ( chart ) } = typeof amount === 'number' ? { x : amount , y : amount } : amount ;
6667 const state = getState ( chart ) ;
6768 const { options : { limits, zoom : zoomOptions } } = state ;
@@ -72,6 +73,7 @@ export function zoom(chart, amount, transition = 'none') {
7273 const yEnabled = y !== 1 ;
7374 const enabledScales = getEnabledScalesByPoint ( zoomOptions , focalPoint , chart ) ;
7475
76+ // @ts -expect-error No overload matches this call
7577 each ( enabledScales || chart . scales , function ( scale ) {
7678 if ( scale . isHorizontal ( ) && xEnabled ) {
7779 doZoom ( scale , x , focalPoint , limits ) ;
@@ -82,10 +84,18 @@ export function zoom(chart, amount, transition = 'none') {
8284
8385 chart . update ( transition ) ;
8486
85- call ( zoomOptions . onZoom , [ { chart} ] ) ;
87+ // @ts -expect-error args not assignable to unknown[]
88+ call ( zoomOptions . onZoom , [ { chart, trigger} ] ) ;
8689}
8790
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' ) {
8999 const state = getState ( chart ) ;
90100 const { options : { limits, zoom : zoomOptions } } = state ;
91101 const { mode = 'xy' } = zoomOptions ;
@@ -104,19 +114,32 @@ export function zoomRect(chart, p0, p1, transition = 'none') {
104114
105115 chart . update ( transition ) ;
106116
107- call ( zoomOptions . onZoom , [ { chart} ] ) ;
117+ // @ts -expect-error args not assignable to unknown[]
118+ call ( zoomOptions . onZoom , [ { chart, trigger} ] ) ;
108119}
109120
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' ) {
111129 const state = getState ( chart ) ;
112130 storeOriginalScaleLimits ( chart , state ) ;
113131 const scale = chart . scales [ scaleId ] ;
114132 updateRange ( scale , range , undefined , true ) ;
115133 chart . update ( transition ) ;
116134
117- call ( state . options . zoom ?. onZoom , [ { chart} ] ) ;
135+ // @ts -expect-error args not assignable to unknown[]
136+ call ( state . options . zoom ?. onZoom , [ { chart, trigger} ] ) ;
118137}
119138
139+ /**
140+ * @param {import('chart.js').Chart } chart The Chart instance
141+ * @param {import('chart.js').UpdateMode } transition
142+ */
120143export function resetZoom ( chart , transition = 'default' ) {
121144 const state = getState ( chart ) ;
122145 const originalScaleLimits = storeOriginalScaleLimits ( chart , state ) ;
@@ -134,6 +157,7 @@ export function resetZoom(chart, transition = 'default') {
134157 } ) ;
135158 chart . update ( transition ) ;
136159
160+ // @ts -expect-error args not assignable to unknown[]
137161 call ( state . options . zoom . onZoomComplete , [ { chart} ] ) ;
138162}
139163
@@ -146,6 +170,9 @@ function getOriginalRange(state, scaleId) {
146170 return valueOrDefault ( max . options , max . scale ) - valueOrDefault ( min . options , min . scale ) ;
147171}
148172
173+ /**
174+ * @param {import('chart.js').Chart } chart The Chart instance
175+ */
149176export function getZoomLevel ( chart ) {
150177 const state = getState ( chart ) ;
151178 let min = 1 ;
@@ -178,6 +205,12 @@ function panScale(scale, delta, limits, state) {
178205 }
179206}
180207
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+ */
181214export function pan ( chart , delta , enabledScales , transition = 'none' ) {
182215 const { x = 0 , y = 0 } = typeof delta === 'number' ? { x : delta , y : delta } : delta ;
183216 const state = getState ( chart ) ;
@@ -189,6 +222,7 @@ export function pan(chart, delta, enabledScales, transition = 'none') {
189222 const xEnabled = x !== 0 ;
190223 const yEnabled = y !== 0 ;
191224
225+ // @ts -expect-error No overload matches this call
192226 each ( enabledScales || chart . scales , function ( scale ) {
193227 if ( scale . isHorizontal ( ) && xEnabled ) {
194228 panScale ( scale , x , limits , state ) ;
@@ -199,9 +233,13 @@ export function pan(chart, delta, enabledScales, transition = 'none') {
199233
200234 chart . update ( transition ) ;
201235
236+ // @ts -expect-error args not assignable to unknown[]
202237 call ( onPan , [ { chart} ] ) ;
203238}
204239
240+ /**
241+ * @param {import('chart.js').Chart } chart The Chart instance
242+ */
205243export function getInitialScaleBounds ( chart ) {
206244 const state = getState ( chart ) ;
207245 storeOriginalScaleLimits ( chart , state ) ;
@@ -214,6 +252,9 @@ export function getInitialScaleBounds(chart) {
214252 return scaleBounds ;
215253}
216254
255+ /**
256+ * @param {import('chart.js').Chart } chart The Chart instance
257+ */
217258export function getZoomedScaleBounds ( chart ) {
218259 const state = getState ( chart ) ;
219260 const scaleBounds = { } ;
@@ -224,6 +265,9 @@ export function getZoomedScaleBounds(chart) {
224265 return scaleBounds ;
225266}
226267
268+ /**
269+ * @param {import('chart.js').Chart } chart The Chart instance
270+ */
227271export function isZoomedOrPanned ( chart ) {
228272 const scaleBounds = getInitialScaleBounds ( chart ) ;
229273 for ( const scaleId of Object . keys ( chart . scales ) ) {
@@ -241,6 +285,9 @@ export function isZoomedOrPanned(chart) {
241285 return false ;
242286}
243287
288+ /**
289+ * @param {import('chart.js').Chart } chart The Chart instance
290+ */
244291export function isZoomingOrPanning ( chart ) {
245292 const state = getState ( chart ) ;
246293 return state . panning || state . dragging ;
0 commit comments