@@ -141,6 +141,17 @@ d3.behavior.zoom = function() {
141141 view . y += p [ 1 ] - l [ 1 ] ;
142142 }
143143
144+ function zoomTo ( that , p , l , k ) {
145+ that . __chart__ = { x : view . x , y : view . y , k : view . k } ;
146+
147+ scaleTo ( Math . pow ( 2 , k ) ) ;
148+ translateTo ( center0 = p , l ) ;
149+
150+ d3 . select ( that ) . transition ( )
151+ . duration ( 350 ) // TODO allow this to be customized?
152+ . call ( zoom . event ) ;
153+ }
154+
144155 function rescale ( ) {
145156 if ( x1 ) x1 . domain ( x0 . range ( ) . map ( function ( x ) { return ( x - view . x ) / view . k ; } ) . map ( x0 . invert ) ) ;
146157 if ( y1 ) y1 . domain ( y0 . range ( ) . map ( function ( y ) { return ( y - view . y ) / view . k ; } ) . map ( y0 . invert ) ) ;
@@ -169,7 +180,7 @@ d3.behavior.zoom = function() {
169180 location0 = location ( d3 . mouse ( that ) ) ,
170181 dragRestore = d3_event_dragSuppress ( ) ;
171182
172- d3_selection_interrupt . call ( that ) ;
183+ d3_selection_interrupt ( that ) ;
173184 zoomstarted ( dispatch ) ;
174185
175186 function moved ( ) {
@@ -199,7 +210,6 @@ d3.behavior.zoom = function() {
199210 subject = d3 . select ( that ) ,
200211 dragRestore = d3_event_dragSuppress ( ) ;
201212
202- d3_selection_interrupt . call ( that ) ;
203213 started ( ) ;
204214 zoomstarted ( dispatch ) ;
205215
@@ -236,11 +246,9 @@ d3.behavior.zoom = function() {
236246
237247 if ( touches . length === 1 ) {
238248 if ( now - touchtime < 500 ) { // dbltap
239- var p = touches [ 0 ] , l = locations0 [ p . identifier ] ;
240- scaleTo ( view . k * 2 ) ;
241- translateTo ( p , l ) ;
249+ var p = touches [ 0 ] ;
250+ zoomTo ( that , p , locations0 [ p . identifier ] , Math . floor ( Math . log ( view . k ) / Math . LN2 ) + 1 ) ;
242251 d3_eventPreventDefault ( ) ;
243- zoomed ( dispatch ) ;
244252 }
245253 touchtime = now ;
246254 } else if ( touches . length > 1 ) {
@@ -254,6 +262,9 @@ d3.behavior.zoom = function() {
254262 var touches = d3 . touches ( that ) ,
255263 p0 , l0 ,
256264 p1 , l1 ;
265+
266+ d3_selection_interrupt ( that ) ;
267+
257268 for ( var i = 0 , n = touches . length ; i < n ; ++ i , l1 = null ) {
258269 p1 = touches [ i ] ;
259270 if ( l1 = locations0 [ p1 . identifier ] ) {
@@ -300,7 +311,7 @@ d3.behavior.zoom = function() {
300311 function mousewheeled ( ) {
301312 var dispatch = event . of ( this , arguments ) ;
302313 if ( mousewheelTimer ) clearTimeout ( mousewheelTimer ) ;
303- else translate0 = location ( center0 = center || d3 . mouse ( this ) ) , d3_selection_interrupt . call ( this ) , zoomstarted ( dispatch ) ;
314+ else translate0 = location ( center0 = center || d3 . mouse ( this ) ) , d3_selection_interrupt ( this ) , zoomstarted ( dispatch ) ;
304315 mousewheelTimer = setTimeout ( function ( ) { mousewheelTimer = null ; zoomended ( dispatch ) ; } , 50 ) ;
305316 d3_eventPreventDefault ( ) ;
306317 scaleTo ( Math . pow ( 2 , d3_behavior_zoomDelta ( ) * .002 ) * view . k ) ;
@@ -309,16 +320,10 @@ d3.behavior.zoom = function() {
309320 }
310321
311322 function dblclicked ( ) {
312- var l = location ( center0 = d3 . mouse ( this ) ) ,
323+ var p = d3 . mouse ( this ) ,
313324 k = Math . log ( view . k ) / Math . LN2 ;
314325
315- this . __chart__ = { x : view . x , y : view . y , k : view . k } ;
316- scaleTo ( Math . pow ( 2 , d3 . event . shiftKey ? Math . ceil ( k ) - 1 : Math . floor ( k ) + 1 ) ) ;
317- translateTo ( center0 , l ) ;
318-
319- d3 . select ( this ) . transition ( )
320- . duration ( 350 ) // TODO allow this to be customized?
321- . call ( zoom . event ) ;
326+ zoomTo ( this , p , location ( p ) , d3 . event . shiftKey ? Math . ceil ( k ) - 1 : Math . floor ( k ) + 1 ) ;
322327 }
323328
324329 return d3 . rebind ( zoom , event , "on" ) ;
0 commit comments