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

Add ticklabelstandoff and ticklabelshift to cartesian axes #7006

Merged
merged 26 commits into from
Jul 5, 2024
Merged
Show file tree
Hide file tree
Changes from 12 commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
6c81892
Add property axis.ticklabelshiftx and axis.ticklabelshifty
my-tien May 27, 2024
ad4509b
makeTransTickLabelFn: default vals for ax.ticklabelshiftx/y
my-tien May 28, 2024
fa50121
Add draftlog for PR 7006
my-tien May 27, 2024
d33e47c
Add ticklabelshiftx/y property to colorbar, indicator, gl3d, carpet, …
my-tien May 28, 2024
3dcb2aa
baseline image for updated date_axes_period2 using ticklabelshiftx/y
my-tien May 28, 2024
facdad3
ticklabelshiftx/y: valType number → integer. for carpet: editType tic…
my-tien May 28, 2024
ecf4787
Revert ticklabelshiftx/y change to mock date_axes_period2
my-tien Jun 3, 2024
2b9c90c
Replace ticklabelshiftx/y with ticklabelrunoff and ticklabelstandoff
my-tien Jun 3, 2024
f06a81e
Adjust ticklabelrunoff/ticklabelstandoff behavior depending on axis, …
my-tien Jun 7, 2024
57c82ee
baseline test mock for ticklabelrunoff/ticklabelstandoff
my-tien Jun 7, 2024
4ccaf73
Merge remote-tracking branch 'origin-plotly/master' into shift_axis_l…
my-tien Jun 7, 2024
4b62652
baseline image for mock zzz_ticklabelrunoff_standoff
my-tien Jun 8, 2024
94878cb
Split option noTicklabelrunoffstandoff → noTicklabelrunoff, noTicklab…
my-tien Jun 13, 2024
9ca95a2
Update property names in draftlog for PR 7006
my-tien Jun 13, 2024
6ea832f
Mark flaky: "should be able to restyle radial axis title"
my-tien Jun 18, 2024
b7a6327
Revert "Mark flaky: "should be able to restyle radial axis title""
my-tien Jun 19, 2024
316158d
Merge remote-tracking branch 'origin-plotly/master' into shift_axis_l…
my-tien Jun 19, 2024
e7a980a
Revert accidentally removed line in colorbar attributes
my-tien Jun 26, 2024
e8f88ba
correct var name. it's not ticks inside/outside, but labels inside/ou…
my-tien Jun 26, 2024
d9210da
Clarify the direction of movement for ticklabelstandoff and ticklabel…
my-tien Jun 26, 2024
e33270b
update plot-schema as well
my-tien Jun 26, 2024
ec5df56
Rename ticklabelrunoff → ticklabelshift
my-tien Jul 3, 2024
e3b0baa
Update draftlogs/7006_add.md
my-tien Jul 5, 2024
23a21c1
Simplify code for standoff sign
my-tien Jul 5, 2024
6715564
Update draftlogs/7006_add.md
my-tien Jul 5, 2024
26315dc
improve ticklabelstandoff description and note that inside ticks coul…
my-tien Jul 5, 2024
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/7006_add.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
- Add property axis.ticklabelshiftx axis.ticklabelshifty for shifting the tick labels by a number of pixels [[#7006](https://github.com/plotly/plotly.js/pull/7006)]
my-tien marked this conversation as resolved.
Show resolved Hide resolved
1 change: 0 additions & 1 deletion src/components/colorbar/attributes.js
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,6 @@ module.exports = overrideAll({
'top and bottom when `orientation` is *v*.'
].join(' ')
},

my-tien marked this conversation as resolved.
Show resolved Hide resolved
ticklen: axesAttrs.ticklen,
tickwidth: axesAttrs.tickwidth,
tickcolor: axesAttrs.tickcolor,
Expand Down
1 change: 1 addition & 0 deletions src/components/colorbar/defaults.js
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ module.exports = function colorbarDefaults(containerIn, containerOut, layout) {
var font = layout.font;
var opts = {
noAutotickangles: true,
noTicklabelrunoffstandoff: true,
outerTicks: false,
font: font
};
Expand Down
31 changes: 26 additions & 5 deletions src/plots/cartesian/axes.js
Original file line number Diff line number Diff line change
Expand Up @@ -2968,20 +2968,41 @@ axes.makeTransTickFn = function(ax) {

axes.makeTransTickLabelFn = function(ax) {
var uv = getTickLabelUV(ax);
var runoff = ax.ticklabelrunoff || 0;
var standoff = ax.ticklabelstandoff || 0;

var u = uv[0];
var v = uv[1];

return ax._id.charAt(0) === 'x' ?
var isXaxis = ax._id.charAt(0) === 'x';
var isYaxis = !isXaxis;
var isReversed = ax.range[0] > ax.range[1];
var ticksInside = ax.ticklabelposition && ax.ticklabelposition.indexOf('inside') !== -1;
var ticksOutside = !ticksInside;

if(runoff) {
var runoffSign = isReversed ? -1 : 1;
runoff = runoff * runoffSign;
}
if(standoff) {
var standoffSign =
isXaxis && ax.side === 'bottom' && ticksOutside ||
isXaxis && ax.side === 'top' && ticksInside ||
isYaxis && ax.side === 'right' && ticksOutside ||
isYaxis && ax.side === 'left' && ticksInside ? 1 : -1;
standoff = standoff * standoffSign;
}
return isXaxis ?
function(d) {
return strTranslate(
u + ax._offset + ax.l2p(getPosX(d)),
v
u + ax._offset + ax.l2p(getPosX(d)) + runoff,
v + standoff
);
} :
function(d) {
return strTranslate(
v,
u + ax._offset + ax.l2p(getPosX(d))
v + standoff,
u + ax._offset + ax.l2p(getPosX(d)) + runoff
);
};
};
Expand Down
16 changes: 16 additions & 0 deletions src/plots/cartesian/layout_attributes.js
Original file line number Diff line number Diff line change
Expand Up @@ -698,6 +698,22 @@ module.exports = {
'In other cases the default is *hide past div*.'
].join(' ')
},
ticklabelrunoff: {
valType: 'integer',
dflt: 0,
editType: 'ticks',
description: [
'Shifts the tick labels by the specified number of pixels in parallel to the axis.'
].join(' ')
},
ticklabelstandoff: {
valType: 'integer',
dflt: 0,
my-tien marked this conversation as resolved.
Show resolved Hide resolved
editType: 'ticks',
description: [
'Shifts the tick labels by the specified number of pixels orthogonally to the axis.'
].join(' ')
},
mirror: {
valType: 'enumerated',
values: [true, 'ticks', false, 'all', 'allticks'],
Expand Down
4 changes: 4 additions & 0 deletions src/plots/cartesian/tick_label_defaults.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ module.exports = function handleTickLabelDefaults(containerIn, containerOut, coe

var showTickLabels = coerce('showticklabels');
if(showTickLabels) {
if(!options.noTicklabelrunoffstandoff) {
my-tien marked this conversation as resolved.
Show resolved Hide resolved
coerce('ticklabelrunoff');
coerce('ticklabelstandoff');
}
var font = options.font || {};
var contColor = containerOut.color;
var position = containerOut.ticklabelposition || '';
Expand Down
1 change: 1 addition & 0 deletions src/plots/gl3d/layout/axis_defaults.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ module.exports = function supplyLayoutDefaults(layoutIn, layoutOut, options) {
noAutotickangles: true,
noTickson: true,
noTicklabelmode: true,
noTicklabelrunoffstandoff: true,
noTicklabelstep: true,
noTicklabelposition: true,
noTicklabeloverflow: true,
Expand Down
3 changes: 2 additions & 1 deletion src/plots/polar/layout_defaults.js
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,8 @@ function handleDefaults(contIn, contOut, coerce, opts) {
size: dfltFontSize,
family: dfltFontFamily
},
noAutotickangles: axName === 'angularaxis'
noAutotickangles: axName === 'angularaxis',
noTicklabelrunoffstandoff: true
});

handleTickMarkDefaults(axIn, axOut, coerceAxis, {outerTicks: true});
Expand Down
1 change: 1 addition & 0 deletions src/plots/smith/layout_defaults.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ function handleDefaults(contIn, contOut, coerce, opts) {

handleTickLabelDefaults(axIn, axOut, coerceAxis, axOut.type, {
noAutotickangles: true,
noTicklabelrunoffstandoff: true,
noTicklabelstep: true,
noAng: !isRealAxis,
noExp: true,
Expand Down
2 changes: 1 addition & 1 deletion src/plots/ternary/layout_defaults.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ function handleAxisDefaults(containerIn, containerOut, options, ternaryLayoutOut

handleTickValueDefaults(containerIn, containerOut, coerce, 'linear');
handlePrefixSuffixDefaults(containerIn, containerOut, coerce, 'linear');
handleTickLabelDefaults(containerIn, containerOut, coerce, 'linear', { noAutotickangles: true });
handleTickLabelDefaults(containerIn, containerOut, coerce, 'linear', { noAutotickangles: true, noTicklabelrunoffstandoff: true });
handleTickMarkDefaults(containerIn, containerOut, coerce,
{ outerTicks: true });

Expand Down
1 change: 1 addition & 0 deletions src/traces/carpet/ab_defaults.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ function mimickAxisDefaults(traceIn, traceOut, fullLayout, dfltColor) {

var defaultOptions = {
noAutotickangles: true,
noTicklabelrunoffstandoff: true,
noTicklabelstep: true,
tickfont: 'x',
id: axLetter + 'axis',
Expand Down
3 changes: 2 additions & 1 deletion src/traces/indicator/defaults.js
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,8 @@ function supplyDefaults(traceIn, traceOut, defaultColor, layout) {
var opts = {
font: layout.font,
noAutotickangles: true,
outerTicks: true
outerTicks: true,
noTicklabelrunoffstandoff: true
};
handleTickValueDefaults(axisIn, axisOut, coerceGaugeAxis, 'linear');
handlePrefixSuffixDefaults(axisIn, axisOut, coerceGaugeAxis, 'linear', opts);
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
158 changes: 158 additions & 0 deletions test/image/mocks/zzz_ticklabelrunoff_ticklabelstandoff.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,158 @@
{
"data": [{
"xaxis": "x",
"yaxis": "y",
"x": ["20-12-20", "21-01-20"],
"y": [1e-1, 1e+6]
}, {
"xaxis": "x2",
"yaxis": "y2",
"x": ["20-10", "21-05-15"],
"y": [1e-1, 1e+6]
}, {
"xaxis": "x3",
"yaxis": "y3",
"x": ["20", "23"],
"y": [1e-1, 1e+6]
}, {
"xaxis": "x4",
"yaxis": "y4",
"x": ["20-12-20", "21-01-20"],
"y": [1e-1, 1e+6]
}],
"layout": {
"xaxis": {
"minor": { "showgrid": true },
"anchor": "y",
"domain": [0, 0.475],
"type": "date",
"ticklabelmode": "period",
"ticklabelstandoff": 20,
"ticklabelrunoff": 20,
"side": "bottom",
"ticks": "inside",
"tickfont": { "size": 16 },
"ticklen": 16,
"tickwidth": 8,
"linewidth": 1,
"gridcolor": "white"
},
"yaxis": {
"minor": { "showgrid": true },
"anchor": "x",
"domain": [0, 0.475],
"autorange": "reversed",
"type": "log",
"side": "left",
"ticks": "inside",
"ticklabelposition": "outside top",
"ticklabelstandoff": 20,
"tickfont": { "size": 20 },
"ticklen": 8,
"tickwidth": 4,
"linewidth": 4,
"gridcolor": "white"
},
"xaxis2": {
"minor": { "showgrid": true },
"anchor": "y2",
"domain": [0.525, 1],
"autorange": "reversed",
"type": "date",
"side": "bottom",
"ticks": "inside",
"ticklabelposition": "inside left",
"ticklabelstandoff": 20,
"tickfont": { "size": 20 },
"ticklen": 8,
"tickwidth": 4,
"linewidth": 4,
"gridcolor": "white"
},
"yaxis2": {
"minor": { "showgrid": true },
"anchor": "x2",
"domain": [0, 0.475],
"type": "log",
"side": "right",
"ticks": "inside",
"ticklabelposition": "inside",
"ticklabelstandoff": 20,
"ticklen": 16,
"tickwidth": 8,
"linewidth": 1,
"gridcolor": "white"
},
"xaxis3": {
"minor": { "showgrid": true },
"anchor": "y3",
"domain": [0.525, 1],
"type": "date",
"side": "top",
"ticks": "inside",
"ticklabelposition": "inside right",
"ticklabelstandoff": 20,
"ticklabelrunoff": 40,
"tickfont": { "size": 20 },
"ticklen": 16,
"tickwidth": 8,
"linewidth": 1,
"gridcolor": "white"
},
"yaxis3": {
"minor": { "showgrid": true },
"anchor": "x3",
"domain": [0.525, 1],
"autorange": "reversed",
"type": "log",
"side": "right",
"ticks": "inside",
"ticklabelposition": "inside bottom",
"ticklabelstandoff": 10,
"ticklabelrunoff": -10,
"tickfont": { "size": 16 },
"ticklen": 8,
"tickwidth": 4,
"linewidth": 4,
"gridcolor": "white"
},
"xaxis4": {
"minor": { "showgrid": true },
"anchor": "y4",
"domain": [0, 0.475],
"autorange": "reversed",
"type": "date",
"ticklabelmode": "period",
"side": "top",
"ticks": "outside",
"ticklabelposition": "outside",
"ticklabelstandoff": -10,
"ticklabelrunoff": 15,
"tickfont": { "size": 16 },
"ticklen": 8,
"tickwidth": 4,
"linewidth": 4,
"gridcolor": "white"
},
"yaxis4": {
"minor": { "showgrid": true },
"anchor": "x4",
"domain": [0.525, 1],
"type": "log",
"side": "left",
"ticks": "outside",
"ticklabelposition": "outside bottom",
"tickangle": 30,
"tickfont": { "size": 16 },
"ticklen": 16,
"tickwidth": 8,
"linewidth": 1,
"gridcolor": "white"
},
"font": {
"family": "Raleway"
},
"plot_bgcolor": "lightblue",
"showlegend": false
}
}
24 changes: 24 additions & 0 deletions test/plot-schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -15154,6 +15154,18 @@
"inside bottom"
]
},
"ticklabelrunoff": {
"description": "Shifts the tick labels by the specified number of pixels in parallel to the axis.",
"dflt": 0,
"editType": "ticks",
"valType": "integer"
},
"ticklabelstandoff": {
"description": "Shifts the tick labels by the specified number of pixels orthogonally to the axis.",
"dflt": 0,
"editType": "ticks",
"valType": "integer"
},
"ticklabelstep": {
"description": "Sets the spacing between tick labels as compared to the spacing between ticks. A value of 1 (default) means each tick gets a label. A value of 2 means shows every 2nd label. A larger value n means only every nth tick is labeled. `tick0` determines which labels are shown. Not implemented for axes with `type` *log* or *multicategory*, or when `tickmode` is *array*.",
"dflt": 1,
Expand Down Expand Up @@ -16463,6 +16475,18 @@
"inside bottom"
]
},
"ticklabelrunoff": {
"description": "Shifts the tick labels by the specified number of pixels in parallel to the axis.",
archmoj marked this conversation as resolved.
Show resolved Hide resolved
"dflt": 0,
"editType": "ticks",
"valType": "integer"
},
"ticklabelstandoff": {
"description": "Shifts the tick labels by the specified number of pixels orthogonally to the axis.",
archmoj marked this conversation as resolved.
Show resolved Hide resolved
"dflt": 0,
"editType": "ticks",
"valType": "integer"
},
"ticklabelstep": {
"description": "Sets the spacing between tick labels as compared to the spacing between ticks. A value of 1 (default) means each tick gets a label. A value of 2 means shows every 2nd label. A larger value n means only every nth tick is labeled. `tick0` determines which labels are shown. Not implemented for axes with `type` *log* or *multicategory*, or when `tickmode` is *array*.",
"dflt": 1,
Expand Down