@@ -52,20 +52,17 @@ module.exports = function dragBox(gd, plotinfo, x, y, w, h, ns, ew) {
5252 pw = xa [ 0 ] . _length ,
5353 ph = ya [ 0 ] . _length ,
5454 MINDRAG = constants . MINDRAG ,
55- MINZOOM = constants . MINZOOM ,
56- i ,
57- subplotXa ,
58- subplotYa ;
59-
60- for ( i = 1 ; i < subplots . length ; i ++ ) {
61- subplotXa = subplots [ i ] . x ( ) ;
62- subplotYa = subplots [ i ] . y ( ) ;
55+ MINZOOM = constants . MINZOOM ;
56+
57+ for ( var i = 1 ; i < subplots . length ; i ++ ) {
58+ var subplotXa = subplots [ i ] . x ( ) ,
59+ subplotYa = subplots [ i ] . y ( ) ;
6360 if ( xa . indexOf ( subplotXa ) === - 1 ) xa . push ( subplotXa ) ;
6461 if ( ya . indexOf ( subplotYa ) === - 1 ) ya . push ( subplotYa ) ;
6562 }
6663
6764 function isDirectionActive ( axList , activeVal ) {
68- for ( i = 0 ; i < axList . length ; i ++ ) {
65+ for ( var i = 0 ; i < axList . length ; i ++ ) {
6966 if ( ! axList [ i ] . fixedrange ) return activeVal ;
7067 }
7168 return '' ;
@@ -183,7 +180,7 @@ module.exports = function dragBox(gd, plotinfo, x, y, w, h, ns, ew) {
183180 . attr ( 'd' , 'M0,0Z' ) ;
184181
185182 clearSelect ( ) ;
186- for ( i = 0 ; i < allaxes . length ; i ++ ) forceNumbers ( allaxes [ i ] . range ) ;
183+ for ( var i = 0 ; i < allaxes . length ; i ++ ) forceNumbers ( allaxes [ i ] . range ) ;
187184 }
188185
189186 function clearSelect ( ) {
@@ -403,7 +400,7 @@ module.exports = function dragBox(gd, plotinfo, x, y, w, h, ns, ew) {
403400 }
404401
405402 // viewbox redraw at first
406- updateViewBoxes ( scrollViewBox ) ;
403+ updateSubplots ( scrollViewBox ) ;
407404 ticksAndAnnotations ( ns , ew ) ;
408405
409406 // then replot after a delay to make sure
@@ -437,7 +434,7 @@ module.exports = function dragBox(gd, plotinfo, x, y, w, h, ns, ew) {
437434 if ( xActive === 'ew' || yActive === 'ns' ) {
438435 if ( xActive ) dragAxList ( xa , dx ) ;
439436 if ( yActive ) dragAxList ( ya , dy ) ;
440- updateViewBoxes ( [ xActive ? - dx : 0 , yActive ? - dy : 0 , pw , ph ] ) ;
437+ updateSubplots ( [ xActive ? - dx : 0 , yActive ? - dy : 0 , pw , ph ] ) ;
441438 ticksAndAnnotations ( yActive , xActive ) ;
442439 return ;
443440 }
@@ -479,7 +476,7 @@ module.exports = function dragBox(gd, plotinfo, x, y, w, h, ns, ew) {
479476 else if ( yActive === 's' ) dy = dz ( ya , 0 , - dy ) ;
480477 else if ( ! yActive ) dy = 0 ;
481478
482- updateViewBoxes ( [
479+ updateSubplots ( [
483480 ( xActive === 'w' ) ? dx : 0 ,
484481 ( yActive === 'n' ) ? dy : 0 ,
485482 pw - dx ,
@@ -580,41 +577,38 @@ module.exports = function dragBox(gd, plotinfo, x, y, w, h, ns, ew) {
580577 axi . range = axi . _r . slice ( ) ;
581578 }
582579
583- updateViewBoxes ( [ 0 , 0 , pw , ph ] ) ;
580+ updateSubplots ( [ 0 , 0 , pw , ph ] ) ;
584581 Plotly . relayout ( gd , attrs ) ;
585582 }
586583
587- // updateViewBoxes - find all plot viewboxes that should be
584+ // updateSubplots - find all plot viewboxes that should be
588585 // affected by this drag, and update them. look for all plots
589586 // sharing an affected axis (including the one being dragged)
590- function updateViewBoxes ( viewBox ) {
587+ function updateSubplots ( viewBox ) {
591588 var plotinfos = fullLayout . _plots ,
592- subplots = Object . keys ( plotinfos ) ,
593- i ,
594- plotinfo2 ,
595- xa2 ,
596- ya2 ,
597- editX ,
598- editY ;
599-
600- for ( i = 0 ; i < subplots . length ; i ++ ) {
601- plotinfo2 = plotinfos [ subplots [ i ] ] ;
602- xa2 = plotinfo2 . x ( ) ;
603- ya2 = plotinfo2 . y ( ) ;
604- editX = ew && xa . indexOf ( xa2 ) !== - 1 && ! xa2 . fixedrange ;
605- editY = ns && ya . indexOf ( ya2 ) !== - 1 && ! ya2 . fixedrange ;
589+ subplots = Object . keys ( plotinfos ) ;
590+
591+ for ( var i = 0 ; i < subplots . length ; i ++ ) {
592+ var subplot = plotinfos [ subplots [ i ] ] ,
593+ xa2 = subplot . x ( ) ,
594+ ya2 = subplot . y ( ) ,
595+ editX = ew && xa . indexOf ( xa2 ) !== - 1 && ! xa2 . fixedrange ,
596+ editY = ns && ya . indexOf ( ya2 ) !== - 1 && ! ya2 . fixedrange ;
606597
607598 if ( editX || editY ) {
608- var newVB = [ 0 , 0 , xa2 . _length , ya2 . _length ] ;
609- if ( editX ) {
610- newVB [ 0 ] = viewBox [ 0 ] ;
611- newVB [ 2 ] = viewBox [ 2 ] ;
612- }
613- if ( editY ) {
614- newVB [ 1 ] = viewBox [ 1 ] ;
615- newVB [ 3 ] = viewBox [ 3 ] ;
616- }
617- plotinfo2 . plot . attr ( 'viewBox' , newVB . join ( ' ' ) ) ;
599+ // plot requires offset position and
600+ // clip moves with opposite sign
601+ var clipDx = editX ? viewBox [ 0 ] : 0 ,
602+ clipDy = editY ? viewBox [ 1 ] : 0 ,
603+ plotDx = xa2 . _offset - clipDx ,
604+ plotDy = ya2 . _offset - clipDy ;
605+
606+ var clipId = 'clip' + fullLayout . _uid + subplots [ i ] + 'plot' ;
607+
608+ fullLayout . _defs . selectAll ( '#' + clipId )
609+ . attr ( 'transform' , 'translate(' + clipDx + ', ' + clipDy + ')' ) ;
610+ subplot . plot
611+ . attr ( 'transform' , 'translate(' + plotDx + ', ' + plotDy + ')' ) ;
618612 }
619613 }
620614 }
0 commit comments