Skip to content

Commit 6cf847c

Browse files
authoredDec 21, 2018
Merge pull request #3354 from plotly/multicategory-y-axis-clearence
Clear y-axis multicategory secondary ticks and dividers
2 parents 2e1bb3c + 6122355 commit 6cf847c

File tree

2 files changed

+65
-0
lines changed

2 files changed

+65
-0
lines changed
 

‎src/plots/cartesian/axes.js

+4
Original file line numberDiff line numberDiff line change
@@ -1585,9 +1585,13 @@ axes.draw = function(gd, arg, opts) {
15851585
plotinfo.xaxislayer.selectAll('.' + xa._id + 'tick').remove();
15861586
plotinfo.yaxislayer.selectAll('.' + ya._id + 'tick').remove();
15871587
plotinfo.xaxislayer.selectAll('.' + xa._id + 'tick2').remove();
1588+
plotinfo.yaxislayer.selectAll('.' + ya._id + 'tick2').remove();
15881589
plotinfo.xaxislayer.selectAll('.' + xa._id + 'divider').remove();
1590+
plotinfo.yaxislayer.selectAll('.' + ya._id + 'divider').remove();
1591+
15891592
if(plotinfo.gridlayer) plotinfo.gridlayer.selectAll('path').remove();
15901593
if(plotinfo.zerolinelayer) plotinfo.zerolinelayer.selectAll('path').remove();
1594+
15911595
fullLayout._infolayer.select('.g-' + xa._id + 'title').remove();
15921596
fullLayout._infolayer.select('.g-' + ya._id + 'title').remove();
15931597
});

‎test/jasmine/tests/cartesian_test.js

+61
Original file line numberDiff line numberDiff line change
@@ -907,4 +907,65 @@ describe('subplot creation / deletion:', function() {
907907
.catch(failTest)
908908
.then(done);
909909
});
910+
911+
it('clears secondary labels and divider when updating out of axis type multicategory (y-axis case)', function(done) {
912+
function _assert(msg, exp) {
913+
var gd3 = d3.select(gd);
914+
expect(gd3.selectAll('.ytick > text').size())
915+
.toBe(exp.tickCnt, msg + ' # labels');
916+
expect(gd3.selectAll('.ytick2 > text').size())
917+
.toBe(exp.tick2Cnt, msg + ' # secondary labels');
918+
expect(gd3.selectAll('.ydivider').size())
919+
.toBe(exp.dividerCnt, msg + ' # dividers');
920+
}
921+
922+
Plotly.react(gd, [{
923+
type: 'bar',
924+
orientation: 'h',
925+
y: ['a', 'b', 'c'],
926+
x: [1, 2, 1]
927+
}])
928+
.then(function() {
929+
_assert('base - category axis', {
930+
tickCnt: 3,
931+
tick2Cnt: 0,
932+
dividerCnt: 0
933+
});
934+
})
935+
.then(function() {
936+
return Plotly.react(gd, [{
937+
type: 'bar',
938+
orientation: 'h',
939+
y: [
940+
['d', 'd', 'e'],
941+
['a', 'b', 'c']
942+
],
943+
x: [1, 2, 3]
944+
}]);
945+
})
946+
.then(function() {
947+
_assert('multicategory axis', {
948+
tickCnt: 3,
949+
tick2Cnt: 2,
950+
dividerCnt: 3
951+
});
952+
})
953+
.then(function() {
954+
return Plotly.react(gd, [{
955+
type: 'bar',
956+
orientation: 'h',
957+
y: ['a', 'b', 'c'],
958+
x: [1, 2, 1]
959+
}]);
960+
})
961+
.then(function() {
962+
_assert('back to category axis', {
963+
tickCnt: 3,
964+
tick2Cnt: 0,
965+
dividerCnt: 0
966+
});
967+
})
968+
.catch(failTest)
969+
.then(done);
970+
});
910971
});

0 commit comments

Comments
 (0)
Please sign in to comment.