@@ -131,6 +131,7 @@ function calc(gd, trace) {
131
131
stash . positions = positions ;
132
132
stash . count = count ;
133
133
134
+ scene . uid2batchIndex [ trace . uid ] = stash . index ;
134
135
scene . count ++ ;
135
136
136
137
gd . firstscatter = false ;
@@ -195,6 +196,8 @@ function sceneUpdate(gd, subplot) {
195
196
count : 0 ,
196
197
// whether scene requires init hook in plot call (dirty plot call)
197
198
dirty : true ,
199
+ // trace uid to batch index
200
+ uid2batchIndex : { } ,
198
201
// last used options
199
202
lineOptions : [ ] ,
200
203
fillOptions : [ ] ,
@@ -209,6 +212,7 @@ function sceneUpdate(gd, subplot) {
209
212
} ;
210
213
211
214
var initOpts = {
215
+ visibleBatch : null ,
212
216
selectBatch : null ,
213
217
unselectBatch : null ,
214
218
// regl- component stubs, initialized in dirty plot call
@@ -249,38 +253,47 @@ function sceneUpdate(gd, subplot) {
249
253
250
254
// draw traces in proper order
251
255
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 ) ;
257
266
}
258
267
}
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 ) ;
262
274
}
263
- if ( scene . error2d && scene . errorXOptions [ i ] ) {
264
- scene . error2d . draw ( i ) ;
275
+ if ( scene . error2d && scene . errorXOptions [ b ] ) {
276
+ scene . error2d . draw ( b ) ;
265
277
}
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 ) ;
268
280
}
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 ) ;
272
283
}
273
284
}
274
285
275
286
// 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 ) ;
279
290
}
280
291
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 ( ) ;
284
297
}
285
298
}
286
299
@@ -371,14 +384,13 @@ function plot(gd, subplot, cdata) {
371
384
var i , j ;
372
385
373
386
var fullLayout = gd . _fullLayout ;
374
- var scene = cdata [ 0 ] [ 0 ] . t . _scene ;
387
+ var scene = subplot . _scene ;
375
388
var xaxis = subplot . xaxis ;
376
389
var yaxis = subplot . yaxis ;
377
390
378
391
// we may have more subplots than initialized data due to Axes.getSubplots method
379
392
if ( ! scene ) return ;
380
393
381
-
382
394
var success = prepareRegl ( gd , [ 'ANGLE_instanced_arrays' , 'OES_element_index_uint' ] ) ;
383
395
if ( ! success ) {
384
396
scene . init ( ) ;
@@ -520,6 +532,7 @@ function plot(gd, subplot, cdata) {
520
532
}
521
533
522
534
// form batch arrays, and check for selected points
535
+ scene . visibleBatch = [ ] ;
523
536
scene . selectBatch = null ;
524
537
scene . unselectBatch = null ;
525
538
var dragmode = fullLayout . dragmode ;
@@ -533,6 +546,7 @@ function plot(gd, subplot, cdata) {
533
546
var x = stash . x ;
534
547
var y = stash . y ;
535
548
549
+ scene . visibleBatch . push ( batchIndex ) ;
536
550
537
551
if ( trace . selectedpoints || selectMode ) {
538
552
if ( ! selectMode ) selectMode = true ;
@@ -544,17 +558,17 @@ function plot(gd, subplot, cdata) {
544
558
545
559
// regenerate scene batch, if traces number changed during selection
546
560
if ( trace . selectedpoints ) {
547
- var selPts = scene . selectBatch [ id ] = Lib . selIndices2selPoints ( trace ) ;
561
+ var selPts = scene . selectBatch [ batchIndex ] = Lib . selIndices2selPoints ( trace ) ;
548
562
549
563
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 ;
552
566
}
553
567
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 ) ;
556
570
}
557
- scene . unselectBatch [ id ] = unselPts ;
571
+ scene . unselectBatch [ batchIndex ] = unselPts ;
558
572
}
559
573
560
574
// precalculate px coords since we are not going to pan during select
0 commit comments