11'use strict' ;
22
3- import Chart from 'chart.js' ;
3+ import { clone , each , isNullOrUndef , merge } from 'chart.js/helpers ' ;
44import Hammer from 'hammerjs' ;
55
6- var helpers = Chart . helpers ;
7-
8- // Take the zoom namespace of Chart
9- var zoomNS = Chart . Zoom = Chart . Zoom || { } ;
6+ // Zoom namespace (kept under Chart prior to Chart.js 3)
7+ var zoomNS = { } ;
108
119// Where we store functions to handle different scale types
1210var zoomFunctions = zoomNS . zoomFunctions = zoomNS . zoomFunctions || { } ;
@@ -21,7 +19,7 @@ function resolveOptions(chart, options) {
2119 deprecatedOptions . zoom = chart . options . zoom ;
2220 }
2321 var props = chart . $zoom ;
24- options = props . _options = helpers . merge ( { } , [ options , deprecatedOptions ] ) ;
22+ options = props . _options = merge ( { } , [ options , deprecatedOptions ] ) ;
2523
2624 // Install listeners. Do this dynamically based on options so that we can turn zoom on and off
2725 // We also want to make sure listeners aren't always on. E.g. if you're scrolling down a page
@@ -46,12 +44,12 @@ function resolveOptions(chart, options) {
4644
4745function storeOriginalOptions ( chart ) {
4846 var originalOptions = chart . $zoom . _originalOptions ;
49- helpers . each ( chart . scales , function ( scale ) {
47+ each ( chart . scales , function ( scale ) {
5048 if ( ! originalOptions [ scale . id ] ) {
51- originalOptions [ scale . id ] = helpers . clone ( scale . options ) ;
49+ originalOptions [ scale . id ] = clone ( scale . options ) ;
5250 }
5351 } ) ;
54- helpers . each ( originalOptions , function ( opt , key ) {
52+ each ( originalOptions , function ( opt , key ) {
5553 if ( ! chart . scales [ key ] ) {
5654 delete originalOptions [ key ] ;
5755 }
@@ -77,7 +75,7 @@ function directionEnabled(mode, dir, chart) {
7775
7876function rangeMaxLimiter ( zoomPanOptions , newMax ) {
7977 if ( zoomPanOptions . scaleAxes && zoomPanOptions . rangeMax &&
80- ! helpers . isNullOrUndef ( zoomPanOptions . rangeMax [ zoomPanOptions . scaleAxes ] ) ) {
78+ ! isNullOrUndef ( zoomPanOptions . rangeMax [ zoomPanOptions . scaleAxes ] ) ) {
8179 var rangeMax = zoomPanOptions . rangeMax [ zoomPanOptions . scaleAxes ] ;
8280 if ( newMax > rangeMax ) {
8381 newMax = rangeMax ;
@@ -88,7 +86,7 @@ function rangeMaxLimiter(zoomPanOptions, newMax) {
8886
8987function rangeMinLimiter ( zoomPanOptions , newMin ) {
9088 if ( zoomPanOptions . scaleAxes && zoomPanOptions . rangeMin &&
91- ! helpers . isNullOrUndef ( zoomPanOptions . rangeMin [ zoomPanOptions . scaleAxes ] ) ) {
89+ ! isNullOrUndef ( zoomPanOptions . rangeMin [ zoomPanOptions . scaleAxes ] ) ) {
9290 var rangeMin = zoomPanOptions . rangeMin [ zoomPanOptions . scaleAxes ] ;
9391 if ( newMin < rangeMin ) {
9492 newMin = rangeMin ;
@@ -183,7 +181,7 @@ function doZoom(chart, percentZoomX, percentZoomY, focalPoint, whichAxes, animat
183181 // Do the zoom here
184182 var zoomMode = typeof zoomOptions . mode === 'function' ? zoomOptions . mode ( { chart : chart } ) : zoomOptions . mode ;
185183
186- // Which axe should be modified when figers were used.
184+ // Which axes should be modified when fingers were used.
187185 var _whichAxes ;
188186 if ( zoomMode === 'xy' && whichAxes !== undefined ) {
189187 // based on fingers positions
@@ -193,7 +191,7 @@ function doZoom(chart, percentZoomX, percentZoomY, focalPoint, whichAxes, animat
193191 _whichAxes = 'xy' ;
194192 }
195193
196- helpers . each ( chart . scales , function ( scale ) {
194+ each ( chart . scales , function ( scale ) {
197195 if ( scale . isHorizontal ( ) && directionEnabled ( zoomMode , 'x' , chart ) && directionEnabled ( _whichAxes , 'x' , chart ) ) {
198196 zoomOptions . scaleAxes = 'x' ;
199197 zoomScale ( scale , percentZoomX , focalPoint , zoomOptions ) ;
@@ -254,11 +252,11 @@ function panNumericalScale(scale, delta, panOptions) {
254252 var diff ;
255253
256254 if ( panOptions . scaleAxes && panOptions . rangeMin &&
257- ! helpers . isNullOrUndef ( panOptions . rangeMin [ panOptions . scaleAxes ] ) ) {
255+ ! isNullOrUndef ( panOptions . rangeMin [ panOptions . scaleAxes ] ) ) {
258256 rangeMin = panOptions . rangeMin [ panOptions . scaleAxes ] ;
259257 }
260258 if ( panOptions . scaleAxes && panOptions . rangeMax &&
261- ! helpers . isNullOrUndef ( panOptions . rangeMax [ panOptions . scaleAxes ] ) ) {
259+ ! isNullOrUndef ( panOptions . rangeMax [ panOptions . scaleAxes ] ) ) {
262260 rangeMax = panOptions . rangeMax [ panOptions . scaleAxes ] ;
263261 }
264262
@@ -289,7 +287,7 @@ function doPan(chartInstance, deltaX, deltaY) {
289287 if ( panOptions . enabled ) {
290288 var panMode = typeof panOptions . mode === 'function' ? panOptions . mode ( { chart : chartInstance } ) : panOptions . mode ;
291289
292- helpers . each ( chartInstance . scales , function ( scale ) {
290+ each ( chartInstance . scales , function ( scale ) {
293291 if ( scale . isHorizontal ( ) && directionEnabled ( panMode , 'x' , chartInstance ) && deltaX !== 0 ) {
294292 panOptions . scaleAxes = 'x' ;
295293 panScale ( scale , deltaX , panOptions ) ;
@@ -580,7 +578,7 @@ var zoomPlugin = {
580578 chartInstance . resetZoom = function ( ) {
581579 storeOriginalOptions ( chartInstance ) ;
582580 var originalOptions = chartInstance . $zoom . _originalOptions ;
583- helpers . each ( chartInstance . scales , function ( scale ) {
581+ each ( chartInstance . scales , function ( scale ) {
584582
585583 var scaleOptions = scale . options ;
586584 if ( originalOptions [ scale . id ] ) {
@@ -671,5 +669,4 @@ var zoomPlugin = {
671669 }
672670} ;
673671
674- Chart . register ( zoomPlugin ) ;
675672export default zoomPlugin ;
0 commit comments