@@ -256,39 +256,38 @@ function sceneUpdate(gd, subplot) {
256
256
257
257
// draw traces in proper order
258
258
scene . draw = function draw ( ) {
259
- var i ;
260
- for ( i = 0 ; i < scene . count ; i ++ ) {
261
- if ( scene . fill2d && scene . fillOptions [ i ] ) {
262
- // must do all fills first
263
- scene . fill2d . draw ( i ) ;
259
+ var count = scene . count ;
260
+ var fill2d = scene . fill2d ;
261
+ var error2d = scene . error2d ;
262
+ var line2d = scene . line2d ;
263
+ var scatter2d = scene . scatter2d ;
264
+ var glText = scene . glText ;
265
+ var select2d = scene . select2d ;
266
+ var selectBatch = scene . selectBatch ;
267
+ var unselectBatch = scene . unselectBatch ;
268
+
269
+ for ( var i = 0 ; i < count ; i ++ ) {
270
+ if ( fill2d && scene . fillOrder [ i ] ) {
271
+ fill2d . draw ( scene . fillOrder [ i ] ) ;
264
272
}
265
- }
266
- for ( i = 0 ; i < scene . count ; i ++ ) {
267
- if ( scene . line2d && scene . lineOptions [ i ] ) {
268
- scene . line2d . draw ( i ) ;
273
+ if ( line2d && scene . lineOptions [ i ] ) {
274
+ line2d . draw ( i ) ;
269
275
}
270
- if ( scene . error2d && scene . errorXOptions [ i ] ) {
271
- scene . error2d . draw ( i ) ;
276
+ if ( error2d ) {
277
+ if ( scene . errorXOptions [ i ] ) error2d . draw ( i ) ;
278
+ if ( scene . errorYOptions [ i ] ) error2d . draw ( i + count ) ;
272
279
}
273
- if ( scene . error2d && scene . errorYOptions [ i ] ) {
274
- scene . error2d . draw ( i + scene . count ) ;
280
+ if ( scatter2d && scene . markerOptions [ i ] && ( ! selectBatch || ! selectBatch [ i ] ) ) {
281
+ scatter2d . draw ( i ) ;
275
282
}
276
- if ( scene . scatter2d && scene . markerOptions [ i ] && ( ! scene . selectBatch || ! scene . selectBatch [ i ] ) ) {
277
- // traces in no-selection mode
278
- scene . scatter2d . draw ( i ) ;
283
+ if ( glText [ i ] && scene . textOptions [ i ] ) {
284
+ glText [ i ] . render ( ) ;
279
285
}
280
286
}
281
287
282
- // draw traces in selection mode
283
- if ( scene . scatter2d && scene . select2d && scene . selectBatch ) {
284
- scene . select2d . draw ( scene . selectBatch ) ;
285
- scene . scatter2d . draw ( scene . unselectBatch ) ;
286
- }
287
-
288
- for ( i = 0 ; i < scene . count ; i ++ ) {
289
- if ( scene . glText [ i ] && scene . textOptions [ i ] ) {
290
- scene . glText [ i ] . render ( ) ;
291
- }
288
+ if ( scatter2d && select2d && selectBatch ) {
289
+ select2d . draw ( selectBatch ) ;
290
+ scatter2d . draw ( unselectBatch ) ;
292
291
}
293
292
294
293
scene . dirty = false ;
@@ -397,6 +396,24 @@ function plot(gd, subplot, cdata) {
397
396
}
398
397
if ( scene . line2d ) {
399
398
scene . line2d . update ( scene . lineOptions ) ;
399
+ scene . lineOptions = scene . lineOptions . map ( function ( lineOptions ) {
400
+ if ( lineOptions && lineOptions . positions ) {
401
+ var pos = [ ] , srcPos = lineOptions . positions ;
402
+
403
+ var firstptdef = 0 ;
404
+ while ( isNaN ( srcPos [ firstptdef ] ) || isNaN ( srcPos [ firstptdef + 1 ] ) ) {
405
+ firstptdef += 2 ;
406
+ }
407
+ var lastptdef = srcPos . length - 2 ;
408
+ while ( isNaN ( srcPos [ lastptdef ] ) || isNaN ( srcPos [ lastptdef + 1 ] ) ) {
409
+ lastptdef += - 2 ;
410
+ }
411
+ pos = pos . concat ( srcPos . slice ( firstptdef , lastptdef + 2 ) ) ;
412
+ lineOptions . positions = pos ;
413
+ }
414
+ return lineOptions ;
415
+ } ) ;
416
+ scene . line2d . update ( scene . lineOptions ) ;
400
417
}
401
418
if ( scene . error2d ) {
402
419
var errorBatch = ( scene . errorXOptions || [ ] ) . concat ( scene . errorYOptions || [ ] ) ;
@@ -405,7 +422,9 @@ function plot(gd, subplot, cdata) {
405
422
if ( scene . scatter2d ) {
406
423
scene . scatter2d . update ( scene . markerOptions ) ;
407
424
}
425
+
408
426
// fill requires linked traces, so we generate it's positions here
427
+ scene . fillOrder = Lib . repeat ( null , scene . count ) ;
409
428
if ( scene . fill2d ) {
410
429
scene . fillOptions = scene . fillOptions . map ( function ( fillOptions , i ) {
411
430
var cdscatter = cdata [ i ] ;
@@ -416,19 +435,46 @@ function plot(gd, subplot, cdata) {
416
435
var lineOptions = scene . lineOptions [ i ] ;
417
436
var last , j ;
418
437
438
+ var fillData = [ ] ;
439
+ if ( trace . _ownfill ) fillData . push ( i ) ;
440
+ if ( trace . _nexttrace ) fillData . push ( i + 1 ) ;
441
+ if ( fillData . length ) scene . fillOrder [ i ] = fillData ;
442
+
419
443
var pos = [ ] , srcPos = ( lineOptions && lineOptions . positions ) || stash . positions ;
420
444
421
445
if ( trace . fill === 'tozeroy' ) {
422
- pos = [ srcPos [ 0 ] , 0 ] ;
423
- pos = pos . concat ( srcPos ) ;
424
- pos . push ( srcPos [ srcPos . length - 2 ] ) ;
425
- pos . push ( 0 ) ;
446
+ var firstpdef = 0 ;
447
+ while ( isNaN ( srcPos [ firstpdef + 1 ] ) ) {
448
+ firstpdef += 2 ;
449
+ }
450
+ var lastpdef = srcPos . length - 2 ;
451
+ while ( isNaN ( srcPos [ lastpdef + 1 ] ) ) {
452
+ lastpdef += - 2 ;
453
+ }
454
+ if ( srcPos [ firstpdef + 1 ] !== 0 ) {
455
+ pos = [ srcPos [ firstpdef ] , 0 ] ;
456
+ }
457
+ pos = pos . concat ( srcPos . slice ( firstpdef , lastpdef + 2 ) ) ;
458
+ if ( srcPos [ lastpdef + 1 ] !== 0 ) {
459
+ pos = pos . concat ( [ srcPos [ lastpdef ] , 0 ] ) ;
460
+ }
426
461
}
427
462
else if ( trace . fill === 'tozerox' ) {
428
- pos = [ 0 , srcPos [ 1 ] ] ;
429
- pos = pos . concat ( srcPos ) ;
430
- pos . push ( 0 ) ;
431
- pos . push ( srcPos [ srcPos . length - 1 ] ) ;
463
+ var firstptdef = 0 ;
464
+ while ( isNaN ( srcPos [ firstptdef ] ) ) {
465
+ firstptdef += 2 ;
466
+ }
467
+ var lastptdef = srcPos . length - 2 ;
468
+ while ( isNaN ( srcPos [ lastptdef ] ) ) {
469
+ lastptdef += - 2 ;
470
+ }
471
+ if ( srcPos [ firstptdef ] !== 0 ) {
472
+ pos = [ 0 , srcPos [ firstptdef + 1 ] ] ;
473
+ }
474
+ pos = pos . concat ( srcPos . slice ( firstptdef , lastptdef + 2 ) ) ;
475
+ if ( srcPos [ lastptdef ] !== 0 ) {
476
+ pos = pos . concat ( [ 0 , srcPos [ lastptdef + 1 ] ] ) ;
477
+ }
432
478
}
433
479
else if ( trace . fill === 'toself' || trace . fill === 'tonext' ) {
434
480
pos = [ ] ;
@@ -459,8 +505,7 @@ function plot(gd, subplot, cdata) {
459
505
for ( i = Math . floor ( nextPos . length / 2 ) ; i -- ; ) {
460
506
var xx = nextPos [ i * 2 ] , yy = nextPos [ i * 2 + 1 ] ;
461
507
if ( isNaN ( xx ) || isNaN ( yy ) ) continue ;
462
- pos . push ( xx ) ;
463
- pos . push ( yy ) ;
508
+ pos . push ( xx , yy ) ;
464
509
}
465
510
fillOptions . fill = nextTrace . fillcolor ;
466
511
}
@@ -486,7 +531,7 @@ function plot(gd, subplot, cdata) {
486
531
pos = pos . concat ( prevLinePos ) ;
487
532
fillOptions . hole = hole ;
488
533
}
489
-
534
+ fillOptions . fillmode = trace . fill ;
490
535
fillOptions . opacity = trace . opacity ;
491
536
fillOptions . positions = pos ;
492
537
0 commit comments