Skip to content

Commit 8a8deda

Browse files
committed
Auto assign bottom subplot in overlaying with zindex
1 parent e2dab8e commit 8a8deda

File tree

2 files changed

+53
-60
lines changed

2 files changed

+53
-60
lines changed

Diff for: src/plots/cartesian/index.js

+46-55
Original file line numberDiff line numberDiff line change
@@ -275,7 +275,6 @@ function plotOne(gd, plotinfo, cdSubplot, transitionOpts, makeOnCompleteCallback
275275
.attr('class', function(d) { return d.className; })
276276
.classed('mlayer', true)
277277
.classed('rangeplot', plotinfo.isRangePlot);
278-
279278
layers.exit().remove();
280279

281280
layers.order();
@@ -395,12 +394,11 @@ exports.drawFramework = function(gd) {
395394
subplotLayers.enter().append('g')
396395
.attr('class', function(d) { return 'subplot ' + d[0]; });
397396

398-
//subplotLayers.order();
397+
subplotLayers.order();
398+
399+
subplotLayers.exit()
400+
.call(purgeSubplotLayers, fullLayout);
399401

400-
//subplotLayers.exit()
401-
// .call(purgeSubplotLayers, fullLayout);
402-
console.log("Subplotlayers")
403-
console.log(subplotLayers)
404402
subplotLayers.each(function(d) {
405403
var id = d[0];
406404
var plotinfo = fullLayout._plots[id];
@@ -424,7 +422,7 @@ exports.rangePlot = function(gd, plotinfo, cdSubplot) {
424422
function makeSubplotData(gd) {
425423
var fullLayout = gd._fullLayout;
426424
var ids = fullLayout._subplots.cartesian;
427-
var len = ids.length;
425+
428426
var i, j, id, plotinfo, xa, ya;
429427

430428
// split 'regular' and 'overlaying' subplots
@@ -447,29 +445,24 @@ function makeSubplotData(gd) {
447445
var zindices = Object.keys(subplotZindexGroups)
448446
.map(Number)
449447
.sort(Lib.sorterAsc);
450-
451-
console.log(subplotZindexGroups)
448+
var len = zindices.length;
452449

453-
for(i = 0; i < zindices.length; i++) {
454-
console.log(i)
450+
for(i = 0; i < len; i++) {
455451
var zindex = subplotZindexGroups[zindices[i]];
456-
console.log(zindex)
457-
console.log()
458452
var ids = Object.keys(zindex);
459453
for(var j=0; j<ids.length; j++) {
460454
var id = ids[j];
461455
plotinfo = fullLayout._plots[id];
462-
//xa = plotinfo.xaxis;
463-
//ya = plotinfo.yaxis;
464456

465-
//var xa2 = xa._mainAxis;
466-
//var ya2 = ya._mainAxis;
467-
var mainplot = mainplot ? mainplot : id;//xa2._id + ya2._id;
468-
var mainplotinfo = fullLayout._plots[mainplot];
457+
var mainplot = mainplot ? mainplot : id;
458+
var mainplotinfo = Object.assign({}, fullLayout._plots[mainplot])
469459
plotinfo.overlays = [];
470460

471-
if(i!==0) {//if(mainplot !== id && mainplotinfo) {
472-
console.log("hererere")
461+
if (regulars.indexOf(id) !== -1 || overlays.indexOf(id) !== -1 ){
462+
plotinfo.mainplot = mainplot;
463+
plotinfo.mainplotinfo = mainplotinfo;
464+
overlays.push(id+'-over-'+i);
465+
} else if(mainplot !== id && mainplotinfo) {
473466
plotinfo.mainplot = mainplot;
474467
plotinfo.mainplotinfo = mainplotinfo;
475468
overlays.push(id);
@@ -478,44 +471,40 @@ function makeSubplotData(gd) {
478471
plotinfo.mainplotinfo = undefined;
479472
regulars.push(id);
480473
}
481-
console.log(".....")
482474
}
483-
484-
}
485-
console.log(plotinfo.mainplotinfo)
486-
console.log("----")
487-
console.log(regulars, overlays)
488-
function onlyUnique(value, index, array) {
489-
return array.indexOf(value) === index;
490475
}
491476

492-
regulars = regulars.filter(onlyUnique);
493-
overlays = overlays.filter(onlyUnique);
494-
console.log(regulars, overlays)
495477
// fill in list of overlaying subplots in 'main plot'
496478
for(i = 0; i < overlays.length; i++) {
497479
id = overlays[i];
498-
plotinfo = fullLayout._plots[id];
499-
plotinfo.mainplotinfo.overlays.push(plotinfo);
480+
if (id.indexOf('-over-')!==-1) {
481+
id = id.split("-over-")[0];
482+
}
483+
var plotinfoCopy = Object.assign({}, fullLayout._plots[id]);
484+
plotinfoCopy.id = overlays[i];
485+
fullLayout._plots[id].mainplotinfo.overlays.push(plotinfoCopy);
500486
}
501487

502488
// put 'regular' subplot data before 'overlaying'
503489
var subplotIds = regulars.concat(overlays);
504-
var subplotData = new Array(len);
505-
506-
for(i = 0; i < len; i++) {
490+
var subplotData = new Array(subplotIds.length);
491+
for(i = 0; i < subplotIds.length; i++) {
507492
id = subplotIds[i];
493+
if (id.indexOf('-over-')!==-1) {
494+
fullLayout._plots[id] = Object.assign({}, fullLayout._plots[id.split("-over-")[0]]);
495+
}
508496
plotinfo = fullLayout._plots[id];
509-
console.log(id, plotinfo)
510497
xa = plotinfo.xaxis;
511498
ya = plotinfo.yaxis;
512499

513500
// use info about axis layer and overlaying pattern
514501
// to clean what need to be cleaned up in exit selection
515-
var d = [id, xa.layer, ya.layer, xa.overlaying || '', ya.overlaying || ''];
516-
for(j = 0; j < plotinfo.overlays.length; j++) {
517-
d.push(plotinfo.overlays[j].id);
518-
}
502+
var d = [id, xa.layer, ya.layer, xa.overlaying || '' , ya.overlaying || ''];
503+
if (id.indexOf('-over-')!==-1){
504+
for(j = 0; j < plotinfo.overlays.length; j++) {
505+
d.push(plotinfo.overlays[j].id);
506+
}
507+
}
519508
subplotData[i] = d;
520509
}
521510
return subplotData;
@@ -528,7 +517,7 @@ function makeSubplotLayer(gd, plotinfo) {
528517
var yLayer = constants.layerValue2layerClass[plotinfo.yaxis.layer];
529518
var hasOnlyLargeSploms = gd._fullLayout._hasOnlyLargeSploms;
530519

531-
if(!plotinfo.mainplot) {
520+
if(!plotinfo.mainplot || id.indexOf('-over-') === -1) {
532521
if(hasOnlyLargeSploms) {
533522
// TODO could do even better
534523
// - we don't need plot (but we would have to mock it in lsInner
@@ -587,22 +576,21 @@ function makeSubplotLayer(gd, plotinfo) {
587576
plotinfo.minorGridlayer = mainplotinfo.minorGridlayer;
588577
plotinfo.gridlayer = mainplotinfo.gridlayer;
589578
plotinfo.zerolinelayer = mainplotinfo.zerolinelayer;
590-
console.log(xId)
591-
console.log(mainplotinfo)
592-
console.log(mainplotinfo.overlinesBelow)
593-
ensureSingle(mainplotinfo.overlinesBelow, 'path', xId);
594-
console.log(yId)
595579

580+
ensureSingle(mainplotinfo.overlinesBelow, 'path', xId);
596581
ensureSingle(mainplotinfo.overlinesBelow, 'path', yId);
582+
597583
ensureSingle(mainplotinfo.overaxesBelow, 'g', xId);
598584
ensureSingle(mainplotinfo.overaxesBelow, 'g', yId);
599585

600586
plotinfo.plot = ensureSingle(mainplotinfo.overplot, 'g', id);
601587

602588
ensureSingle(mainplotinfo.overlinesAbove, 'path', xId);
603589
ensureSingle(mainplotinfo.overlinesAbove, 'path', yId);
590+
604591
ensureSingle(mainplotinfo.overaxesAbove, 'g', xId);
605592
ensureSingle(mainplotinfo.overaxesAbove, 'g', yId);
593+
606594

607595
// set refs to correct layers as determined by 'abovetraces'
608596
plotinfo.xlines = mainplotgroup.select('.overlines-' + xLayer).select('.' + xId);
@@ -614,17 +602,21 @@ function makeSubplotLayer(gd, plotinfo) {
614602
// common attributes for all subplots, overlays or not
615603

616604
if(!hasOnlyLargeSploms) {
617-
ensureSingleAndAddDatum(plotinfo.minorGridlayer, 'g', plotinfo.xaxis._id);
605+
if (plotinfo.minorGridlayer){
606+
ensureSingleAndAddDatum(plotinfo.minorGridlayer, 'g', plotinfo.xaxis._id);
618607
ensureSingleAndAddDatum(plotinfo.minorGridlayer, 'g', plotinfo.yaxis._id);
619608
plotinfo.minorGridlayer.selectAll('g')
620609
.map(function(d) { return d[0]; })
621610
.sort(axisIds.idSort);
622611

623-
ensureSingleAndAddDatum(plotinfo.gridlayer, 'g', plotinfo.xaxis._id);
624-
ensureSingleAndAddDatum(plotinfo.gridlayer, 'g', plotinfo.yaxis._id);
625-
plotinfo.gridlayer.selectAll('g')
626-
.map(function(d) { return d[0]; })
627-
.sort(axisIds.idSort);
612+
}
613+
if (plotinfo.gridlayer){
614+
ensureSingleAndAddDatum(plotinfo.gridlayer, 'g', plotinfo.xaxis._id);
615+
ensureSingleAndAddDatum(plotinfo.gridlayer, 'g', plotinfo.yaxis._id);
616+
plotinfo.gridlayer.selectAll('g')
617+
.map(function(d) { return d[0]; })
618+
.sort(axisIds.idSort);
619+
}
628620
}
629621

630622
plotinfo.xlines
@@ -634,7 +626,6 @@ function makeSubplotLayer(gd, plotinfo) {
634626
plotinfo.ylines
635627
.style('fill', 'none')
636628
.classed('crisp', true);
637-
console.log("ñññññ")
638629
}
639630

640631
function purgeSubplotLayers(layers, fullLayout) {

Diff for: test/image/mocks/zindex_mult_axes.json

+7-5
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
"marker": {"size": 20},
99
"line": {"width": 6},
1010
"yaxis": "y",
11-
"zindex": 5
11+
"zindex": 10
1212
},
1313
{
1414
"x": [2, 3, 4, 5, 6],
@@ -18,7 +18,7 @@
1818
"marker": {"size": 20},
1919
"line": {"width": 6},
2020
"yaxis": "y",
21-
"zindex": 1
21+
"zindex": 5
2222
},
2323
{
2424
"x": [3, 4, 5, 6, 7],
@@ -27,7 +27,8 @@
2727
"type": "scatter",
2828
"marker": {"size": 20},
2929
"line": {"width": 6},
30-
"yaxis": "y2"
30+
"yaxis": "y2",
31+
"zindex": 7
3132
},
3233

3334
{
@@ -36,7 +37,7 @@
3637
"name": "bar",
3738
"type": "bar",
3839
"yaxis": "y2",
39-
"zindex": 20
40+
"zindex": 8
4041
}
4142
],
4243
"layout": {
@@ -46,7 +47,8 @@
4647
}
4748
},
4849
"yaxis": {
49-
"side": "right"
50+
"side": "right",
51+
"title":{"text":"y"}
5052
},
5153
"y2axis": {
5254
"title":{"text":"y2"}, "overlaying": "y"

0 commit comments

Comments
 (0)