@@ -153,21 +153,28 @@ function zoomScale(scale, zoom, center, zoomOptions) {
153153 }
154154}
155155
156- function doZoom ( chartInstance , zoomX , zoomY , center , whichAxes ) {
157- var ca = chartInstance . chartArea ;
158- if ( ! center ) {
159- center = {
156+ /**
157+ * @param chart The chart instance
158+ * @param {number } percentZoomX The zoom percentage in the x direction
159+ * @param {number } percentZoomY The zoom percentage in the y direction
160+ * @param {{x: number, y: number} } focalPoint The x and y coordinates of zoom focal point. The point which doesn't change while zooming. E.g. the location of the mouse cursor when "drag: false"
161+ * @param {string } whichAxes `xy`, 'x', or 'y'
162+ */
163+ function doZoom ( chart , percentZoomX , percentZoomY , focalPoint , whichAxes ) {
164+ var ca = chart . chartArea ;
165+ if ( ! focalPoint ) {
166+ focalPoint = {
160167 x : ( ca . left + ca . right ) / 2 ,
161168 y : ( ca . top + ca . bottom ) / 2 ,
162169 } ;
163170 }
164171
165- var zoomOptions = chartInstance . options . zoom ;
172+ var zoomOptions = chart . options . zoom ;
166173
167174 if ( zoomOptions && helpers . getValueOrDefault ( zoomOptions . enabled , defaultOptions . zoom . enabled ) ) {
168175 // Do the zoom here
169- var zoomMode = helpers . getValueOrDefault ( chartInstance . options . zoom . mode , defaultOptions . zoom . mode ) ;
170- zoomOptions . sensitivity = helpers . getValueOrDefault ( chartInstance . options . zoom . sensitivity , defaultOptions . zoom . sensitivity ) ;
176+ var zoomMode = helpers . getValueOrDefault ( chart . options . zoom . mode , defaultOptions . zoom . mode ) ;
177+ zoomOptions . sensitivity = helpers . getValueOrDefault ( chart . options . zoom . sensitivity , defaultOptions . zoom . sensitivity ) ;
171178
172179 // Which axe should be modified when figers were used.
173180 var _whichAxes ;
@@ -179,18 +186,18 @@ function doZoom(chartInstance, zoomX, zoomY, center, whichAxes) {
179186 _whichAxes = 'xy' ;
180187 }
181188
182- helpers . each ( chartInstance . scales , function ( scale ) {
189+ helpers . each ( chart . scales , function ( scale ) {
183190 if ( scale . isHorizontal ( ) && directionEnabled ( zoomMode , 'x' ) && directionEnabled ( _whichAxes , 'x' ) ) {
184191 zoomOptions . scaleAxes = 'x' ;
185- zoomScale ( scale , zoomX , center , zoomOptions ) ;
192+ zoomScale ( scale , percentZoomX , focalPoint , zoomOptions ) ;
186193 } else if ( ! scale . isHorizontal ( ) && directionEnabled ( zoomMode , 'y' ) && directionEnabled ( _whichAxes , 'y' ) ) {
187194 // Do Y zoom
188195 zoomOptions . scaleAxes = 'y' ;
189- zoomScale ( scale , zoomY , center , zoomOptions ) ;
196+ zoomScale ( scale , percentZoomY , focalPoint , zoomOptions ) ;
190197 }
191198 } ) ;
192199
193- chartInstance . update ( 0 ) ;
200+ chart . update ( 0 ) ;
194201
195202 if ( typeof zoomOptions . onZoom === 'function' ) {
196203 zoomOptions . onZoom ( ) ;
0 commit comments