Skip to content

Add support for ticklabelposition "inside"/"outside" for category axes with tickson set to "boundaries" #7420

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

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
1 change: 1 addition & 0 deletions draftlogs/7420_add.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
- Add support for ticklabelposition "inside"/"outside" for category axes with `tickson` set to "boundaries" [[#7420](https://github.com/plotly/plotly.js/pull/7420)]
13 changes: 9 additions & 4 deletions src/plots/cartesian/axes.js
Original file line number Diff line number Diff line change
Expand Up @@ -3071,6 +3071,7 @@ function getPosX(d) {
// v is a shift perpendicular to the axis
function getTickLabelUV(ax) {
var ticklabelposition = ax.ticklabelposition || '';
var tickson = ax.tickson || '';
var has = function(str) {
return ticklabelposition.indexOf(str) !== -1;
};
Expand All @@ -3081,7 +3082,7 @@ function getTickLabelUV(ax) {
var isBottom = has('bottom');
var isInside = has('inside');

var isAligned = isBottom || isLeft || isTop || isRight;
var isAligned = (tickson != 'boundaries') && (isBottom || isLeft || isTop || isRight);

// early return
if(!isAligned && !isInside) return [0, 0];
Expand Down Expand Up @@ -3165,6 +3166,8 @@ axes.makeTickPath = function(ax, shift, sgn, opts) {
*/
axes.makeLabelFns = function(ax, shift, angle) {
var ticklabelposition = ax.ticklabelposition || '';
var tickson = ax.tickson || '';

var has = function(str) {
return ticklabelposition.indexOf(str) !== -1;
};
Expand All @@ -3173,12 +3176,12 @@ axes.makeLabelFns = function(ax, shift, angle) {
var isLeft = has('left');
var isRight = has('right');
var isBottom = has('bottom');
var isAligned = isBottom || isLeft || isTop || isRight;
var isAligned = (tickson != 'boundaries') && (isBottom || isLeft || isTop || isRight);

var insideTickLabels = has('inside');
var labelsOverTicks =
(ticklabelposition === 'inside' && ax.ticks === 'inside') ||
(!insideTickLabels && ax.ticks === 'outside' && ax.tickson !== 'boundaries');
(!insideTickLabels && ax.ticks === 'outside' && tickson !== 'boundaries');

var labelStandoff = 0;
var labelShift = 0;
Expand Down Expand Up @@ -3890,14 +3893,16 @@ axes.drawLabels = function(gd, ax, opts) {
}
} else {
var ticklabelposition = ax.ticklabelposition || '';
var tickson = ax.tickson ||'';

var has = function(str) {
return ticklabelposition.indexOf(str) !== -1;
};
var isTop = has('top');
var isLeft = has('left');
var isRight = has('right');
var isBottom = has('bottom');
var isAligned = isBottom || isLeft || isTop || isRight;
var isAligned = (tickson != 'boundaries') && (isBottom || isLeft || isTop || isRight);
var pad = !isAligned ? 0 :
(ax.tickwidth || 0) + 2 * TEXTPAD;

Expand Down
8 changes: 4 additions & 4 deletions src/plots/cartesian/axis_defaults.js
Original file line number Diff line number Diff line change
Expand Up @@ -167,11 +167,11 @@ module.exports = function handleAxisDefaults(containerIn, containerOut, coerce,
(axType === 'category' || isMultiCategory) &&
(containerOut.ticks || containerOut.showgrid)
) {
var ticksonDflt;
if(isMultiCategory) ticksonDflt = 'boundaries';
var tickson = coerce('tickson', ticksonDflt);
if(tickson === 'boundaries') {
if (isMultiCategory) {
coerce('tickson', 'boundaries');
delete containerOut.ticklabelposition;
} else { // category axis
coerce('tickson');
}
}

Expand Down
11 changes: 6 additions & 5 deletions src/plots/cartesian/layout_attributes.js
Original file line number Diff line number Diff line change
Expand Up @@ -663,12 +663,13 @@ module.exports = {
dflt: 'outside',
editType: 'calc',
description: [
'Determines where tick labels are drawn with respect to the axis',
'Determines where tick labels are drawn with respect to the axis.',
'Please note that',
'top or bottom has no effect on x axes or when `ticklabelmode` is set to *period*.',
'Similarly',
'left or right has no effect on y axes or when `ticklabelmode` is set to *period*.',
'Has no effect on *multicategory* axes or when `tickson` is set to *boundaries*.',
'top or bottom has no effect on x axes or when `ticklabelmode` is set to *period*',
'or when `tickson` is set to *boundaries*. Similarly,',
'left or right has no effect on y axes or when `ticklabelmode` is set to *period*',
'or when `tickson` is set to *boundaries*.',
'Has no effect on *multicategory* axes.',
'When used on axes linked by `matches` or `scaleanchor`,',
'no extra padding for inside labels would be added by autorange,',
'so that the scales could match.'
Expand Down
150 changes: 150 additions & 0 deletions test/image/mocks/zz-tickson_boundaries_ticklabelposition.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,150 @@
{
"data": [
{
"type": "box",
"x": [
"day 1",
"day 1",
"day 1",
"day 1",
"day 1",
"day 1",
"day 2",
"day 2",
"day 2",
"day 2",
"day 2",
"day 2"
],
"y": [0.2, 0.2, 0.6, 1, 0.5, 0.4, 0.2, 0.7, 0.9, 0.1, 0.5, 0.3]
},
{
"type": "box",
"x": [
"day 1",
"day 1",
"day 1",
"day 1",
"day 1",
"day 1",
"day 2",
"day 2",
"day 2",
"day 2",
"day 2",
"day 2"
],
"y": [0.1, 0.3, 0.1, 0.9, 0.6, 0.6, 0.9, 1, 0.3, 0.6, 0.8, 0.5]
},
{
"type": "box",
"x": [
"day 1",
"day 1",
"day 1",
"day 1",
"day 1",
"day 1",
"day 2",
"day 2",
"day 2",
"day 2",
"day 2",
"day 2"
],
"y": [0.6, 0.7, 0.3, 0.6, 0, 0.5, 0.7, 0.9, 0.5, 0.8, 0.7, 0.2]
},

{
"type": "bar",
"x": [1, 2, 1],
"y": ["apples", "bananas", "clementines"],
"orientation": "h",
"xaxis": "x2",
"yaxis": "y2"
},
{
"type": "bar",
"x": [1.3, 2.2, 0.8],
"y": ["apples", "bananas", "clementines"],
"orientation": "h",
"xaxis": "x2",
"yaxis": "y2"
},
{
"type": "bar",
"x": [3, 3.2, 1.8],
"y": ["apples", "bananas", "clementines"],
"orientation": "h",
"xaxis": "x2",
"yaxis": "y2"
},

{
"type": "bar",
"name": "with dtick !== 1",
"x": ["a", "b", "c", "d", "e", "f", "g", "h"],
"y": [1, 2, 1, 2, 1, 3, 4, 1],
"xaxis": "x3",
"yaxis": "y3"
},

{
"mode": "markers",
"marker": { "symbol": "square" },
"name": "with overlapping tick labels",
"x": ["A very long title", "short", "Another very long title"],
"y": [0, 10, 2],
"xaxis": "x4",
"yaxis": "y4"
}
],
"layout": {
"title": {
"text": "Although some ticklabelpositions have a side specified,<br>all category labels are expected to be centered."
},
"boxmode": "group",
"grid": {
"rows": 4,
"columns": 1,
"pattern": "independent",
"ygap": 0.2
},
"xaxis": {
"ticklabelposition": "inside right",
"ticks": "outside",
"tickson": "boundaries",
"gridcolor": "white",
"gridwidth": 4
},
"yaxis2": {
"ticks": "inside",
"ticklabelposition": "inside top",
"tickson": "boundaries",
"gridcolor": "white",
"gridwidth": 4
},
"xaxis3": {
"ticks": "inside",
"ticklabelposition": "inside left",
"tickson": "boundaries",
"gridcolor": "white",
"gridwidth": 4,
"dtick": 2
},
"xaxis4": {
"domain": [0.22, 0.78],
"ticks": "outside",
"ticklabelposition": "inside",
"ticklen": 20,
"tickson": "boundaries",
"gridcolor": "white",
"gridwidth": 4
},
"plot_bgcolor": "lightgrey",
"showlegend": false,
"width": 500,
"height": 800,
"margin": { "b": 140 }
}
}