From db07f469a75980849e8add1967a0a8f92649ed38 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Etienne=20T=C3=A9treault-Pinard?= Date: Fri, 1 Sep 2017 17:55:40 -0400 Subject: [PATCH] clear axis title on axis redraw --- src/plots/cartesian/axes.js | 2 ++ test/jasmine/tests/cartesian_test.js | 42 ++++++++++++++++++++++++++++ 2 files changed, 44 insertions(+) diff --git a/src/plots/cartesian/axes.js b/src/plots/cartesian/axes.js index 25d5f02f597..ed976a0e6d1 100644 --- a/src/plots/cartesian/axes.js +++ b/src/plots/cartesian/axes.js @@ -1698,6 +1698,8 @@ axes.doTicks = function(gd, axid, skipTitle) { .selectAll('path').remove(); plotinfo.zerolinelayer .selectAll('path').remove(); + fullLayout._infolayer.select('.g-' + xa._id + 'title').remove(); + fullLayout._infolayer.select('.g-' + ya._id + 'title').remove(); }); } diff --git a/test/jasmine/tests/cartesian_test.js b/test/jasmine/tests/cartesian_test.js index 324d3789f87..415ccc0e20d 100644 --- a/test/jasmine/tests/cartesian_test.js +++ b/test/jasmine/tests/cartesian_test.js @@ -478,4 +478,46 @@ describe('subplot creation / deletion:', function() { .catch(failTest) .then(done); }); + + it('clear axis ticks, labels and title when relayout an axis to `*visible:false*', function(done) { + function _assert(xaxis, yaxis) { + var g = d3.select('.subplot.xy'); + var info = d3.select('.infolayer'); + + expect(g.selectAll('.xtick').size()).toBe(xaxis[0], 'x tick cnt'); + expect(g.selectAll('.gridlayer > .xgrid').size()).toBe(xaxis[1], 'x gridline cnt'); + expect(info.selectAll('.g-xtitle').size()).toBe(xaxis[2], 'x title cnt'); + + expect(g.selectAll('.ytick').size()).toBe(yaxis[0], 'y tick cnt'); + expect(g.selectAll('.gridlayer > .ygrid').size()).toBe(yaxis[1], 'y gridline cnt'); + expect(info.selectAll('.g-ytitle').size()).toBe(yaxis[2], 'y title cnt'); + } + + Plotly.plot(gd, [{ + y: [1, 2, 1] + }], { + xaxis: {title: 'X'}, + yaxis: {title: 'Y'} + }) + .then(function() { + _assert([5, 4, 1], [6, 6, 1]); + return Plotly.relayout(gd, 'xaxis.visible', false); + }) + .then(function() { + _assert([0, 0, 0], [6, 6, 1]); + return Plotly.relayout(gd, 'yaxis.visible', false); + }) + .then(function() { + _assert([0, 0, 0], [0, 0, 0]); + return Plotly.relayout(gd, { + 'xaxis.visible': true, + 'yaxis.visible': true + }); + }) + .then(function() { + _assert([5, 4, 1], [6, 6, 1]); + }) + .catch(failTest) + .then(done); + }); });