@@ -82,6 +82,8 @@ function makeDragBox(gd, plotinfo, x, y, w, h, ns, ew) {
8282 var isSubplotConstrained ;
8383 // do we need to edit x/y ranges?
8484 var editX , editY ;
85+ // graph-wide optimization flags
86+ var hasScatterGl , hasOnlyLargeSploms , hasSplom , hasSVG ;
8587
8688 function recomputeAxisLists ( ) {
8789 xa0 = plotinfo . xaxis ;
@@ -117,6 +119,12 @@ function makeDragBox(gd, plotinfo, x, y, w, h, ns, ew) {
117119 isSubplotConstrained = links . isSubplotConstrained ;
118120 editX = ew || isSubplotConstrained ;
119121 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' ) ;
120128 }
121129
122130 recomputeAxisLists ( ) ;
@@ -688,6 +696,10 @@ function makeDragBox(gd, plotinfo, x, y, w, h, ns, ew) {
688696 ] , gd ) ;
689697 }
690698
699+ // x/y scaleFactor stash,
700+ // minimizes number of per-point DOM updates in updateSubplots below
701+ var xScaleFactorOld , yScaleFactorOld ;
702+
691703 // updateSubplots - find all plot viewboxes that should be
692704 // affected by this drag, and update them. look for all plots
693705 // sharing an affected axis (including the one being dragged),
@@ -696,14 +708,6 @@ function makeDragBox(gd, plotinfo, x, y, w, h, ns, ew) {
696708 var fullLayout = gd . _fullLayout ;
697709 var plotinfos = fullLayout . _plots ;
698710 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-
707711 var i , sp , xa , ya ;
708712
709713 if ( hasSplom || hasScatterGl ) {
@@ -788,26 +792,20 @@ function makeDragBox(gd, plotinfo, x, y, w, h, ns, ew) {
788792 . call ( Drawing . setTranslate , plotDx , plotDy )
789793 . call ( Drawing . setScale , 1 / xScaleFactor2 , 1 / yScaleFactor2 ) ;
790794
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 ) ;
810802 }
803+
804+ Drawing . hideOutsideRangePoints ( sp . clipOnAxisFalseTraces , sp ) ;
805+
806+ // update x/y scaleFactor stash
807+ xScaleFactorOld = xScaleFactor2 ;
808+ yScaleFactorOld = yScaleFactor2 ;
811809 }
812810 }
813811 }
0 commit comments