@@ -52,20 +52,17 @@ module.exports = function dragBox(gd, plotinfo, x, y, w, h, ns, ew) {
52
52
pw = xa [ 0 ] . _length ,
53
53
ph = ya [ 0 ] . _length ,
54
54
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 ( ) ;
63
60
if ( xa . indexOf ( subplotXa ) === - 1 ) xa . push ( subplotXa ) ;
64
61
if ( ya . indexOf ( subplotYa ) === - 1 ) ya . push ( subplotYa ) ;
65
62
}
66
63
67
64
function isDirectionActive ( axList , activeVal ) {
68
- for ( i = 0 ; i < axList . length ; i ++ ) {
65
+ for ( var i = 0 ; i < axList . length ; i ++ ) {
69
66
if ( ! axList [ i ] . fixedrange ) return activeVal ;
70
67
}
71
68
return '' ;
@@ -183,7 +180,7 @@ module.exports = function dragBox(gd, plotinfo, x, y, w, h, ns, ew) {
183
180
. attr ( 'd' , 'M0,0Z' ) ;
184
181
185
182
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 ) ;
187
184
}
188
185
189
186
function clearSelect ( ) {
@@ -403,7 +400,7 @@ module.exports = function dragBox(gd, plotinfo, x, y, w, h, ns, ew) {
403
400
}
404
401
405
402
// viewbox redraw at first
406
- updateViewBoxes ( scrollViewBox ) ;
403
+ updateSubplots ( scrollViewBox ) ;
407
404
ticksAndAnnotations ( ns , ew ) ;
408
405
409
406
// then replot after a delay to make sure
@@ -437,7 +434,7 @@ module.exports = function dragBox(gd, plotinfo, x, y, w, h, ns, ew) {
437
434
if ( xActive === 'ew' || yActive === 'ns' ) {
438
435
if ( xActive ) dragAxList ( xa , dx ) ;
439
436
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 ] ) ;
441
438
ticksAndAnnotations ( yActive , xActive ) ;
442
439
return ;
443
440
}
@@ -479,7 +476,7 @@ module.exports = function dragBox(gd, plotinfo, x, y, w, h, ns, ew) {
479
476
else if ( yActive === 's' ) dy = dz ( ya , 0 , - dy ) ;
480
477
else if ( ! yActive ) dy = 0 ;
481
478
482
- updateViewBoxes ( [
479
+ updateSubplots ( [
483
480
( xActive === 'w' ) ? dx : 0 ,
484
481
( yActive === 'n' ) ? dy : 0 ,
485
482
pw - dx ,
@@ -580,41 +577,38 @@ module.exports = function dragBox(gd, plotinfo, x, y, w, h, ns, ew) {
580
577
axi . range = axi . _r . slice ( ) ;
581
578
}
582
579
583
- updateViewBoxes ( [ 0 , 0 , pw , ph ] ) ;
580
+ updateSubplots ( [ 0 , 0 , pw , ph ] ) ;
584
581
Plotly . relayout ( gd , attrs ) ;
585
582
}
586
583
587
- // updateViewBoxes - find all plot viewboxes that should be
584
+ // updateSubplots - find all plot viewboxes that should be
588
585
// affected by this drag, and update them. look for all plots
589
586
// sharing an affected axis (including the one being dragged)
590
- function updateViewBoxes ( viewBox ) {
587
+ function updateSubplots ( viewBox ) {
591
588
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 ;
606
597
607
598
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 + ')' ) ;
618
612
}
619
613
}
620
614
}
0 commit comments