@@ -131,6 +131,7 @@ function calc(gd, trace) {
131131 stash . positions = positions ;
132132 stash . count = count ;
133133
134+ scene . uid2batchIndex [ trace . uid ] = stash . index ;
134135 scene . count ++ ;
135136
136137 gd . firstscatter = false ;
@@ -195,6 +196,8 @@ function sceneUpdate(gd, subplot) {
195196 count : 0 ,
196197 // whether scene requires init hook in plot call (dirty plot call)
197198 dirty : true ,
199+ // trace uid to batch index
200+ uid2batchIndex : { } ,
198201 // last used options
199202 lineOptions : [ ] ,
200203 fillOptions : [ ] ,
@@ -209,6 +212,7 @@ function sceneUpdate(gd, subplot) {
209212 } ;
210213
211214 var initOpts = {
215+ visibleBatch : null ,
212216 selectBatch : null ,
213217 unselectBatch : null ,
214218 // regl- component stubs, initialized in dirty plot call
@@ -249,38 +253,47 @@ function sceneUpdate(gd, subplot) {
249253
250254 // draw traces in proper order
251255 scene . draw = function draw ( ) {
252- var i ;
253- for ( i = 0 ; i < scene . count ; i ++ ) {
254- if ( scene . fill2d && scene . fillOptions [ i ] ) {
255- // must do all fills first
256- scene . fill2d . draw ( i ) ;
256+ var visibleBatch = scene . visibleBatch ;
257+ var selectBatch = scene . selectBatch ;
258+ var unselectBatch = scene . unselectBatch ;
259+ var i , b ;
260+
261+ // must do all fills first
262+ for ( i = 0 ; i < visibleBatch . length ; i ++ ) {
263+ b = visibleBatch [ i ] ;
264+ if ( scene . fill2d && scene . fillOptions [ b ] ) {
265+ scene . fill2d . draw ( b ) ;
257266 }
258267 }
259- for ( i = 0 ; i < scene . count ; i ++ ) {
260- if ( scene . line2d && scene . lineOptions [ i ] ) {
261- scene . line2d . draw ( i ) ;
268+
269+ // traces in no-selection mode
270+ for ( i = 0 ; i < visibleBatch . length ; i ++ ) {
271+ b = visibleBatch [ i ] ;
272+ if ( scene . line2d && scene . lineOptions [ b ] ) {
273+ scene . line2d . draw ( b ) ;
262274 }
263- if ( scene . error2d && scene . errorXOptions [ i ] ) {
264- scene . error2d . draw ( i ) ;
275+ if ( scene . error2d && scene . errorXOptions [ b ] ) {
276+ scene . error2d . draw ( b ) ;
265277 }
266- if ( scene . error2d && scene . errorYOptions [ i ] ) {
267- scene . error2d . draw ( i + scene . count ) ;
278+ if ( scene . error2d && scene . errorYOptions [ b ] ) {
279+ scene . error2d . draw ( b + scene . count ) ;
268280 }
269- if ( scene . scatter2d && scene . markerOptions [ i ] && ( ! scene . selectBatch || ! scene . selectBatch [ i ] ) ) {
270- // traces in no-selection mode
271- scene . scatter2d . draw ( i ) ;
281+ if ( scene . scatter2d && scene . markerOptions [ b ] && ( ! selectBatch || ! selectBatch [ b ] ) ) {
282+ scene . scatter2d . draw ( b ) ;
272283 }
273284 }
274285
275286 // draw traces in selection mode
276- if ( scene . scatter2d && scene . select2d && scene . selectBatch ) {
277- scene . select2d . draw ( scene . selectBatch ) ;
278- scene . scatter2d . draw ( scene . unselectBatch ) ;
287+ if ( scene . scatter2d && scene . select2d && selectBatch ) {
288+ scene . select2d . draw ( selectBatch ) ;
289+ scene . scatter2d . draw ( unselectBatch ) ;
279290 }
280291
281- for ( i = 0 ; i < scene . count ; i ++ ) {
282- if ( scene . glText [ i ] && scene . textOptions [ i ] ) {
283- scene . glText [ i ] . render ( ) ;
292+ // draw text, including selected/unselected items
293+ for ( i = 0 ; i < visibleBatch . length ; i ++ ) {
294+ b = visibleBatch [ i ] ;
295+ if ( scene . glText [ b ] && scene . textOptions [ b ] ) {
296+ scene . glText [ b ] . render ( ) ;
284297 }
285298 }
286299
@@ -371,14 +384,13 @@ function plot(gd, subplot, cdata) {
371384 var i , j ;
372385
373386 var fullLayout = gd . _fullLayout ;
374- var scene = cdata [ 0 ] [ 0 ] . t . _scene ;
387+ var scene = subplot . _scene ;
375388 var xaxis = subplot . xaxis ;
376389 var yaxis = subplot . yaxis ;
377390
378391 // we may have more subplots than initialized data due to Axes.getSubplots method
379392 if ( ! scene ) return ;
380393
381-
382394 var success = prepareRegl ( gd , [ 'ANGLE_instanced_arrays' , 'OES_element_index_uint' ] ) ;
383395 if ( ! success ) {
384396 scene . init ( ) ;
@@ -520,6 +532,7 @@ function plot(gd, subplot, cdata) {
520532 }
521533
522534 // form batch arrays, and check for selected points
535+ scene . visibleBatch = [ ] ;
523536 scene . selectBatch = null ;
524537 scene . unselectBatch = null ;
525538 var dragmode = fullLayout . dragmode ;
@@ -533,6 +546,7 @@ function plot(gd, subplot, cdata) {
533546 var x = stash . x ;
534547 var y = stash . y ;
535548
549+ scene . visibleBatch . push ( batchIndex ) ;
536550
537551 if ( trace . selectedpoints || selectMode ) {
538552 if ( ! selectMode ) selectMode = true ;
@@ -544,17 +558,17 @@ function plot(gd, subplot, cdata) {
544558
545559 // regenerate scene batch, if traces number changed during selection
546560 if ( trace . selectedpoints ) {
547- var selPts = scene . selectBatch [ id ] = Lib . selIndices2selPoints ( trace ) ;
561+ var selPts = scene . selectBatch [ batchIndex ] = Lib . selIndices2selPoints ( trace ) ;
548562
549563 var selDict = { } ;
550- for ( i = 0 ; i < selPts . length ; i ++ ) {
551- selDict [ selPts [ i ] ] = 1 ;
564+ for ( j = 0 ; j < selPts . length ; j ++ ) {
565+ selDict [ selPts [ j ] ] = 1 ;
552566 }
553567 var unselPts = [ ] ;
554- for ( i = 0 ; i < stash . count ; i ++ ) {
555- if ( ! selDict [ i ] ) unselPts . push ( i ) ;
568+ for ( j = 0 ; j < stash . count ; j ++ ) {
569+ if ( ! selDict [ j ] ) unselPts . push ( j ) ;
556570 }
557- scene . unselectBatch [ id ] = unselPts ;
571+ scene . unselectBatch [ batchIndex ] = unselPts ;
558572 }
559573
560574 // precalculate px coords since we are not going to pan during select
0 commit comments