Skip to content

Commit c88c167

Browse files
committed
fix updates out of multicategory axis type
1 parent c855e26 commit c88c167

File tree

2 files changed

+60
-4
lines changed

2 files changed

+60
-4
lines changed

src/plots/cartesian/axes.js

+2-4
Original file line numberDiff line numberDiff line change
@@ -1584,10 +1584,8 @@ axes.draw = function(gd, arg, opts) {
15841584

15851585
plotinfo.xaxislayer.selectAll('.' + xa._id + 'tick').remove();
15861586
plotinfo.yaxislayer.selectAll('.' + ya._id + 'tick').remove();
1587-
if(xa.type === 'multicategory') {
1588-
plotinfo.xaxislayer.selectAll('.' + xa._id + 'tick2').remove();
1589-
plotinfo.xaxislayer.selectAll('.' + xa._id + 'divider').remove();
1590-
}
1587+
plotinfo.xaxislayer.selectAll('.' + xa._id + 'tick2').remove();
1588+
plotinfo.xaxislayer.selectAll('.' + xa._id + 'divider').remove();
15911589
if(plotinfo.gridlayer) plotinfo.gridlayer.selectAll('path').remove();
15921590
if(plotinfo.zerolinelayer) plotinfo.zerolinelayer.selectAll('path').remove();
15931591
fullLayout._infolayer.select('.g-' + xa._id + 'title').remove();

test/jasmine/tests/cartesian_test.js

+58
Original file line numberDiff line numberDiff line change
@@ -849,4 +849,62 @@ describe('subplot creation / deletion:', function() {
849849
.catch(failTest)
850850
.then(done);
851851
});
852+
853+
it('clears secondary labels and divider when updating out of axis type multicategory', function(done) {
854+
function _assert(msg, exp) {
855+
var gd3 = d3.select(gd);
856+
expect(gd3.selectAll('.xtick > text').size())
857+
.toBe(exp.tickCnt, msg + ' # labels');
858+
expect(gd3.selectAll('.xtick2 > text').size())
859+
.toBe(exp.tick2Cnt, msg + ' # secondary labels');
860+
expect(gd3.selectAll('.xdivider').size())
861+
.toBe(exp.dividerCnt, msg + ' # dividers');
862+
}
863+
864+
Plotly.react(gd, [{
865+
type: 'bar',
866+
x: ['a', 'b', 'c'],
867+
y: [1, 2, 1]
868+
}])
869+
.then(function() {
870+
_assert('base - category axis', {
871+
tickCnt: 3,
872+
tick2Cnt: 0,
873+
dividerCnt: 0
874+
});
875+
})
876+
.then(function() {
877+
return Plotly.react(gd, [{
878+
type: 'bar',
879+
x: [
880+
['d', 'd', 'e'],
881+
['a', 'b', 'c']
882+
],
883+
y: [1, 2, 3]
884+
}]);
885+
})
886+
.then(function() {
887+
_assert('multicategory axis', {
888+
tickCnt: 3,
889+
tick2Cnt: 2,
890+
dividerCnt: 3
891+
});
892+
})
893+
.then(function() {
894+
return Plotly.react(gd, [{
895+
type: 'bar',
896+
x: ['a', 'b', 'c'],
897+
y: [1, 2, 1]
898+
}]);
899+
})
900+
.then(function() {
901+
_assert('back to category axis', {
902+
tickCnt: 3,
903+
tick2Cnt: 0,
904+
dividerCnt: 0
905+
});
906+
})
907+
.catch(failTest)
908+
.then(done);
909+
});
852910
});

0 commit comments

Comments
 (0)