Skip to content

Commit 7427f14

Browse files
authored
Merge pull request #6481 from plotly/label-alias
Add `labelalias` to various axes
2 parents 1625db4 + 4f3a6b0 commit 7427f14

28 files changed

+381
-10
lines changed

draftlogs/6481_add.md

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
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)]

src/components/colorbar/attributes.js

+1
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,7 @@ module.exports = overrideAll({
168168
tickcolor: axesAttrs.tickcolor,
169169
ticklabelstep: axesAttrs.ticklabelstep,
170170
showticklabels: axesAttrs.showticklabels,
171+
labelalias: axesAttrs.labelalias,
171172
tickfont: fontAttrs({
172173
description: 'Sets the color bar\'s tick label font'
173174
}),

src/components/colorbar/draw.js

+1
Original file line numberDiff line numberDiff line change
@@ -931,6 +931,7 @@ function mockColorBarAxis(gd, opts, zrange) {
931931
tickwidth: opts.tickwidth,
932932
tickcolor: opts.tickcolor,
933933
showticklabels: opts.showticklabels,
934+
labelalias: opts.labelalias,
934935
ticklabelposition: opts.ticklabelposition,
935936
ticklabeloverflow: opts.ticklabeloverflow,
936937
ticklabelstep: opts.ticklabelstep,

src/plots/cartesian/axes.js

+5
Original file line numberDiff line numberDiff line change
@@ -1660,6 +1660,11 @@ axes.tickText = function(ax, x, hover, noSuffixPrefix) {
16601660
if(ax.ticksuffix && !isHidden(ax.showticksuffix)) out.text += ax.ticksuffix;
16611661
}
16621662

1663+
if(ax.labelalias && ax.labelalias.hasOwnProperty(out.text)) {
1664+
var t = ax.labelalias[out.text];
1665+
if(typeof t === 'string') out.text = t;
1666+
}
1667+
16631668
// Setup ticks and grid lines boundaries
16641669
// at 1/2 a 'category' to the left/bottom
16651670
if(ax.tickson === 'boundaries' || ax.showdividers) {

src/plots/cartesian/layout_attributes.js

+13
Original file line numberDiff line numberDiff line change
@@ -633,6 +633,19 @@ module.exports = {
633633
editType: 'ticks',
634634
description: 'Determines whether or not the tick labels are drawn.'
635635
},
636+
labelalias: {
637+
valType: 'any',
638+
dflt: false,
639+
editType: 'ticks',
640+
description: [
641+
'Replacement text for specific tick or hover labels.',
642+
'For example using {US: \'USA\', CA: \'Canada\'} changes US to USA',
643+
'and CA to Canada. The labels we would have shown must match',
644+
'the keys exactly, after adding any tickprefix or ticksuffix.',
645+
'labelalias can be used with any axis type, and both keys (if needed)',
646+
'and values (if desired) can include html-like tags or MathJax.'
647+
].join(' ')
648+
},
636649
automargin: {
637650
valType: 'flaglist',
638651
flags: ['height', 'width', 'left', 'right', 'top', 'bottom'],

src/plots/cartesian/tick_label_defaults.js

+4
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@ var handleArrayContainerDefaults = require('../array_container_defaults');
88

99
module.exports = function handleTickLabelDefaults(containerIn, containerOut, coerce, axType, options) {
1010
if(!options) options = {};
11+
12+
var labelalias = coerce('labelalias');
13+
if(!Lib.isPlainObject(labelalias)) delete containerOut.labelalias;
14+
1115
var showAttrDflt = getShowAttrDflt(containerIn);
1216

1317
var showTickLabels = coerce('showticklabels');

src/plots/gl3d/layout/axis_attributes.js

+1
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ module.exports = overrideAll({
8686
tickwidth: axesAttrs.tickwidth,
8787
tickcolor: axesAttrs.tickcolor,
8888
showticklabels: axesAttrs.showticklabels,
89+
labelalias: axesAttrs.labelalias,
8990
tickfont: axesAttrs.tickfont,
9091
tickangle: axesAttrs.tickangle,
9192
tickprefix: axesAttrs.tickprefix,

src/plots/polar/layout_attributes.js

+1
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ var axisTickAttrs = overrideAll({
3535
tickcolor: axesAttrs.tickcolor,
3636
ticklabelstep: axesAttrs.ticklabelstep,
3737
showticklabels: axesAttrs.showticklabels,
38+
labelalias: axesAttrs.labelalias,
3839
showtickprefix: axesAttrs.showtickprefix,
3940
tickprefix: axesAttrs.tickprefix,
4041
showticksuffix: axesAttrs.showticksuffix,

src/plots/smith/layout_attributes.js

+1
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ var axisTickAttrs = overrideAll({
2222
tickwidth: extendFlat({}, axesAttrs.tickwidth, {dflt: 2}),
2323
tickcolor: axesAttrs.tickcolor,
2424
showticklabels: axesAttrs.showticklabels,
25+
labelalias: axesAttrs.labelalias,
2526
showtickprefix: axesAttrs.showtickprefix,
2627
tickprefix: axesAttrs.tickprefix,
2728
showticksuffix: axesAttrs.showticksuffix,

src/plots/ternary/layout_attributes.js

+1
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ var ternaryAxesAttrs = {
2727
tickcolor: axesAttrs.tickcolor,
2828
ticklabelstep: axesAttrs.ticklabelstep,
2929
showticklabels: axesAttrs.showticklabels,
30+
labelalias: axesAttrs.labelalias,
3031
showtickprefix: axesAttrs.showtickprefix,
3132
tickprefix: axesAttrs.tickprefix,
3233
showticksuffix: axesAttrs.showticksuffix,

src/traces/carpet/axis_attributes.js

+1
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,7 @@ module.exports = {
185185
'the high side, both, or neither side of the axis.'
186186
].join(' ')
187187
},
188+
labelalias: extendFlat({}, axesAttrs.labelalias, {editType: 'calc'}),
188189
tickfont: fontAttrs({
189190
editType: 'calc',
190191
description: 'Sets the tick font.'

src/traces/indicator/attributes.js

+1
Original file line numberDiff line numberDiff line change
@@ -319,6 +319,7 @@ module.exports = {
319319
tickcolor: axesAttrs.tickcolor,
320320
ticklabelstep: axesAttrs.ticklabelstep,
321321
showticklabels: axesAttrs.showticklabels,
322+
labelalias: axesAttrs.labelalias,
322323
tickfont: fontAttrs({
323324
description: 'Sets the color bar\'s tick label font'
324325
}),
760 Bytes
Loading
4.65 KB
Loading
521 Bytes
Loading
221 Bytes
Loading
Loading

test/image/baselines/polar_blank.png

242 Bytes
Loading

test/image/baselines/smith_blank.png

280 Bytes
Loading
1.68 KB
Loading

test/image/mocks/carpet_grid_dash.json

+1
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
"minorgriddash": "dash"
3838
},
3939
"baxis": {
40+
"labelalias": { "0": "ZERO<sup>2</sup>" },
4041
"minorgridcount": 3,
4142
"gridcolor": "black",
4243
"minorgridcolor": "red",

test/image/mocks/grid_subplot_types.json

+14-9
Original file line numberDiff line numberDiff line change
@@ -13,18 +13,23 @@
1313
"domain": {"row": 2, "column": 0}
1414
},
1515
{"type": "scattergeo", "lon": [0, -75], "lat": [0, 45], "marker": {"size": [20, 30]}},
16-
{"type": "heatmap", "z": [[1, 2], [4, 1]], "showscale": false, "xaxis": "x3", "yaxis": "y3"}
16+
{"type": "heatmap", "z": [[1, 2], [4, 1]], "showscale": true, "xaxis": "x3", "yaxis": "y3", "colorbar": {
17+
"yanchor": "bottom",
18+
"y": 0,
19+
"len": 0.3,
20+
"labelalias": {"3": "2+1", "4": "2<sup>2</sup>"}
21+
}}
1722
],
1823
"layout": {
19-
"xaxis": {"title": {"text": "x"}},
20-
"xaxis2": {"title": {"text": "x2"}},
21-
"yaxis": {"title": {"text": "y"}},
22-
"yaxis2": {"title": {"text": "y2"}},
23-
"xaxis3": {"title": {"text": "x3"}},
24-
"yaxis3": {"title": {"text": "y3"}},
24+
"xaxis": {"title": {"text": "x"}, "labelalias": {"0": "ZERO<sup>2</sup>"}},
25+
"xaxis2": {"title": {"text": "x2"}, "labelalias": {"0": "ZERO<sup>2</sup>"}},
26+
"yaxis": {"title": {"text": "y"}, "labelalias": {"0": "ZERO<sup>2</sup>"}},
27+
"yaxis2": {"title": {"text": "y2"}, "labelalias": {"0": "ZERO<sup>2</sup>"}},
28+
"xaxis3": {"title": {"text": "x3"}, "labelalias": {"0": "ZERO<sup>2</sup>"}},
29+
"yaxis3": {"title": {"text": "y3"}, "labelalias": {"0": "ZERO<sup>2</sup>"}},
2530
"grid": {"rows": 3, "columns": 3, "xgap": 0.3, "ygap": 0.3},
26-
"scene": {"domain": {"row": 1, "column": 1}},
27-
"ternary": {"domain": {"row": 1, "column": 2}},
31+
"scene": {"domain": {"row": 1, "column": 1}, "zaxis": {"labelalias": {"1": "", "1.5": "1+½", "2": "√4", "2.5": "5/<sub>2</sub>", "3.5": ""}}},
32+
"ternary": {"domain": {"row": 1, "column": 2}, "caxis": {"labelalias": {"1": "ONE"}}},
2833
"geo": {"domain": {"row": 2, "column": 1}},
2934
"width": 700,
3035
"height": 700

test/image/mocks/indicator_bullet.json

+3
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@
1414
"gauge": {
1515
"shape": "bullet",
1616
"axis": {
17+
"labelalias": {
18+
"0": "ZERO<sup>2</sup>"
19+
},
1720
"range": [null, 300]
1821
},
1922
"threshold": {

test/image/mocks/indicator_format_extremes.json

+7
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,13 @@
171171
{
172172
"type": "indicator",
173173
"mode": "number+delta+gauge",
174+
"gauge": {
175+
"axis": {
176+
"labelalias": {
177+
"1": "ONE"
178+
}
179+
}
180+
},
174181
"title": {
175182
"text": "null"
176183
},

test/image/mocks/polar_blank.json

+3
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,9 @@
3333
"x": [0, 0.46],
3434
"y": [0.56, 1]
3535
},
36+
"angularaxis": {
37+
"labelalias": { "0°": "ZERO<sup>2</sup>" }
38+
},
3639
"radialaxis": {
3740
"title": {"text": "blank"},
3841
"angle": 180

test/image/mocks/smith_blank.json

+3
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,9 @@
4141
"x": [0, 0.46],
4242
"y": [0.56, 1]
4343
},
44+
"imaginaryaxis": {
45+
"labelalias": { "0": "ZERO<sup>2</sup>" }
46+
},
4447
"realaxis": {
4548
"side": "top"
4649
}

test/image/mocks/ternary-mathjax.json

+7-1
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@
3131
"title": {
3232
"text": "$B^2$"
3333
},
34+
"tickprefix": "$\\sqrt",
35+
"ticksuffix": "^2$",
3436
"showline": true,
3537
"showgrid": true
3638
},
@@ -39,7 +41,11 @@
3941
"text": "$C^2$"
4042
},
4143
"showline": true,
42-
"showgrid": true
44+
"showgrid": true,
45+
"labelalias": {
46+
"20": "$(\\sqrt20)^2$",
47+
"60": "<i><b>Sixty<b><i>"
48+
}
4349
}
4450
},
4551
"annotations": [

0 commit comments

Comments
 (0)