@@ -413,10 +413,12 @@ function makeDragBox(gd, plotinfo, x, y, w, h, ns, ew) {
413
413
414
414
// TODO: edit linked axes in zoomAxRanges and in dragTail
415
415
if ( zoomMode === 'xy' || zoomMode === 'x' ) {
416
- zoomAxRanges ( xaxes , box . l / pw , box . r / pw , updates , links . xaxes , matches . xaxes ) ;
416
+ zoomAxRanges ( xaxes , box . l / pw , box . r / pw , updates , links . xaxes ) ;
417
+ updateMatchedAxRange ( 'x' , updates ) ;
417
418
}
418
419
if ( zoomMode === 'xy' || zoomMode === 'y' ) {
419
- zoomAxRanges ( yaxes , ( ph - box . b ) / ph , ( ph - box . t ) / ph , updates , links . yaxes , matches . yaxes ) ;
420
+ zoomAxRanges ( yaxes , ( ph - box . b ) / ph , ( ph - box . t ) / ph , updates , links . yaxes ) ;
421
+ updateMatchedAxRange ( 'y' , updates ) ;
420
422
}
421
423
422
424
removeZoombox ( gd ) ;
@@ -482,7 +484,7 @@ function makeDragBox(gd, plotinfo, x, y, w, h, ns, ew) {
482
484
for ( i = 0 ; i < xaxes . length ; i ++ ) {
483
485
zoomWheelOneAxis ( xaxes [ i ] , xfrac , zoom ) ;
484
486
}
485
- updateMatchedAxes ( matches . isSubplotConstrained ? yaxes : matches . xaxes , xaxes [ 0 ] . range ) ;
487
+ updateMatchedAxRange ( 'x' ) ;
486
488
487
489
scrollViewBox [ 2 ] *= zoom ;
488
490
scrollViewBox [ 0 ] += scrollViewBox [ 2 ] * xfrac * ( 1 / zoom - 1 ) ;
@@ -493,7 +495,7 @@ function makeDragBox(gd, plotinfo, x, y, w, h, ns, ew) {
493
495
for ( i = 0 ; i < yaxes . length ; i ++ ) {
494
496
zoomWheelOneAxis ( yaxes [ i ] , yfrac , zoom ) ;
495
497
}
496
- updateMatchedAxes ( matches . isSubplotConstrained ? xaxes : matches . yaxes , yaxes [ 0 ] . range ) ;
498
+ updateMatchedAxRange ( 'y' ) ;
497
499
498
500
scrollViewBox [ 3 ] *= zoom ;
499
501
scrollViewBox [ 1 ] += scrollViewBox [ 3 ] * ( 1 - yfrac ) * ( 1 / zoom - 1 ) ;
@@ -529,19 +531,15 @@ function makeDragBox(gd, plotinfo, x, y, w, h, ns, ew) {
529
531
// prevent axis drawing from monkeying with margins until we're done
530
532
gd . _fullLayout . _replotting = true ;
531
533
532
- var matchedByXaxes ;
533
- var matchesByYaxes ;
534
- if ( matches . isSubplotConstrained ) {
535
- matchedByXaxes = yaxes ;
536
- matchesByYaxes = xaxes ;
537
- } else {
538
- matchedByXaxes = matches . xaxes ;
539
- matchesByYaxes = matches . yaxes ;
540
- }
541
-
542
534
if ( xActive === 'ew' || yActive === 'ns' ) {
543
- if ( xActive ) dragAxList ( xaxes , matchedByXaxes , dx ) ;
544
- if ( yActive ) dragAxList ( yaxes , matchesByYaxes , dy ) ;
535
+ if ( xActive ) {
536
+ dragAxList ( xaxes , dx ) ;
537
+ updateMatchedAxRange ( 'x' ) ;
538
+ }
539
+ if ( yActive ) {
540
+ dragAxList ( yaxes , dy ) ;
541
+ updateMatchedAxRange ( 'y' ) ;
542
+ }
545
543
updateSubplots ( [ xActive ? - dx : 0 , yActive ? - dy : 0 , pw , ph ] ) ;
546
544
ticksAndAnnotations ( ) ;
547
545
return ;
@@ -614,12 +612,39 @@ function makeDragBox(gd, plotinfo, x, y, w, h, ns, ew) {
614
612
}
615
613
}
616
614
617
- updateMatchedAxes ( matchedByXaxes , xaxes [ 0 ] . range ) ;
618
- updateMatchedAxes ( matchesByYaxes , yaxes [ 0 ] . range ) ;
615
+ updateMatchedAxRange ( 'x' ) ;
616
+ updateMatchedAxRange ( 'y' ) ;
619
617
updateSubplots ( [ x0 , y0 , pw - dx , ph - dy ] ) ;
620
618
ticksAndAnnotations ( ) ;
621
619
}
622
620
621
+ function updateMatchedAxRange ( axLetter , out ) {
622
+ var matchedAxes = matches . isSubplotConstrained ?
623
+ { x : yaxes , y : xaxes } [ axLetter ] :
624
+ matches [ axLetter + 'axes' ] ;
625
+
626
+ var constrainedAxes = matches . isSubplotConstrained ?
627
+ { x : xaxes , y : yaxes } [ axLetter ] :
628
+ [ ] ;
629
+
630
+ for ( var i = 0 ; i < matchedAxes . length ; i ++ ) {
631
+ var ax = matchedAxes [ i ] ;
632
+ var axId = ax . _id ;
633
+ var axId2 = matches . xLinks [ axId ] || matches . yLinks [ axId ] ;
634
+ var ax2 = constrainedAxes [ 0 ] || xaHash [ axId2 ] || yaHash [ axId2 ] ;
635
+
636
+ if ( ax2 ) {
637
+ var rng = ax2 . range ;
638
+ if ( out ) {
639
+ out [ ax . _name + '.range[0]' ] = rng [ 0 ] ;
640
+ out [ ax . _name + '.range[1]' ] = rng [ 1 ] ;
641
+ } else {
642
+ ax . range = rng ;
643
+ }
644
+ }
645
+ }
646
+ }
647
+
623
648
// Draw ticks and annotations (and other components) when ranges change.
624
649
// Also records the ranges that have changed for use by update at the end.
625
650
function ticksAndAnnotations ( ) {
@@ -947,18 +972,13 @@ function getEndText(ax, end) {
947
972
}
948
973
}
949
974
950
- function zoomAxRanges ( axList , r0Fraction , r1Fraction , updates , linkedAxes , matchedAxes ) {
951
- var i ,
952
- axi ,
953
- axRangeLinear0 ,
954
- axRangeLinearSpan ;
955
-
956
- for ( i = 0 ; i < axList . length ; i ++ ) {
957
- axi = axList [ i ] ;
975
+ function zoomAxRanges ( axList , r0Fraction , r1Fraction , updates , linkedAxes ) {
976
+ for ( var i = 0 ; i < axList . length ; i ++ ) {
977
+ var axi = axList [ i ] ;
958
978
if ( axi . fixedrange ) continue ;
959
979
960
- axRangeLinear0 = axi . _rl [ 0 ] ;
961
- axRangeLinearSpan = axi . _rl [ 1 ] - axRangeLinear0 ;
980
+ var axRangeLinear0 = axi . _rl [ 0 ] ;
981
+ var axRangeLinearSpan = axi . _rl [ 1 ] - axRangeLinear0 ;
962
982
axi . range = [
963
983
axi . l2r ( axRangeLinear0 + axRangeLinearSpan * r0Fraction ) ,
964
984
axi . l2r ( axRangeLinear0 + axRangeLinearSpan * r1Fraction )
@@ -973,18 +993,9 @@ function zoomAxRanges(axList, r0Fraction, r1Fraction, updates, linkedAxes, match
973
993
var linkedR0Fraction = ( r0Fraction + ( 1 - r1Fraction ) ) / 2 ;
974
994
zoomAxRanges ( linkedAxes , linkedR0Fraction , 1 - linkedR0Fraction , updates , [ ] , [ ] ) ;
975
995
}
976
-
977
- // TODO is picking the first ax always ok in general?
978
- // What if we're matching an overlaying axis?
979
- var rng = axList [ 0 ] . range ;
980
- for ( i = 0 ; i < matchedAxes . length ; i ++ ) {
981
- axi = matchedAxes [ i ] ;
982
- updates [ axi . _name + '.range[0]' ] = rng [ 0 ] ;
983
- updates [ axi . _name + '.range[1]' ] = rng [ 1 ] ;
984
- }
985
996
}
986
997
987
- function dragAxList ( axList , matchedAxes , pix ) {
998
+ function dragAxList ( axList , pix ) {
988
999
for ( var i = 0 ; i < axList . length ; i ++ ) {
989
1000
var axi = axList [ i ] ;
990
1001
if ( ! axi . fixedrange ) {
@@ -994,16 +1005,6 @@ function dragAxList(axList, matchedAxes, pix) {
994
1005
] ;
995
1006
}
996
1007
}
997
-
998
- updateMatchedAxes ( matchedAxes , axList [ 0 ] . range ) ;
999
- }
1000
-
1001
- function updateMatchedAxes ( matchedAxes , rng ) {
1002
- // TODO is picking the first ax always ok in general?
1003
- // What if we're matching an overlaying axis?
1004
- for ( var i = 0 ; i < matchedAxes . length ; i ++ ) {
1005
- matchedAxes [ i ] . range = rng . slice ( ) ;
1006
- }
1007
1008
}
1008
1009
1009
1010
// common transform for dragging one end of an axis
@@ -1133,7 +1134,7 @@ function calcLinks(gd, groups, xaHash, yaHash) {
1133
1134
// to match the changes in the dragged x axes
1134
1135
for ( xLinkID in group ) {
1135
1136
if ( ! ( xLinkID . charAt ( 0 ) === 'x' ? xaHash : yaHash ) [ xLinkID ] ) {
1136
- xLinks [ xLinkID ] = 1 ;
1137
+ xLinks [ xLinkID ] = xID ;
1137
1138
}
1138
1139
}
1139
1140
@@ -1150,7 +1151,7 @@ function calcLinks(gd, groups, xaHash, yaHash) {
1150
1151
if ( group [ yID ] ) {
1151
1152
for ( yLinkID in group ) {
1152
1153
if ( ! ( yLinkID . charAt ( 0 ) === 'x' ? xaHash : yaHash ) [ yLinkID ] ) {
1153
- yLinks [ yLinkID ] = 1 ;
1154
+ yLinks [ yLinkID ] = yID ;
1154
1155
}
1155
1156
}
1156
1157
}
@@ -1186,6 +1187,8 @@ function calcLinks(gd, groups, xaHash, yaHash) {
1186
1187
yaHash : yaHashLinked ,
1187
1188
xaxes : xaxesLinked ,
1188
1189
yaxes : yaxesLinked ,
1190
+ xLinks : xLinks ,
1191
+ yLinks : yLinks ,
1189
1192
isSubplotConstrained : isSubplotConstrained
1190
1193
} ;
1191
1194
}
0 commit comments