@@ -127,7 +127,7 @@ exports.finalizeSubplots = function(layoutIn, layoutOut) {
127
127
exports . plot = function ( gd , traces , transitionOpts , makeOnCompleteCallback ) {
128
128
var fullLayout = gd . _fullLayout ;
129
129
var calcdata = gd . calcdata ;
130
- var i ;
130
+ var i , j ;
131
131
132
132
// Traces is a list of trace indices to (re)plot. If it's not provided,
133
133
// then it's a complete replot so we create a new list and add all trace indices
@@ -142,41 +142,65 @@ exports.plot = function(gd, traces, transitionOpts, makeOnCompleteCallback) {
142
142
143
143
var trace ;
144
144
var subplot ;
145
- var subplotZindexGroups = { } ;
145
+ var subplotZorderGroups = { } ;
146
146
for ( var t = 0 ; t < calcdata . length ; t ++ ) {
147
147
trace = calcdata [ t ] [ 0 ] . trace ;
148
- var zi = trace . zindex || 0 ;
148
+ var zi = trace . zorder || 0 ;
149
149
subplot = trace . xaxis + trace . yaxis ;
150
- if ( ! subplotZindexGroups [ zi ] ) subplotZindexGroups [ zi ] = { } ;
151
- if ( ! subplotZindexGroups [ zi ] [ subplot ] ) subplotZindexGroups [ zi ] [ subplot ] = [ ] ;
152
- subplotZindexGroups [ zi ] [ subplot ] . push ( calcdata [ t ] ) ;
150
+ if ( ! subplotZorderGroups [ zi ] ) subplotZorderGroups [ zi ] = { } ;
151
+ if ( ! subplotZorderGroups [ zi ] [ subplot ] ) subplotZorderGroups [ zi ] [ subplot ] = [ ] ;
152
+ subplotZorderGroups [ zi ] [ subplot ] . push ( calcdata [ t ] ) ;
153
153
}
154
- var zindices = Object . keys ( subplotZindexGroups )
154
+ var zindices = Object . keys ( subplotZorderGroups )
155
155
. map ( Number )
156
156
. sort ( Lib . sorterAsc ) ;
157
157
158
+ var prevSubplots = [ ] ;
158
159
var subplots ;
160
+ var zin ;
161
+ var subplotId ;
162
+ var newsubplotZorderGroups = { } ;
163
+ for ( i = 0 ; i < zindices . length ; i ++ ) {
164
+ zin = zindices [ i ] ;
165
+ subplots = Object . keys ( subplotZorderGroups [ zin ] ) ;
166
+
167
+ // For each subplot
168
+ for ( j = 0 ; j < subplots . length ; j ++ ) {
169
+ subplot = subplots [ j ] ;
170
+ if ( prevSubplots . indexOf ( subplot ) === - 1 ) {
171
+ prevSubplots . push ( subplot ) ;
172
+ subplotId = subplot ;
173
+ } else {
174
+ subplotId = subplot + '-over-' + i ;
175
+ }
176
+ if ( ! newsubplotZorderGroups [ zin ] ) newsubplotZorderGroups [ zin ] = { } ;
177
+ if ( ! newsubplotZorderGroups [ zin ] [ subplotId ] ) newsubplotZorderGroups [ zin ] [ subplotId ] = [ ] ;
178
+ newsubplotZorderGroups [ zin ] [ subplotId ] . push ( subplotZorderGroups [ zin ] [ subplot ] ) ;
179
+ }
180
+ }
181
+
159
182
var zindex ;
160
183
var subplotLayerData = { } ;
161
184
for ( i = 0 ; i < zindices . length ; i ++ ) {
162
185
zindex = zindices [ i ] ;
163
- subplots = Object . keys ( subplotZindexGroups [ zindex ] ) ;
186
+ subplots = Object . keys ( newsubplotZorderGroups [ zindex ] ) ;
164
187
165
188
// For each subplot
166
- for ( var j = 0 ; j < subplots . length ; j ++ ) {
189
+ for ( j = 0 ; j < subplots . length ; j ++ ) {
167
190
subplot = subplots [ j ] ;
168
191
var subplotInfo = fullLayout . _plots [ subplot ] ;
169
192
170
193
// Get all calcdata (traces) for this subplot:
171
194
var cdSubplot = [ ] ;
172
195
var pcd ;
173
196
// For each trace
174
- for ( var k = 0 ; k < subplotZindexGroups [ zindex ] [ subplot ] . length ; k ++ ) {
175
- var cd = subplotZindexGroups [ zindex ] [ subplot ] [ k ] ;
197
+ for ( var k = 0 ; k < newsubplotZorderGroups [ zindex ] [ subplot ] . length ; k ++ ) {
198
+ var cd = newsubplotZorderGroups [ zindex ] [ subplot ] [ k ] [ 0 ] ;
176
199
trace = cd [ 0 ] . trace ;
200
+
177
201
// Skip trace if whitelist provided and it's not whitelisted:
178
202
// if (Array.isArray(traces) && traces.indexOf(i) === -1) continue;
179
- if ( trace . xaxis + trace . yaxis === subplot ) {
203
+ if ( trace . xaxis + trace . yaxis === subplot || ( subplot . indexOf ( '-over-' ) !== - 1 && subplot . indexOf ( trace . xaxis + trace . yaxis ) === 0 ) ) {
180
204
// XXX: Should trace carpet dependencies. Only replot all carpet plots if the carpet
181
205
// axis has actually changed:
182
206
//
@@ -240,8 +264,7 @@ function plotOne(gd, plotinfo, cdSubplot, transitionOpts, makeOnCompleteCallback
240
264
241
265
if ( categories . svg ) {
242
266
var classBaseName = ( _module . layerName || name + 'layer' ) ;
243
- //var className = classBaseName + (z ? Number(z) + 1 : '');
244
- var className = classBaseName + '_' + zorder ;
267
+ var className = classBaseName + ( z ? Number ( z ) + 1 : '' ) ;
245
268
var plotMethod = _module . plot ;
246
269
247
270
// plot all visible traces of this type on this subplot at once
@@ -254,7 +277,7 @@ function plotOne(gd, plotinfo, cdSubplot, transitionOpts, makeOnCompleteCallback
254
277
if ( cdModule . length ) {
255
278
layerData . push ( {
256
279
i : traceLayerClasses . indexOf ( classBaseName ) ,
257
- zorder : zorder ,
280
+ zorder : z ,
258
281
className : className ,
259
282
plotMethod : plotMethod ,
260
283
cdModule : cdModule
@@ -397,7 +420,7 @@ exports.drawFramework = function(gd) {
397
420
398
421
var subplotLayers = fullLayout . _cartesianlayer . selectAll ( '.subplot' )
399
422
. data ( subplotData , String ) ;
400
-
423
+
401
424
subplotLayers . enter ( ) . append ( 'g' )
402
425
. attr ( 'class' , function ( d ) { return 'subplot ' + d [ 0 ] ; } ) ;
403
426
@@ -411,7 +434,7 @@ exports.drawFramework = function(gd) {
411
434
var plotinfo = fullLayout . _plots [ id ] ;
412
435
413
436
plotinfo . plotgroup = d3 . select ( this ) ;
414
- makeSubplotLayer ( gd , plotinfo ) ;
437
+ makeSubplotLayer ( gd , plotinfo , id ) ;
415
438
416
439
// make separate drag layers for each subplot,
417
440
// but append them to paper rather than the plot groups,
@@ -421,15 +444,15 @@ exports.drawFramework = function(gd) {
421
444
} ;
422
445
423
446
exports . rangePlot = function ( gd , plotinfo , cdSubplot ) {
424
- makeSubplotLayer ( gd , plotinfo ) ;
447
+ makeSubplotLayer ( gd , plotinfo , plotinfo . id ) ;
425
448
plotOne ( gd , plotinfo , cdSubplot ) ;
426
449
Plots . style ( gd ) ;
427
450
} ;
428
451
429
452
function makeSubplotData ( gd ) {
430
453
var fullLayout = gd . _fullLayout ;
431
454
var ids = fullLayout . _subplots . cartesian ;
432
-
455
+
433
456
var i , j , id , plotinfo , xa , ya ;
434
457
435
458
// split 'regular' and 'overlaying' subplots
@@ -440,35 +463,37 @@ function makeSubplotData(gd) {
440
463
441
464
var trace ;
442
465
var subplot ;
443
- var subplotZindexGroups = { } ;
466
+ var subplotZorderGroups = { } ;
444
467
for ( var t = 0 ; t < calcdata . length ; t ++ ) {
445
468
trace = calcdata [ t ] [ 0 ] . trace ;
446
- var zi = trace . zindex || 0 ;
469
+ var zi = trace . zorder || 0 ;
447
470
subplot = trace . xaxis + trace . yaxis ;
448
- if ( ! subplotZindexGroups [ zi ] ) subplotZindexGroups [ zi ] = { } ;
449
- if ( ! subplotZindexGroups [ zi ] [ subplot ] ) subplotZindexGroups [ zi ] [ subplot ] = [ ] ;
450
- subplotZindexGroups [ zi ] [ subplot ] . push ( calcdata [ t ] ) ;
471
+ if ( ! subplotZorderGroups [ zi ] ) subplotZorderGroups [ zi ] = { } ;
472
+ if ( ! subplotZorderGroups [ zi ] [ subplot ] ) subplotZorderGroups [ zi ] [ subplot ] = [ ] ;
473
+ subplotZorderGroups [ zi ] [ subplot ] . push ( calcdata [ t ] ) ;
451
474
}
452
- var zindices = Object . keys ( subplotZindexGroups )
475
+ var zindices = Object . keys ( subplotZorderGroups )
453
476
. map ( Number )
454
477
. sort ( Lib . sorterAsc ) ;
455
478
var len = zindices . length ;
456
479
480
+ var mainplot ;
481
+ var mainplotinfo ;
457
482
for ( i = 0 ; i < len ; i ++ ) {
458
- var zindex = subplotZindexGroups [ zindices [ i ] ] ;
459
- var ids = Object . keys ( zindex ) ;
460
- for ( var j = 0 ; j < ids . length ; j ++ ) {
461
- var id = ids [ j ] ;
483
+ var zindex = subplotZorderGroups [ zindices [ i ] ] ;
484
+ ids = Object . keys ( zindex ) ;
485
+ for ( j = 0 ; j < ids . length ; j ++ ) {
486
+ id = ids [ j ] ;
462
487
plotinfo = fullLayout . _plots [ id ] ;
463
488
464
- var mainplot = mainplot ? mainplot : id ;
465
- var mainplotinfo = Object . assign ( { } , fullLayout . _plots [ mainplot ] )
489
+ mainplot = mainplot ? mainplot : id ;
490
+ mainplotinfo = fullLayout . _plots [ mainplot ] ;
466
491
plotinfo . overlays = [ ] ;
467
492
468
- if ( regulars . indexOf ( id ) !== - 1 || overlays . indexOf ( id ) !== - 1 ) {
493
+ if ( regulars . indexOf ( id ) !== - 1 || overlays . indexOf ( id ) !== - 1 ) {
469
494
plotinfo . mainplot = mainplot ;
470
495
plotinfo . mainplotinfo = mainplotinfo ;
471
- overlays . push ( id + '-over-' + i ) ;
496
+ overlays . push ( id + '-over-' + i ) ;
472
497
} else if ( mainplot !== id && mainplotinfo ) {
473
498
plotinfo . mainplot = mainplot ;
474
499
plotinfo . mainplotinfo = mainplotinfo ;
@@ -484,8 +509,8 @@ function makeSubplotData(gd) {
484
509
// fill in list of overlaying subplots in 'main plot'
485
510
for ( i = 0 ; i < overlays . length ; i ++ ) {
486
511
id = overlays [ i ] ;
487
- if ( id . indexOf ( '-over-' ) !== - 1 ) {
488
- id = id . split ( " -over-" ) [ 0 ] ;
512
+ if ( id . indexOf ( '-over-' ) !== - 1 ) {
513
+ id = id . split ( ' -over-' ) [ 0 ] ;
489
514
}
490
515
var plotinfoCopy = Object . assign ( { } , fullLayout . _plots [ id ] ) ;
491
516
plotinfoCopy . id = overlays [ i ] ;
@@ -497,34 +522,33 @@ function makeSubplotData(gd) {
497
522
var subplotData = new Array ( subplotIds . length ) ;
498
523
for ( i = 0 ; i < subplotIds . length ; i ++ ) {
499
524
id = subplotIds [ i ] ;
500
- if ( id . indexOf ( '-over-' ) !== - 1 ) {
501
- fullLayout . _plots [ id ] = Object . assign ( { } , fullLayout . _plots [ id . split ( " -over-" ) [ 0 ] ] ) ;
525
+ if ( id . indexOf ( '-over-' ) !== - 1 ) {
526
+ fullLayout . _plots [ id ] = Object . assign ( { } , fullLayout . _plots [ id . split ( ' -over-' ) [ 0 ] ] ) ;
502
527
}
503
528
plotinfo = fullLayout . _plots [ id ] ;
504
529
xa = plotinfo . xaxis ;
505
530
ya = plotinfo . yaxis ;
506
531
507
532
// use info about axis layer and overlaying pattern
508
533
// to clean what need to be cleaned up in exit selection
509
- var d = [ id , xa . layer , ya . layer , xa . overlaying || '' , ya . overlaying || '' ] ;
510
- if ( id . indexOf ( '-over-' ) !== - 1 ) {
534
+ var d = [ id , xa . layer , ya . layer , xa . overlaying || '' , ya . overlaying || '' ] ;
535
+ if ( id . indexOf ( '-over-' ) !== - 1 ) {
511
536
for ( j = 0 ; j < plotinfo . overlays . length ; j ++ ) {
512
537
d . push ( plotinfo . overlays [ j ] . id ) ;
513
538
}
514
- }
539
+ }
515
540
subplotData [ i ] = d ;
516
541
}
517
542
return subplotData ;
518
543
}
519
544
520
- function makeSubplotLayer ( gd , plotinfo ) {
545
+ function makeSubplotLayer ( gd , plotinfo , id ) {
521
546
var plotgroup = plotinfo . plotgroup ;
522
- var id = plotinfo . id ;
523
547
var xLayer = constants . layerValue2layerClass [ plotinfo . xaxis . layer ] ;
524
548
var yLayer = constants . layerValue2layerClass [ plotinfo . yaxis . layer ] ;
525
549
var hasOnlyLargeSploms = gd . _fullLayout . _hasOnlyLargeSploms ;
526
550
527
- if ( ! plotinfo . mainplot || id . indexOf ( '-over-' ) === - 1 ) {
551
+ if ( ! plotinfo . mainplot || ( plotinfo . mainplot === id && id . indexOf ( '-over-' ) === - 1 ) ) {
528
552
if ( hasOnlyLargeSploms ) {
529
553
// TODO could do even better
530
554
// - we don't need plot (but we would have to mock it in lsInner
@@ -590,7 +614,7 @@ function makeSubplotLayer(gd, plotinfo) {
590
614
591
615
ensureSingle ( mainplotinfo . overlinesBelow , 'path' , xId ) ;
592
616
ensureSingle ( mainplotinfo . overlinesBelow , 'path' , yId ) ;
593
-
617
+
594
618
ensureSingle ( mainplotinfo . overaxesBelow , 'g' , xId ) ;
595
619
ensureSingle ( mainplotinfo . overaxesBelow , 'g' , yId ) ;
596
620
@@ -601,7 +625,6 @@ function makeSubplotLayer(gd, plotinfo) {
601
625
602
626
ensureSingle ( mainplotinfo . overaxesAbove , 'g' , xId ) ;
603
627
ensureSingle ( mainplotinfo . overaxesAbove , 'g' , yId ) ;
604
-
605
628
606
629
// set refs to correct layers as determined by 'abovetraces'
607
630
plotinfo . xlines = mainplotgroup . select ( '.overlines-' + xLayer ) . select ( '.' + xId ) ;
@@ -613,15 +636,14 @@ function makeSubplotLayer(gd, plotinfo) {
613
636
// common attributes for all subplots, overlays or not
614
637
615
638
if ( ! hasOnlyLargeSploms ) {
616
- if ( plotinfo . minorGridlayer ) {
639
+ if ( plotinfo . minorGridlayer ) {
617
640
ensureSingleAndAddDatum ( plotinfo . minorGridlayer , 'g' , plotinfo . xaxis . _id ) ;
618
- ensureSingleAndAddDatum ( plotinfo . minorGridlayer , 'g' , plotinfo . yaxis . _id ) ;
619
- plotinfo . minorGridlayer . selectAll ( 'g' )
641
+ ensureSingleAndAddDatum ( plotinfo . minorGridlayer , 'g' , plotinfo . yaxis . _id ) ;
642
+ plotinfo . minorGridlayer . selectAll ( 'g' )
620
643
. map ( function ( d ) { return d [ 0 ] ; } )
621
644
. sort ( axisIds . idSort ) ;
622
-
623
645
}
624
- if ( plotinfo . gridlayer ) {
646
+ if ( plotinfo . gridlayer ) {
625
647
ensureSingleAndAddDatum ( plotinfo . gridlayer , 'g' , plotinfo . xaxis . _id ) ;
626
648
ensureSingleAndAddDatum ( plotinfo . gridlayer , 'g' , plotinfo . yaxis . _id ) ;
627
649
plotinfo . gridlayer . selectAll ( 'g' )
0 commit comments