Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit db07f46

Browse files
committed
clear axis title on axis redraw
1 parent fc5a73a commit db07f46

File tree

2 files changed

+44
-0
lines changed

2 files changed

+44
-0
lines changed

src/plots/cartesian/axes.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1698,6 +1698,8 @@ axes.doTicks = function(gd, axid, skipTitle) {
16981698
.selectAll('path').remove();
16991699
plotinfo.zerolinelayer
17001700
.selectAll('path').remove();
1701+
fullLayout._infolayer.select('.g-' + xa._id + 'title').remove();
1702+
fullLayout._infolayer.select('.g-' + ya._id + 'title').remove();
17011703
});
17021704
}
17031705

test/jasmine/tests/cartesian_test.js

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -478,4 +478,46 @@ describe('subplot creation / deletion:', function() {
478478
.catch(failTest)
479479
.then(done);
480480
});
481+
482+
it('clear axis ticks, labels and title when relayout an axis to `*visible:false*', function(done) {
483+
function _assert(xaxis, yaxis) {
484+
var g = d3.select('.subplot.xy');
485+
var info = d3.select('.infolayer');
486+
487+
expect(g.selectAll('.xtick').size()).toBe(xaxis[0], 'x tick cnt');
488+
expect(g.selectAll('.gridlayer > .xgrid').size()).toBe(xaxis[1], 'x gridline cnt');
489+
expect(info.selectAll('.g-xtitle').size()).toBe(xaxis[2], 'x title cnt');
490+
491+
expect(g.selectAll('.ytick').size()).toBe(yaxis[0], 'y tick cnt');
492+
expect(g.selectAll('.gridlayer > .ygrid').size()).toBe(yaxis[1], 'y gridline cnt');
493+
expect(info.selectAll('.g-ytitle').size()).toBe(yaxis[2], 'y title cnt');
494+
}
495+
496+
Plotly.plot(gd, [{
497+
y: [1, 2, 1]
498+
}], {
499+
xaxis: {title: 'X'},
500+
yaxis: {title: 'Y'}
501+
})
502+
.then(function() {
503+
_assert([5, 4, 1], [6, 6, 1]);
504+
return Plotly.relayout(gd, 'xaxis.visible', false);
505+
})
506+
.then(function() {
507+
_assert([0, 0, 0], [6, 6, 1]);
508+
return Plotly.relayout(gd, 'yaxis.visible', false);
509+
})
510+
.then(function() {
511+
_assert([0, 0, 0], [0, 0, 0]);
512+
return Plotly.relayout(gd, {
513+
'xaxis.visible': true,
514+
'yaxis.visible': true
515+
});
516+
})
517+
.then(function() {
518+
_assert([5, 4, 1], [6, 6, 1]);
519+
})
520+
.catch(failTest)
521+
.then(done);
522+
});
481523
});

0 commit comments

Comments
 (0)