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 labelalias to various axes #6481

Merged
merged 17 commits into from
Feb 24, 2023
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions draftlogs/6481_add.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
- Add `labelalias` to various axes namely cartesian, gl3d, polar, smith, ternary, carpet, indicator and colorbar [[#6481](https://github.com/plotly/plotly.js/pull/6481)]
1 change: 1 addition & 0 deletions src/components/colorbar/attributes.js
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,7 @@ module.exports = overrideAll({
tickcolor: axesAttrs.tickcolor,
ticklabelstep: axesAttrs.ticklabelstep,
showticklabels: axesAttrs.showticklabels,
labelalias: axesAttrs.labelalias,
tickfont: fontAttrs({
description: 'Sets the color bar\'s tick label font'
}),
Expand Down
1 change: 1 addition & 0 deletions src/components/colorbar/draw.js
Original file line number Diff line number Diff line change
Expand Up @@ -931,6 +931,7 @@ function mockColorBarAxis(gd, opts, zrange) {
tickwidth: opts.tickwidth,
tickcolor: opts.tickcolor,
showticklabels: opts.showticklabels,
labelalias: opts.labelalias,
ticklabelposition: opts.ticklabelposition,
ticklabeloverflow: opts.ticklabeloverflow,
ticklabelstep: opts.ticklabelstep,
Expand Down
5 changes: 5 additions & 0 deletions src/plots/cartesian/axes.js
Original file line number Diff line number Diff line change
Expand Up @@ -1660,6 +1660,11 @@ axes.tickText = function(ax, x, hover, noSuffixPrefix) {
if(ax.ticksuffix && !isHidden(ax.showticksuffix)) out.text += ax.ticksuffix;
}

if(ax.labelalias) {
var t = ax.labelalias[out.text];
if(typeof t === 'string') out.text = t;
}

// Setup ticks and grid lines boundaries
// at 1/2 a 'category' to the left/bottom
if(ax.tickson === 'boundaries' || ax.showdividers) {
Expand Down
11 changes: 11 additions & 0 deletions src/plots/cartesian/layout_attributes.js
Original file line number Diff line number Diff line change
Expand Up @@ -633,6 +633,17 @@ module.exports = {
editType: 'ticks',
description: 'Determines whether or not the tick labels are drawn.'
},
labelalias: {
valType: 'any',
dflt: false,
editType: 'ticks',
description: [
'Determines the alias for certain labels for ticks and hover.',
'For example using {US: \'USA\', CA: \'Canada\'} maps US to USA',
'and CA to Canada if tick or hover labels match US or Canada i.e.',
'after adding prefix and suffix to labels.'
archmoj marked this conversation as resolved.
Show resolved Hide resolved
].join(' ')
},
automargin: {
valType: 'flaglist',
flags: ['height', 'width', 'left', 'right', 'top', 'bottom'],
Expand Down
3 changes: 3 additions & 0 deletions src/plots/cartesian/tick_label_defaults.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ var handleArrayContainerDefaults = require('../array_container_defaults');

module.exports = function handleTickLabelDefaults(containerIn, containerOut, coerce, axType, options) {
if(!options) options = {};

coerce('labelalias');

var showAttrDflt = getShowAttrDflt(containerIn);

var showTickLabels = coerce('showticklabels');
Expand Down
1 change: 1 addition & 0 deletions src/plots/gl3d/layout/axis_attributes.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ module.exports = overrideAll({
tickwidth: axesAttrs.tickwidth,
tickcolor: axesAttrs.tickcolor,
showticklabels: axesAttrs.showticklabels,
labelalias: axesAttrs.labelalias,
tickfont: axesAttrs.tickfont,
tickangle: axesAttrs.tickangle,
tickprefix: axesAttrs.tickprefix,
Expand Down
1 change: 1 addition & 0 deletions src/plots/polar/layout_attributes.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ var axisTickAttrs = overrideAll({
tickcolor: axesAttrs.tickcolor,
ticklabelstep: axesAttrs.ticklabelstep,
showticklabels: axesAttrs.showticklabels,
labelalias: axesAttrs.labelalias,
showtickprefix: axesAttrs.showtickprefix,
tickprefix: axesAttrs.tickprefix,
showticksuffix: axesAttrs.showticksuffix,
Expand Down
1 change: 1 addition & 0 deletions src/plots/smith/layout_attributes.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ var axisTickAttrs = overrideAll({
tickwidth: extendFlat({}, axesAttrs.tickwidth, {dflt: 2}),
tickcolor: axesAttrs.tickcolor,
showticklabels: axesAttrs.showticklabels,
labelalias: axesAttrs.labelalias,
showtickprefix: axesAttrs.showtickprefix,
tickprefix: axesAttrs.tickprefix,
showticksuffix: axesAttrs.showticksuffix,
Expand Down
1 change: 1 addition & 0 deletions src/plots/ternary/layout_attributes.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ var ternaryAxesAttrs = {
tickcolor: axesAttrs.tickcolor,
ticklabelstep: axesAttrs.ticklabelstep,
showticklabels: axesAttrs.showticklabels,
labelalias: axesAttrs.labelalias,
showtickprefix: axesAttrs.showtickprefix,
tickprefix: axesAttrs.tickprefix,
showticksuffix: axesAttrs.showticksuffix,
Expand Down
1 change: 1 addition & 0 deletions src/traces/carpet/axis_attributes.js
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,7 @@ module.exports = {
'the high side, both, or neither side of the axis.'
].join(' ')
},
labelalias: extendFlat({}, axesAttrs.labelalias, {editType: 'calc'}),
tickfont: fontAttrs({
editType: 'calc',
description: 'Sets the tick font.'
Expand Down
1 change: 1 addition & 0 deletions src/traces/indicator/attributes.js
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,7 @@ module.exports = {
tickcolor: axesAttrs.tickcolor,
ticklabelstep: axesAttrs.ticklabelstep,
showticklabels: axesAttrs.showticklabels,
labelalias: axesAttrs.labelalias,
tickfont: fontAttrs({
description: 'Sets the color bar\'s tick label font'
}),
Expand Down
Binary file modified test/image/baselines/carpet_grid_dash.png
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/grid_subplot_types.png
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/indicator_bullet.png
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/indicator_format_extremes.png
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/smith_blank.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions test/image/mocks/carpet_grid_dash.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
"minorgriddash": "dash"
},
"baxis": {
"labelalias": { "0": "ZERO" },
"minorgridcount": 3,
"gridcolor": "black",
"minorgridcolor": "red",
Expand Down
23 changes: 14 additions & 9 deletions test/image/mocks/grid_subplot_types.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,23 @@
"domain": {"row": 2, "column": 0}
},
{"type": "scattergeo", "lon": [0, -75], "lat": [0, 45], "marker": {"size": [20, 30]}},
{"type": "heatmap", "z": [[1, 2], [4, 1]], "showscale": false, "xaxis": "x3", "yaxis": "y3"}
{"type": "heatmap", "z": [[1, 2], [4, 1]], "showscale": true, "xaxis": "x3", "yaxis": "y3", "colorbar": {
"yanchor": "bottom",
"y": 0,
"len": 0.3,
"labelalias": {"2": "TWO"}
}}
],
"layout": {
"xaxis": {"title": {"text": "x"}},
"xaxis2": {"title": {"text": "x2"}},
"yaxis": {"title": {"text": "y"}},
"yaxis2": {"title": {"text": "y2"}},
"xaxis3": {"title": {"text": "x3"}},
"yaxis3": {"title": {"text": "y3"}},
"xaxis": {"title": {"text": "x"}, "labelalias": {"0": "ZERO"}},
"xaxis2": {"title": {"text": "x2"}, "labelalias": {"0": "ZERO"}},
"yaxis": {"title": {"text": "y"}, "labelalias": {"0": "ZERO"}},
"yaxis2": {"title": {"text": "y2"}, "labelalias": {"0": "ZERO"}},
"xaxis3": {"title": {"text": "x3"}, "labelalias": {"0": "ZERO"}},
"yaxis3": {"title": {"text": "y3"}, "labelalias": {"0": "ZERO"}},
"grid": {"rows": 3, "columns": 3, "xgap": 0.3, "ygap": 0.3},
"scene": {"domain": {"row": 1, "column": 1}},
"ternary": {"domain": {"row": 1, "column": 2}},
"scene": {"domain": {"row": 1, "column": 1}, "zaxis": {"labelalias": {"2": "TWO"}}},
"ternary": {"domain": {"row": 1, "column": 2}, "caxis": {"labelalias": {"1": "ONE"}}},
"geo": {"domain": {"row": 2, "column": 1}},
"width": 700,
"height": 700
Expand Down
3 changes: 3 additions & 0 deletions test/image/mocks/indicator_bullet.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@
"gauge": {
"shape": "bullet",
"axis": {
"labelalias": {
"0": "ZERO"
},
"range": [null, 300]
},
"threshold": {
Expand Down
7 changes: 7 additions & 0 deletions test/image/mocks/indicator_format_extremes.json
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,13 @@
{
"type": "indicator",
"mode": "number+delta+gauge",
"gauge": {
"axis": {
"labelalias": {
"1": "ONE"
}
}
},
"title": {
"text": "null"
},
Expand Down
3 changes: 3 additions & 0 deletions test/image/mocks/polar_blank.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@
"x": [0, 0.46],
"y": [0.56, 1]
},
"angularaxis": {
"labelalias": { "0": "ZERO" }
},
"radialaxis": {
"title": {"text": "blank"},
"angle": 180
Expand Down
3 changes: 3 additions & 0 deletions test/image/mocks/smith_blank.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@
"x": [0, 0.46],
"y": [0.56, 1]
},
"imaginaryaxis": {
"labelalias": { "0": "ZERO" }
},
"realaxis": {
"side": "top"
}
Expand Down