@@ -184,6 +184,9 @@ module.exports = function dragBox(gd, plotinfo, x, y, w, h, ns, ew) {
184
184
zb ,
185
185
corners ;
186
186
187
+ // collected changes to be made to the plot by relayout at the end
188
+ var updates = { } ;
189
+
187
190
function zoomPrep ( e , startX , startY ) {
188
191
var dragBBox = dragger . getBoundingClientRect ( ) ;
189
192
x0 = startX - dragBBox . left ;
@@ -282,8 +285,8 @@ module.exports = function dragBox(gd, plotinfo, x, y, w, h, ns, ew) {
282
285
}
283
286
284
287
// TODO: edit linked axes in zoomAxRanges and in dragTail
285
- if ( zoomMode === 'xy' || zoomMode === 'x' ) zoomAxRanges ( xa , box . l / pw , box . r / pw , xaLinked ) ;
286
- if ( zoomMode === 'xy' || zoomMode === 'y' ) zoomAxRanges ( ya , ( ph - box . b ) / ph , ( ph - box . t ) / ph , yaLinked ) ;
288
+ if ( zoomMode === 'xy' || zoomMode === 'x' ) zoomAxRanges ( xa , box . l / pw , box . r / pw , updates , xaLinked ) ;
289
+ if ( zoomMode === 'xy' || zoomMode === 'y' ) zoomAxRanges ( ya , ( ph - box . b ) / ph , ( ph - box . t ) / ph , updates , yaLinked ) ;
287
290
288
291
removeZoombox ( gd ) ;
289
292
dragTail ( zoomMode ) ;
@@ -335,11 +338,11 @@ module.exports = function dragBox(gd, plotinfo, x, y, w, h, ns, ew) {
335
338
}
336
339
337
340
// scroll zoom, on all draggers except corners
338
- var scrollViewBox = [ 0 , 0 , pw , ph ] ,
339
- // wait a little after scrolling before redrawing
340
- redrawTimer = null ,
341
- REDRAWDELAY = constants . REDRAWDELAY ,
342
- mainplot = plotinfo . mainplot ?
341
+ var scrollViewBox = [ 0 , 0 , pw , ph ] ;
342
+ // wait a little after scrolling before redrawing
343
+ var redrawTimer = null ;
344
+ var REDRAWDELAY = constants . REDRAWDELAY ;
345
+ var mainplot = plotinfo . mainplot ?
343
346
fullLayout . _plots [ plotinfo . mainplot ] : plotinfo ;
344
347
345
348
function zoomWheel ( e ) {
@@ -524,6 +527,8 @@ module.exports = function dragBox(gd, plotinfo, x, y, w, h, ns, ew) {
524
527
ticksAndAnnotations ( yActive , xActive ) ;
525
528
}
526
529
530
+ // Draw ticks and annotations (and other components) when ranges change.
531
+ // Also records the ranges that have changed for use by update at the end.
527
532
function ticksAndAnnotations ( ns , ew ) {
528
533
var activeAxIds = [ ] ,
529
534
i ;
@@ -543,8 +548,12 @@ module.exports = function dragBox(gd, plotinfo, x, y, w, h, ns, ew) {
543
548
pushActiveAxIds ( yaLinked ) ;
544
549
}
545
550
551
+ updates = { } ;
546
552
for ( i = 0 ; i < activeAxIds . length ; i ++ ) {
547
- doTicks ( gd , activeAxIds [ i ] , true ) ;
553
+ var axId = activeAxIds [ i ] ;
554
+ doTicks ( gd , axId , true ) ;
555
+ var ax = getFromId ( gd , axId ) ;
556
+ updates [ ax . _name + '.range' ] = ax . range . slice ( ) ;
548
557
}
549
558
550
559
function redrawObjs ( objArray , method , shortCircuit ) {
@@ -641,29 +650,17 @@ module.exports = function dragBox(gd, plotinfo, x, y, w, h, ns, ew) {
641
650
function dragTail ( zoommode ) {
642
651
if ( zoommode === undefined ) zoommode = ( ew ? 'x' : '' ) + ( ns ? 'y' : '' ) ;
643
652
644
- var attrs = { } ;
645
- // revert to the previous axis settings, then apply the new ones
646
- // through relayout - this lets relayout manage undo/redo
647
- var axesToModify ;
648
- if ( zoommode === 'xy' ) axesToModify = xa . concat ( ya ) ;
649
- else if ( zoommode === 'x' ) axesToModify = xa ;
650
- else if ( zoommode === 'y' ) axesToModify = ya ;
651
-
652
- for ( var i = 0 ; i < axesToModify . length ; i ++ ) {
653
- var axi = axesToModify [ i ] ;
654
- if ( axi . _r [ 0 ] !== axi . range [ 0 ] ) attrs [ axi . _name + '.range[0]' ] = axi . range [ 0 ] ;
655
- if ( axi . _r [ 1 ] !== axi . range [ 1 ] ) attrs [ axi . _name + '.range[1]' ] = axi . range [ 1 ] ;
656
-
657
- axi . range = axi . _input . range = axi . _r . slice ( ) ;
658
- }
659
-
653
+ // put the subplot viewboxes back to default (Because we're going to)
654
+ // be repositioning the data in the relayout. But DON'T call
655
+ // ticksAndAnnotations again - it's unnecessary and would overwrite `updates`
660
656
updateSubplots ( [ 0 , 0 , pw , ph ] ) ;
661
- Plotly . relayout ( gd , attrs ) ;
657
+ Plotly . relayout ( gd , updates ) ;
662
658
}
663
659
664
660
// updateSubplots - find all plot viewboxes that should be
665
661
// affected by this drag, and update them. look for all plots
666
662
// sharing an affected axis (including the one being dragged)
663
+ // returns all the new axis ranges as an update object
667
664
function updateSubplots ( viewBox ) {
668
665
var plotinfos = fullLayout . _plots ;
669
666
var subplots = Object . keys ( plotinfos ) ;
@@ -674,6 +671,8 @@ module.exports = function dragBox(gd, plotinfo, x, y, w, h, ns, ew) {
674
671
675
672
var i , xScaleFactor2 , yScaleFactor2 , clipDx , clipDy ;
676
673
674
+ var attrs = { } ;
675
+
677
676
// Find the appropriate scaling for this axis, if it's linked to the
678
677
// dragged axes by constraints. 0 is special, it means this axis shouldn't
679
678
// ever be scaled (will be converted to 1 if the other axis is scaled)
@@ -693,6 +692,7 @@ module.exports = function dragBox(gd, plotinfo, x, y, w, h, ns, ew) {
693
692
if ( scaleFactor ) {
694
693
ax . range = ax . _r . slice ( ) ;
695
694
scaleZoom ( ax , scaleFactor ) ;
695
+ attrs [ ax . _name + '.range' ] = ax . range . slice ( ) ;
696
696
return getShift ( ax , scaleFactor ) ;
697
697
}
698
698
return 0 ;
@@ -758,6 +758,8 @@ module.exports = function dragBox(gd, plotinfo, x, y, w, h, ns, ew) {
758
758
. selectAll ( '.points' ) . selectAll ( '.textpoint' )
759
759
. call ( Drawing . setTextPointsScale , xScaleFactor2 , yScaleFactor2 ) ;
760
760
}
761
+
762
+ return attrs ;
761
763
}
762
764
763
765
return dragger ;
@@ -806,7 +808,7 @@ function getEndText(ax, end) {
806
808
}
807
809
}
808
810
809
- function zoomAxRanges ( axList , r0Fraction , r1Fraction , linkedAxes ) {
811
+ function zoomAxRanges ( axList , r0Fraction , r1Fraction , updates , linkedAxes ) {
810
812
var i ,
811
813
axi ,
812
814
axRangeLinear0 ,
@@ -822,13 +824,14 @@ function zoomAxRanges(axList, r0Fraction, r1Fraction, linkedAxes) {
822
824
axi . l2r ( axRangeLinear0 + axRangeLinearSpan * r0Fraction ) ,
823
825
axi . l2r ( axRangeLinear0 + axRangeLinearSpan * r1Fraction )
824
826
] ;
827
+ updates [ axi . _name + '.range' ] = axi . range . slice ( ) ;
825
828
}
826
829
827
830
// zoom linked axes about their centers
828
831
if ( linkedAxes && linkedAxes . length ) {
829
832
var linkedR0Fraction = ( r0Fraction + ( 1 - r1Fraction ) ) / 2 ;
830
833
831
- zoomAxRanges ( linkedAxes , linkedR0Fraction , 1 - linkedR0Fraction ) ;
834
+ zoomAxRanges ( linkedAxes , linkedR0Fraction , 1 - linkedR0Fraction , updates ) ;
832
835
}
833
836
}
834
837
0 commit comments