Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Multicategory inside ticks fixes #3326

Merged
merged 3 commits into from
Dec 14, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions src/plots/cartesian/axes.js
Original file line number Diff line number Diff line change
Expand Up @@ -1584,10 +1584,8 @@ axes.draw = function(gd, arg, opts) {

plotinfo.xaxislayer.selectAll('.' + xa._id + 'tick').remove();
plotinfo.yaxislayer.selectAll('.' + ya._id + 'tick').remove();
if(xa.type === 'multicategory') {
plotinfo.xaxislayer.selectAll('.' + xa._id + 'tick2').remove();
plotinfo.xaxislayer.selectAll('.' + xa._id + 'divider').remove();
}
plotinfo.xaxislayer.selectAll('.' + xa._id + 'tick2').remove();
plotinfo.xaxislayer.selectAll('.' + xa._id + 'divider').remove();
if(plotinfo.gridlayer) plotinfo.gridlayer.selectAll('path').remove();
if(plotinfo.zerolinelayer) plotinfo.zerolinelayer.selectAll('path').remove();
fullLayout._infolayer.select('.g-' + xa._id + 'title').remove();
Expand Down Expand Up @@ -1781,11 +1779,12 @@ axes.drawOne = function(gd, ax, opts) {
if(ax.type === 'multicategory') {
var labelLength = 0;
var pad = {x: 2, y: 10}[axLetter];
archmoj marked this conversation as resolved.
Show resolved Hide resolved
var sgn = tickSigns[2] * (ax.ticks === 'inside' ? -1 : 1);

seq.push(function() {
labelLength += getLabelLevelSpan(ax, axId + 'tick') + pad;
labelLength += ax._tickAngles[axId + 'tick'] ? ax.tickfont.size * LINE_SPACING : 0;
var secondaryPosition = mainLinePosition + labelLength * tickSigns[2];
var secondaryPosition = mainLinePosition + labelLength * sgn;
var secondaryLabelFns = axes.makeLabelFns(ax, secondaryPosition);

return axes.drawLabels(gd, ax, {
Expand All @@ -1803,11 +1802,12 @@ axes.drawOne = function(gd, ax, opts) {

seq.push(function() {
labelLength += getLabelLevelSpan(ax, axId + 'tick2');
ax._labelLength = labelLength;

return drawDividers(gd, ax, {
vals: dividerVals,
layer: mainAxLayer,
path: axes.makeTickPath(ax, mainLinePosition, tickSigns[2], labelLength),
path: axes.makeTickPath(ax, mainLinePosition, sgn, labelLength),
transFn: transFn
});
});
Expand Down Expand Up @@ -2608,7 +2608,7 @@ function drawTitle(gd, ax) {

var titleStandoff;
if(ax.type === 'multicategory') {
titleStandoff = ax._boundingBox[{x: 'height', y: 'width'}[axLetter]];
titleStandoff = ax._labelLength;
} else {
var offsetBase = 1.5;
titleStandoff = 10 + fontSize * offsetBase + (ax.linewidth ? ax.linewidth - 1 : 0);
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified test/image/baselines/multicategory-mirror.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified test/image/baselines/multicategory.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
76 changes: 76 additions & 0 deletions test/image/mocks/multicategory-inside-ticks.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
{
"data": [
{
"type": "bar",
"x": [
["2017", "2017", "2017", "2017", "2018", "2018", "2018"],
["q1", "q2", "q3", "q4", "q1", "q2", "q3" ]
],
"y": [1, 2, 3, 1, 3, 2, 3, 1]
archmoj marked this conversation as resolved.
Show resolved Hide resolved
},
{
"type": "bar",
"x": [
["2017", "2017", "2017", "2017", "2018", "2018", "2018"],
["q1", "q2", "q3", "q4", "q1", "q2", "q3"]
],
"y": [1.12, 2.15, 3.07, 1.48, 2.78, 1.95, 2.54, 0.64]
archmoj marked this conversation as resolved.
Show resolved Hide resolved
},

{
"type": "bar",
"x": [
["2017", "2017", "2017", "2017", "2018", "2018", "2018"],
["q1", "q2", "q3", "q4", "q1", "q2", "q3"]
],
"y": [1.12, 2.15, 3.07, 1.48, 2.78, 1.95, 2.54, 0.64],
archmoj marked this conversation as resolved.
Show resolved Hide resolved
"xaxis": "x2",
"yaxis": "y2"
},
{
"type": "bar",
"x": [
["2017", "2017", "2017", "2017", "2018", "2018", "2018"],
["q1", "q2", "q3", "q4", "q1", "q2", "q3" ]
],
"y": [1, 2, 3, 1, 3, 2, 3, 1],
archmoj marked this conversation as resolved.
Show resolved Hide resolved
"xaxis": "x2",
"yaxis": "y2"
}
],
"layout": {
archmoj marked this conversation as resolved.
Show resolved Hide resolved
"grid": {"rows": 2, "columns": 1, "pattern": "independent"},
"xaxis": {
"side": "top",
"title": "MULTI-CATEGORY",
"range": [-0.5, 7],
"showline": true,
"tickfont": {"size": 16},
"ticks": "inside",
archmoj marked this conversation as resolved.
Show resolved Hide resolved
"ticklen": 10,
archmoj marked this conversation as resolved.
Show resolved Hide resolved
"tickcolor": "red",
"tickwidth": 2,
"dividercolor": "blue",
"dividerwidth": 2
},
"xaxis2": {
"title": "MULTI-CATEGORY",
"range": [-1, 6.5],
"showline": true,
"tickfont": {"size": 16},
"ticks": "inside",
"ticklen": 10,
"tickcolor": "red",
"tickwidth": 2,
archmoj marked this conversation as resolved.
Show resolved Hide resolved
"dividercolor": "blue",
"dividerwidth": 2
},
"yaxis": {
"zeroline": false
},
"yaxis2": {
"zeroline": false
},
"showlegend": false
}
}
1 change: 1 addition & 0 deletions test/image/mocks/multicategory-mirror.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
],
"layout": {
"xaxis": {
"title": "MULTI-CATEGORY",
"ticks": "outside",
"showline": true,
"mirror": "ticks",
Expand Down
58 changes: 58 additions & 0 deletions test/jasmine/tests/cartesian_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -849,4 +849,62 @@ describe('subplot creation / deletion:', function() {
.catch(failTest)
.then(done);
});

it('clears secondary labels and divider when updating out of axis type multicategory', function(done) {
function _assert(msg, exp) {
var gd3 = d3.select(gd);
expect(gd3.selectAll('.xtick > text').size())
.toBe(exp.tickCnt, msg + ' # labels');
expect(gd3.selectAll('.xtick2 > text').size())
.toBe(exp.tick2Cnt, msg + ' # secondary labels');
expect(gd3.selectAll('.xdivider').size())
.toBe(exp.dividerCnt, msg + ' # dividers');
}

Plotly.react(gd, [{
type: 'bar',
x: ['a', 'b', 'c'],
y: [1, 2, 1]
}])
.then(function() {
_assert('base - category axis', {
tickCnt: 3,
tick2Cnt: 0,
dividerCnt: 0
});
})
.then(function() {
return Plotly.react(gd, [{
type: 'bar',
x: [
['d', 'd', 'e'],
['a', 'b', 'c']
],
y: [1, 2, 3]
}]);
})
.then(function() {
_assert('multicategory axis', {
tickCnt: 3,
tick2Cnt: 2,
dividerCnt: 3
});
})
.then(function() {
return Plotly.react(gd, [{
type: 'bar',
x: ['a', 'b', 'c'],
y: [1, 2, 1]
}]);
})
.then(function() {
_assert('back to category axis', {
tickCnt: 3,
tick2Cnt: 0,
dividerCnt: 0
});
})
.catch(failTest)
.then(done);
});
});