Skip to content

Commit 394ce6e

Browse files
author
Bruno Pommier
committed
fix(cartesian): preserve axis lines across zorder layers
1 parent 0316e60 commit 394ce6e

3 files changed

Lines changed: 48 additions & 0 deletions

File tree

‎draftlogs/PR_NUMBER_fix.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
- Fix missing axis lines for traces with different `zorder` values [[#PR_NUMBER](https://github.com/plotly/plotly.js/pull/PR_NUMBER)]

‎src/plot_api/subroutines.js‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -264,6 +264,8 @@ function lsInner(gd) {
264264
}
265265

266266
for(subplot in fullLayout._plots) {
267+
// Z-order subplots share axis lines with their primary subplot.
268+
if (subplot.indexOf(zindexSeparator) !== -1) continue;
267269
plotinfo = fullLayout._plots[subplot];
268270
xa = plotinfo.xaxis;
269271
ya = plotinfo.yaxis;

‎test/jasmine/tests/cartesian_test.js‎

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -347,6 +347,51 @@ describe('relayout', function() {
347347

348348
afterEach(destroyGraphDiv);
349349

350+
['scatter', 'bar'].forEach((type) => {
351+
it(`preserves axis lines across zorder layers for ${type} traces`, async () => {
352+
const assertLineLengths = (layer, xLength, yLength) => {
353+
expect(gd.querySelector(`.xlines-${layer}`).getTotalLength()).toBeCloseTo(xLength, 5);
354+
expect(gd.querySelector(`.ylines-${layer}`).getTotalLength()).toBeCloseTo(yLength, 5);
355+
};
356+
357+
await Plotly.newPlot(gd, [
358+
{type, x: [1, 2], y: [1, 2], zorder: -1},
359+
{type, x: [1, 2], y: [2, 1]},
360+
{type, x: [1, 2], y: [3, 2], zorder: 2}
361+
], {
362+
width: 400,
363+
height: 400,
364+
margin: {l: 50, r: 50, t: 50, b: 50},
365+
showlegend: false,
366+
xaxis: {range: [0, 4], showline: true, linewidth: 2},
367+
yaxis: {range: [0, 4], showline: true, linewidth: 2}
368+
});
369+
assertLineLengths('above', 302, 300);
370+
371+
await Plotly.restyle(gd, {zorder: [0, 0, 0]});
372+
assertLineLengths('above', 302, 300);
373+
374+
await Plotly.restyle(gd, {zorder: [-1, 0, 2]});
375+
assertLineLengths('above', 302, 300);
376+
377+
await Plotly.relayout(gd, {'xaxis.showline': false, 'yaxis.showline': false});
378+
assertLineLengths('above', 0, 0);
379+
380+
await Plotly.relayout(gd, {
381+
'xaxis.showline': true,
382+
'yaxis.showline': true,
383+
'xaxis.layer': 'below traces',
384+
'yaxis.layer': 'below traces',
385+
'xaxis.mirror': true,
386+
'yaxis.mirror': true
387+
});
388+
assertLineLengths('below', 608, 600);
389+
390+
await Plotly.relayout(gd, {width: 500, height: 450});
391+
assertLineLengths('below', 808, 700);
392+
});
393+
});
394+
350395
it('can show and hide axis lines', function(done) {
351396
Plotly.newPlot(gd, [{y: [1, 2]}], {width: 400, height: 400})
352397
.then(function() {

0 commit comments

Comments
 (0)