diff --git a/draftlogs/6312_fix.md b/draftlogs/6312_fix.md new file mode 100644 index 00000000000..282fc028424 --- /dev/null +++ b/draftlogs/6312_fix.md @@ -0,0 +1 @@ +Fix bug with automargin and axis titles [[#6312](https://github.com/plotly/plotly.js/pull/6312)] \ No newline at end of file diff --git a/src/plot_api/plot_api.js b/src/plot_api/plot_api.js index ef16b6e5f51..77fd6ee9ccc 100644 --- a/src/plot_api/plot_api.js +++ b/src/plot_api/plot_api.js @@ -1888,8 +1888,6 @@ function addAxRangeSequence(seq, rangesAltered) { } } } - - if(ax.automargin) skipTitle = false; } return Axes.draw(gd, axIds, {skipTitle: skipTitle}); diff --git a/test/image/baselines/z-automargin-zoom.png b/test/image/baselines/z-automargin-zoom.png new file mode 100644 index 00000000000..2bd98d4dba3 Binary files /dev/null and b/test/image/baselines/z-automargin-zoom.png differ diff --git a/test/image/mocks/z-automargin-zoom.json b/test/image/mocks/z-automargin-zoom.json new file mode 100644 index 00000000000..8be883c2fad --- /dev/null +++ b/test/image/mocks/z-automargin-zoom.json @@ -0,0 +1,60 @@ +{"data": [{ + "showlegend": false, + "type": "scatter", + "x": [ + "@100000001", + "@100000002", + "@100000003", + "@100000004", + "@100000005", + "@100000006", + "@100000007", + "@100000008", + "@100000009", + "@100000010", + "@100000011", + "@100000012", + "@100000013", + "@100000014", + "@100000015", + "@100000016", + "@100000017", + "@100000018", + "@100000019" + ], + "xaxis": "x", + "y": [ + 100, + 101, + 99, + 101, + 98, + 97, + 101, + 102, + 109, + 110, + 110, + 102, + 93, + 114, + 115, + 115, + 171, + 185, + 190 + ], + "yaxis": "y" + }], + "layout": { + "height": 400, + "width": 700, + "xaxis": { + "title": {"text": "Revision"}, + "automargin": true + }, + "yaxis": { + "automargin": true + } + } +} diff --git a/test/jasmine/tests/axes_test.js b/test/jasmine/tests/axes_test.js index 019c6351dae..14b9419ebcf 100644 --- a/test/jasmine/tests/axes_test.js +++ b/test/jasmine/tests/axes_test.js @@ -4376,6 +4376,31 @@ describe('Test axes', function() { }) .then(done, done.fail); }); + it('should respect axis title placement on relayout', function(done) { + function getPos(gd, sel) { + return d3Select(gd).select(sel).node().getBoundingClientRect(); + } + + // Tick position is < title position since 0 is at the top of the graph, + // rather than at the bottom. We're checking that the ticks and title don't overlap + function assertLayout() { + var titleTop = getPos(gd, '.xtitle').top; + var tickBottom = getPos(gd, '.xtick').bottom; + expect(tickBottom).toBeLessThan(titleTop + 2); // allow two pixels tolerance + } + + var fig = require('@mocks/z-automargin-zoom.json'); + Plotly.newPlot(gd, fig) + + .then(assertLayout) + .then(function() { + return Plotly.relayout(gd, {'xaxis.range': [6, 14]}); + }) + .then(function() { + assertLayout(); + }) + .then(done, done.fail); + }); }); describe('zeroline visibility logic', function() {