Skip to content

Commit c855e26

Browse files
committed
fix multicategory axes with inside ticks
... where dividers and ticks go in opposite directions
1 parent 71dc6b7 commit c855e26

File tree

4 files changed

+79
-2
lines changed

4 files changed

+79
-2
lines changed

src/plots/cartesian/axes.js

+3-2
Original file line numberDiff line numberDiff line change
@@ -1781,11 +1781,12 @@ axes.drawOne = function(gd, ax, opts) {
17811781
if(ax.type === 'multicategory') {
17821782
var labelLength = 0;
17831783
var pad = {x: 2, y: 10}[axLetter];
1784+
var sgn = tickSigns[2] * (ax.ticks === 'inside' ? -1 : 1);
17841785

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

17911792
return axes.drawLabels(gd, ax, {
@@ -1808,7 +1809,7 @@ axes.drawOne = function(gd, ax, opts) {
18081809
return drawDividers(gd, ax, {
18091810
vals: dividerVals,
18101811
layer: mainAxLayer,
1811-
path: axes.makeTickPath(ax, mainLinePosition, tickSigns[2], labelLength),
1812+
path: axes.makeTickPath(ax, mainLinePosition, sgn, labelLength),
18121813
transFn: transFn
18131814
});
18141815
});
Loading
-2 Bytes
Loading
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
{
2+
"data": [
3+
{
4+
"type": "bar",
5+
"x": [
6+
["2017", "2017", "2017", "2017", "2018", "2018", "2018"],
7+
["q1", "q2", "q3", "q4", "q1", "q2", "q3" ]
8+
],
9+
"y": [1, 2, 3, 1, 3, 2, 3, 1]
10+
},
11+
{
12+
"type": "bar",
13+
"x": [
14+
["2017", "2017", "2017", "2017", "2018", "2018", "2018"],
15+
["q1", "q2", "q3", "q4", "q1", "q2", "q3"]
16+
],
17+
"y": [1.12, 2.15, 3.07, 1.48, 2.78, 1.95, 2.54, 0.64]
18+
},
19+
20+
{
21+
"type": "bar",
22+
"x": [
23+
["2017", "2017", "2017", "2017", "2018", "2018", "2018"],
24+
["q1", "q2", "q3", "q4", "q1", "q2", "q3"]
25+
],
26+
"y": [1.12, 2.15, 3.07, 1.48, 2.78, 1.95, 2.54, 0.64],
27+
"xaxis": "x2",
28+
"yaxis": "y2"
29+
},
30+
{
31+
"type": "bar",
32+
"x": [
33+
["2017", "2017", "2017", "2017", "2018", "2018", "2018"],
34+
["q1", "q2", "q3", "q4", "q1", "q2", "q3" ]
35+
],
36+
"y": [1, 2, 3, 1, 3, 2, 3, 1],
37+
"xaxis": "x2",
38+
"yaxis": "y2"
39+
}
40+
],
41+
"layout": {
42+
"grid": {"rows": 2, "columns": 1, "pattern": "independent"},
43+
"xaxis": {
44+
"side": "top",
45+
"title": "MULTI-CATEGORY",
46+
"range": [-0.5, 7],
47+
"showline": true,
48+
"tickfont": {"size": 16},
49+
"ticks": "inside",
50+
"ticklen": 10,
51+
"tickcolor": "red",
52+
"tickwidth": 2,
53+
"dividercolor": "blue",
54+
"dividerwidth": 2
55+
},
56+
"xaxis2": {
57+
"title": "MULTI-CATEGORY",
58+
"range": [-1, 6.5],
59+
"showline": true,
60+
"tickfont": {"size": 16},
61+
"ticks": "inside",
62+
"ticklen": 10,
63+
"tickcolor": "red",
64+
"tickwidth": 2,
65+
"dividercolor": "blue",
66+
"dividerwidth": 2
67+
},
68+
"yaxis": {
69+
"zeroline": false
70+
},
71+
"yaxis2": {
72+
"zeroline": false
73+
},
74+
"showlegend": false
75+
}
76+
}

0 commit comments

Comments
 (0)