@@ -99,8 +99,8 @@ export function mouseUp(chart, event) {
9999}
100100
101101export function wheel ( chart , event ) {
102- const { options : { zoom : zoomOptions } } = getState ( chart ) ;
103- const { wheelModifierKey, onZoomRejected, onZoomComplete } = zoomOptions ;
102+ const { handlers : { onZoomComplete } , options : { zoom : zoomOptions } } = getState ( chart ) ;
103+ const { wheelModifierKey, onZoomRejected} = zoomOptions ;
104104
105105 // Before preventDefault, check if the modifier key required and pressed
106106 if ( wheelModifierKey && ! event [ wheelModifierKey + 'Key' ] ) {
@@ -114,7 +114,7 @@ export function wheel(chart, event) {
114114
115115 // Firefox always fires the wheel event twice:
116116 // First without the delta and right after that once with the delta properties.
117- if ( typeof event . deltaY === ' undefined' ) {
117+ if ( event . deltaY === undefined ) {
118118 return ;
119119 }
120120
@@ -132,20 +132,26 @@ export function wheel(chart, event) {
132132 zoom ( chart , amount ) ;
133133
134134 if ( onZoomComplete ) {
135- debounce ( ( ) => call ( onZoomComplete , [ { chart} ] ) , 250 ) ;
135+ onZoomComplete ( ) ;
136+ }
137+ }
138+
139+ function addDebouncedHandler ( chart , name , handler , delay ) {
140+ if ( handler ) {
141+ getState ( chart ) . handlers [ name ] = debounce ( ( ) => call ( handler , [ { chart} ] ) , delay ) ;
136142 }
137143}
138144
139145export function addListeners ( chart , options ) {
140146 const canvas = chart . canvas ;
147+ const { enabled : zoomEnabled , drag : dragEnabled , onZoomComplete} = options . zoom ;
141148
142149 // Install listeners. Do this dynamically based on options so that we can turn zoom on and off
143150 // We also want to make sure listeners aren't always on. E.g. if you're scrolling down a page
144151 // and the mouse goes over a chart you don't want it intercepted unless the plugin is enabled
145- const zoomEnabled = options . zoom && options . zoom . enabled ;
146- const dragEnabled = options . zoom . drag ;
147152 if ( zoomEnabled && ! dragEnabled ) {
148153 addHandler ( chart , canvas , 'wheel' , wheel ) ;
154+ addDebouncedHandler ( chart , 'onZoomComplete' , onZoomComplete , 250 ) ;
149155 } else {
150156 removeHandler ( chart , canvas , 'wheel' ) ;
151157 }
0 commit comments