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

Lines changed: 1 addition & 0 deletions
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

Lines changed: 1 addition & 0 deletions
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

Lines changed: 1 addition & 0 deletions
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

Lines changed: 5 additions & 0 deletions
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

Lines changed: 13 additions & 0 deletions
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

Lines changed: 4 additions & 0 deletions
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

Lines changed: 1 addition & 0 deletions
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

Lines changed: 1 addition & 0 deletions
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

Lines changed: 1 addition & 0 deletions
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

Lines changed: 1 addition & 0 deletions
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,

0 commit comments

Comments
 (0)