@@ -256,64 +256,38 @@ function sceneUpdate(gd, subplot) {
256256
257257 // draw traces in proper order
258258 scene . draw = function draw ( ) {
259- var i ;
260- var we_must_draw_previous_line_marker = 0 ;
261- for ( i = 0 ; i < scene . count ; i ++ ) {
262- var we_defer_somes_draw = 0 ;
263- if ( scene . fill2d && scene . fillOptions [ i ] && scene . fillOptions [ i ] . fillmode && scene . fillOptions [ i ] . fillmode === 'tonext' ) {
264- we_defer_somes_draw = 1 ;
265- } else {
266- if ( we_must_draw_previous_line_marker && scene . line2d && scene . lineOptions [ i - 1 ] ) {
267- scene . line2d . draw ( i - 1 ) ;
268- }
269- if ( we_must_draw_previous_line_marker && scene . scatter2d && scene . markerOptions [ i - 1 ] ) {
270- scene . scatter2d . draw ( i - 1 ) ;
271- }
272- we_must_draw_previous_line_marker = 0 ;
273- }
274- if ( scene . fill2d && scene . fillOptions [ i ] ) {
275- 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 ] ) ;
276272 }
277- // we draw line2d
278- if ( we_must_draw_previous_line_marker && scene . line2d && scene . lineOptions [ i - 1 ] ) {
279- scene . line2d . draw ( i - 1 ) ;
273+ if ( line2d && scene . lineOptions [ i ] ) {
274+ line2d . draw ( i ) ;
280275 }
281- if ( scene . line2d && scene . lineOptions [ i ] ) {
282- if ( we_defer_somes_draw === 0 ) {
283- scene . line2d . draw ( i ) ;
284- }
276+ if ( error2d ) {
277+ if ( scene . errorXOptions [ i ] ) error2d . draw ( i ) ;
278+ if ( scene . errorYOptions [ i ] ) error2d . draw ( i + count ) ;
285279 }
286- if ( scene . error2d && scene . errorXOptions [ i ] ) {
287- scene . error2d . draw ( i ) ;
280+ if ( scatter2d && scene . markerOptions [ i ] && ( ! selectBatch || ! selectBatch [ i ] ) ) {
281+ scatter2d . draw ( i ) ;
288282 }
289- if ( scene . error2d && scene . errorYOptions [ i ] ) {
290- scene . error2d . draw ( i + scene . count ) ;
291- }
292- // we draw scatter2d
293- if ( ! scene . selectBatch || ! scene . selectBatch [ i ] ) {
294- if ( we_must_draw_previous_line_marker && scene . scatter2d && scene . markerOptions [ i - 1 ] ) {
295- scene . scatter2d . draw ( i - 1 ) ;
296- }
297- if ( scene . scatter2d && scene . markerOptions [ i ] ) {
298- if ( we_defer_somes_draw === 0 ) {
299- scene . scatter2d . draw ( i ) ;
300- }
301- }
302- }
303- if ( scene . glText [ i ] && scene . textOptions [ i ] ) {
304- scene . glText [ i ] . render ( ) ;
305- }
306- if ( we_defer_somes_draw === 1 ) {
307- we_must_draw_previous_line_marker = 1 ;
308- } else {
309- we_must_draw_previous_line_marker = 0 ;
283+ if ( glText [ i ] && scene . textOptions [ i ] ) {
284+ glText [ i ] . render ( ) ;
310285 }
311286 }
312287
313- // draw traces in selection mode
314- if ( scene . scatter2d && scene . select2d && scene . selectBatch ) {
315- scene . select2d . draw ( scene . selectBatch ) ;
316- scene . scatter2d . draw ( scene . unselectBatch ) ;
288+ if ( scatter2d && select2d && selectBatch ) {
289+ select2d . draw ( selectBatch ) ;
290+ scatter2d . draw ( unselectBatch ) ;
317291 }
318292
319293 scene . dirty = false ;
@@ -448,7 +422,9 @@ function plot(gd, subplot, cdata) {
448422 if ( scene . scatter2d ) {
449423 scene . scatter2d . update ( scene . markerOptions ) ;
450424 }
425+
451426 // fill requires linked traces, so we generate it's positions here
427+ scene . fillOrder = Lib . repeat ( null , scene . count ) ;
452428 if ( scene . fill2d ) {
453429 scene . fillOptions = scene . fillOptions . map ( function ( fillOptions , i ) {
454430 var cdscatter = cdata [ i ] ;
@@ -459,6 +435,19 @@ function plot(gd, subplot, cdata) {
459435 var lineOptions = scene . lineOptions [ i ] ;
460436 var last , j ;
461437
438+ var fillData = [ ] ;
439+ if ( trace . fill && ( trace . fill . substr ( 0 , 6 ) === 'tozero' || trace . fill === 'toself' ||
440+ ( trace . fill . substr ( 0 , 2 ) === 'to' && ! trace . _prevtrace ) )
441+ ) {
442+ fillData . push ( i )
443+ }
444+ if ( trace . _nexttrace ) {
445+ // make the fill-to-next path now for the NEXT trace, so it shows
446+ // behind both lines.
447+ fillData . push ( i + 1 ) ;
448+ }
449+ if ( fillData . length ) scene . fillOrder [ i ] = fillData ;
450+
462451 var pos = [ ] , srcPos = ( lineOptions && lineOptions . positions ) || stash . positions ;
463452
464453 if ( trace . fill === 'tozeroy' ) {
0 commit comments