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

ticklabelalignment #2729

Closed
wants to merge 4 commits into from
Closed
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
12 changes: 10 additions & 2 deletions src/plots/cartesian/axes.js
Original file line number Diff line number Diff line change
Expand Up @@ -1736,14 +1736,22 @@ axes.doTicksSingle = function(gd, arg, skipTitle) {
return d.dy + d.fontSize * MID_SHIFT - labelShift * flipit;
};
labelx = function(d) {
var alignmentFlip = (ax.ticklabelalignment === "outside") ? 1 : -1
return d.dx + position + (labelStandoff + pad +
((Math.abs(ax.tickangle) === 90) ? d.fontSize / 2 : 0)) * flipit;
((Math.abs(ax.tickangle) === 90) ? d.fontSize / 2 : 0)) * flipit
* alignmentFlip;
};
labelanchor = function(angle) {
if(isNumeric(angle) && Math.abs(angle) === 90) {
return 'middle';
}
return axside === 'right' ? 'start' : 'end';
let alignment = axside === 'right' ? 'start' : 'end';

// flip the alignment rules if ticklabels are inside the axis
if (ax.ticklabelalignment === "inside") {
alignment = axside === 'right' ? 'end' : 'start';
}
return alignment;
};
}
else if(axid === 'angular') {
Expand Down
7 changes: 7 additions & 0 deletions src/plots/cartesian/layout_attributes.js
Original file line number Diff line number Diff line change
Expand Up @@ -344,6 +344,13 @@ module.exports = {
editType: 'ticks',
description: 'Determines whether or not the tick labels are drawn.'
},
ticklabelalignment: {
valType: 'string',
dflt: 'outside',
role: 'style',
editType: 'ticks',
description: 'Determines whether the tick labels will be inside the axis (and text aligned toward the axis.'
},
automargin: {
valType: 'boolean',
dflt: false,
Expand Down
8 changes: 7 additions & 1 deletion src/plots/cartesian/tick_label_defaults.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,13 @@ module.exports = function handleTickLabelDefaults(containerIn, containerOut, coe
size: font.size,
color: dfltFontColor
});
coerce('tickangle');
var tickangle = coerce('tickangle');

var tickLabelAlignment = coerce('ticklabelalignment');
// if tickangle is not 90, set ticklabelalignment back to default "outside"
if (tickangle !== 90 && tickangle !== 'auto') {
containerOut['ticklabelalignment'] = 'outside';
}

if(axType !== 'category') {
var tickFormat = coerce('tickformat');
Expand Down
12 changes: 8 additions & 4 deletions test/image/mocks/multiple_subplots.json
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,8 @@
"domain": [
0,
0.45
]
],
"ticklabelalignment": "inside"
},
"xaxis4": {
"domain": [
Expand All @@ -97,20 +98,23 @@
0,
0.45
],
"anchor": "x2"
"anchor": "x2",
"ticklabelalignment": "inside"
},
"yaxis3": {
"domain": [
0.55,
1
]
],
"ticklabelalignment": "inside"
},
"yaxis4": {
"domain": [
0.55,
1
],
"anchor": "x4"
"anchor": "x4",
"ticklabelalignment": "inside"
}
}
}
4 changes: 2 additions & 2 deletions test/image/mocks/overlaying-axis-lines.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
}],
"layout": {
"xaxis": {"showline": true},
"yaxis": {"showline": true},
"yaxis": {"showline": true, "ticklabelalignment": "inside"},
"xaxis2": {"showline": true, "overlaying": "x", "side": "top"},
"yaxis2": {"showline": true, "overlaying": "y", "side": "right"}
"yaxis2": {"showline": true, "overlaying": "y", "side": "right", "ticklabelalignment": "inside"}
}
}
3 changes: 2 additions & 1 deletion test/image/mocks/tick_attributes.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@
-2.1464968152866244,
0.1464968152866242
],
"autorange": true
"autorange": true,
"ticklabelalignment": "inside"
},
"height": 450,
"width": 1000,
Expand Down
3 changes: 2 additions & 1 deletion test/image/mocks/tick_prefix_suffix.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@
"tickprefix": "*** ",
"showtickprefix": "first",
"ticksuffix": " €",
"showticksuffix": "last"
"showticksuffix": "last",
"ticklabelalignment": "inside"
}
}
}
3 changes: 2 additions & 1 deletion test/image/mocks/tickformat.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@
},
"yaxis": {
"type": "log",
"tickformat": ":^+12.3g"
"tickformat": ":^+12.3g",
"ticklabelalignment": "inside"
}
}
}