@@ -82,6 +82,8 @@ function makeDragBox(gd, plotinfo, x, y, w, h, ns, ew) {
82
82
var isSubplotConstrained ;
83
83
// do we need to edit x/y ranges?
84
84
var editX , editY ;
85
+ // graph-wide optimization flags
86
+ var hasScatterGl , hasOnlyLargeSploms , hasSplom , hasSVG ;
85
87
86
88
function recomputeAxisLists ( ) {
87
89
xa0 = plotinfo . xaxis ;
@@ -117,6 +119,12 @@ function makeDragBox(gd, plotinfo, x, y, w, h, ns, ew) {
117
119
isSubplotConstrained = links . isSubplotConstrained ;
118
120
editX = ew || isSubplotConstrained ;
119
121
editY = ns || isSubplotConstrained ;
122
+
123
+ var fullLayout = gd . _fullLayout ;
124
+ hasScatterGl = fullLayout . _has ( 'scattergl' ) ;
125
+ hasOnlyLargeSploms = fullLayout . _hasOnlyLargeSploms ;
126
+ hasSplom = hasOnlyLargeSploms || fullLayout . _has ( 'splom' ) ;
127
+ hasSVG = fullLayout . _has ( 'svg' ) ;
120
128
}
121
129
122
130
recomputeAxisLists ( ) ;
@@ -688,6 +696,10 @@ function makeDragBox(gd, plotinfo, x, y, w, h, ns, ew) {
688
696
] , gd ) ;
689
697
}
690
698
699
+ // x/y scaleFactor stash,
700
+ // minimizes number of per-point DOM updates in updateSubplots below
701
+ var xScaleFactorOld , yScaleFactorOld ;
702
+
691
703
// updateSubplots - find all plot viewboxes that should be
692
704
// affected by this drag, and update them. look for all plots
693
705
// sharing an affected axis (including the one being dragged),
@@ -696,14 +708,6 @@ function makeDragBox(gd, plotinfo, x, y, w, h, ns, ew) {
696
708
var fullLayout = gd . _fullLayout ;
697
709
var plotinfos = fullLayout . _plots ;
698
710
var subplots = fullLayout . _subplots . cartesian ;
699
-
700
- // TODO can we move these to outer scope?
701
- var hasScatterGl = fullLayout . _has ( 'scattergl' ) ;
702
- var hasOnlyLargeSploms = fullLayout . _hasOnlyLargeSploms ;
703
- var hasSplom = hasOnlyLargeSploms || fullLayout . _has ( 'splom' ) ;
704
- var hasSVG = fullLayout . _has ( 'svg' ) ;
705
- var hasDraggedPts = fullLayout . _has ( 'draggedPts' ) ;
706
-
707
711
var i , sp , xa , ya ;
708
712
709
713
if ( hasSplom || hasScatterGl ) {
@@ -788,26 +792,20 @@ function makeDragBox(gd, plotinfo, x, y, w, h, ns, ew) {
788
792
. call ( Drawing . setTranslate , plotDx , plotDy )
789
793
. call ( Drawing . setScale , 1 / xScaleFactor2 , 1 / yScaleFactor2 ) ;
790
794
791
- // TODO move these selectAll calls out of here
792
- // and stash them somewhere nice, see:
793
- // https://github.com/plotly/plotly.js/issues/2548
794
- if ( hasDraggedPts ) {
795
- var traceGroups = sp . plot
796
- . selectAll ( '.scatterlayer .trace, .boxlayer .trace, .violinlayer .trace' ) ;
797
-
798
- // This is specifically directed at marker points in scatter, box and violin traces,
799
- // applying an inverse scale to individual points to counteract
800
- // the scale of the trace as a whole:
801
- traceGroups . selectAll ( '.point' )
802
- . call ( Drawing . setPointGroupScale , xScaleFactor2 , yScaleFactor2 ) ;
803
- traceGroups . selectAll ( '.textpoint' )
804
- . call ( Drawing . setTextPointsScale , xScaleFactor2 , yScaleFactor2 ) ;
805
- traceGroups
806
- . call ( Drawing . hideOutsideRangePoints , sp ) ;
807
-
808
- sp . plot . selectAll ( '.barlayer .trace' )
809
- . call ( Drawing . hideOutsideRangePoints , sp , '.bartext' ) ;
795
+ // apply an inverse scale to individual points to counteract
796
+ // the scale of the trace group.
797
+ // apply only when scale changes, as adjusting the scale of
798
+ // all the points can be expansive.
799
+ if ( xScaleFactor2 !== xScaleFactorOld || yScaleFactor2 !== yScaleFactorOld ) {
800
+ Drawing . setPointGroupScale ( sp . zoomScalePts , xScaleFactor2 , yScaleFactor2 ) ;
801
+ Drawing . setTextPointsScale ( sp . zoomScaleTxt , xScaleFactor2 , yScaleFactor2 ) ;
810
802
}
803
+
804
+ Drawing . hideOutsideRangePoints ( sp . clipOnAxisFalseTraces , sp ) ;
805
+
806
+ // update x/y scaleFactor stash
807
+ xScaleFactorOld = xScaleFactor2 ;
808
+ yScaleFactorOld = yScaleFactor2 ;
811
809
}
812
810
}
813
811
}
0 commit comments