Skip to content

Commit 7da95e1

Browse files
authored
Merge pull request #3553 from plotly/more-hovertext
Add 'hovertext' attribute to all traces that support hover 'text'
2 parents bb1239a + 0842b6c commit 7da95e1

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

57 files changed

+397
-31
lines changed

src/traces/barpolar/attributes.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,9 @@ module.exports = {
5858
'this trace\'s coordinates.'
5959
].join(' ')
6060
}),
61-
// hovertext: barAttrs.hovertext,
61+
hovertext: extendFlat({}, barAttrs.hovertext, {
62+
description: 'Same as `text`.'
63+
}),
6264

6365
// textposition: {},
6466
// textfont: {},

src/traces/barpolar/defaults.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@ module.exports = function supplyDefaults(traceIn, traceOut, defaultColor, layout
3333
coerce('width');
3434

3535
coerce('text');
36+
coerce('hovertext');
3637
coerce('hovertemplate');
37-
// coerce('hovertext');
3838

3939
// var textPosition = coerce('textposition');
4040
// var hasBoth = Array.isArray(textPosition) || textPosition === 'auto';

src/traces/box/attributes.js

+3
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,9 @@ module.exports = {
7373
'To be seen, trace `hoverinfo` must contain a *text* flag.'
7474
].join(' ')
7575
}),
76+
hovertext: extendFlat({}, scatterAttrs.hovertext, {
77+
description: 'Same as `text`.'
78+
}),
7679
whiskerwidth: {
7780
valType: 'number',
7881
min: 0,

src/traces/box/calc.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,8 @@ function initNestedArray(len) {
212212

213213
function arraysToCalcdata(pt, trace, i) {
214214
var trace2calc = {
215-
text: 'tx'
215+
text: 'tx',
216+
hovertext: 'htx'
216217
};
217218

218219
for(var k in trace2calc) {

src/traces/box/defaults.js

+1
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ function handlePointsDefaults(traceIn, traceOut, coerce, opts) {
100100
coerce('unselected.marker.size');
101101

102102
coerce('text');
103+
coerce('hovertext');
103104
} else {
104105
delete traceOut.marker;
105106
}

src/traces/candlestick/attributes.js

+1
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ module.exports = {
5050
decreasing: directionAttrs(OHLCattrs.decreasing.line.color.dflt),
5151

5252
text: OHLCattrs.text,
53+
hovertext: OHLCattrs.hovertext,
5354
whiskerwidth: extendFlat({}, boxAttrs.whiskerwidth, { dflt: 0 }),
5455

5556
hoverlabel: OHLCattrs.hoverlabel,

src/traces/candlestick/defaults.js

+1
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ module.exports = function supplyDefaults(traceIn, traceOut, defaultColor, layout
3131
handleDirection(traceIn, traceOut, coerce, 'decreasing');
3232

3333
coerce('text');
34+
coerce('hovertext');
3435
coerce('whiskerwidth');
3536

3637
layout._requestRangeslider[traceOut.xaxis] = true;

src/traces/choropleth/attributes.js

+3
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,9 @@ module.exports = extendFlat({
3636
text: extendFlat({}, scatterGeoAttrs.text, {
3737
description: 'Sets the text elements associated with each location.'
3838
}),
39+
hovertext: extendFlat({}, scatterGeoAttrs.hovertext, {
40+
description: 'Same as `text`.'
41+
}),
3942
marker: {
4043
line: {
4144
color: scatterGeoMarkerLineAttrs.color,

src/traces/choropleth/defaults.js

+1
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ module.exports = function supplyDefaults(traceIn, traceOut, defaultColor, layout
3030
coerce('locationmode');
3131

3232
coerce('text');
33+
coerce('hovertext');
3334
coerce('hovertemplate');
3435

3536
coerce('marker.line.color');

src/traces/cone/attributes.js

+8
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,14 @@ var attrs = {
159159
'these elements will be seen in the hover labels.'
160160
].join(' ')
161161
},
162+
hovertext: {
163+
valType: 'string',
164+
role: 'info',
165+
dflt: '',
166+
arrayOk: true,
167+
editType: 'calc',
168+
description: 'Same as `text`.'
169+
},
162170
hovertemplate: hovertemplateAttrs({editType: 'calc'}, {keys: ['norm']})
163171
};
164172

src/traces/cone/convert.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ proto.handlePick = function(selection) {
4040
Math.sqrt(uu * uu + vv * vv + ww * ww)
4141
];
4242

43-
var text = this.data.text;
43+
var text = this.data.hovertext || this.data.text;
4444
if(Array.isArray(text) && text[selectIndex] !== undefined) {
4545
selection.textLabel = text[selectIndex];
4646
} else if(text) {

src/traces/cone/defaults.js

+1
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ module.exports = function supplyDefaults(traceIn, traceOut, defaultColor, layout
5252
colorscaleDefaults(traceIn, traceOut, layout, coerce, {prefix: '', cLetter: 'c'});
5353

5454
coerce('text');
55+
coerce('hovertext');
5556
coerce('hovertemplate');
5657

5758
// disable 1D transforms (for now)

src/traces/contour/attributes.js

+1
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ module.exports = extendFlat({
3131
y0: heatmapAttrs.y0,
3232
dy: heatmapAttrs.dy,
3333
text: heatmapAttrs.text,
34+
hovertext: heatmapAttrs.hovertext,
3435
transpose: heatmapAttrs.transpose,
3536
xtype: heatmapAttrs.xtype,
3637
ytype: heatmapAttrs.ytype,

src/traces/contour/defaults.js

+1
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ module.exports = function supplyDefaults(traceIn, traceOut, defaultColor, layout
3333
}
3434

3535
coerce('text');
36+
coerce('hovertext');
3637
coerce('hovertemplate');
3738

3839
var isConstraint = (coerce('contours.type') === 'constraint');

src/traces/contourcarpet/attributes.js

+1
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ module.exports = extendFlat({
3636
b0: heatmapAttrs.y0,
3737
db: heatmapAttrs.dy,
3838
text: heatmapAttrs.text,
39+
hovertext: heatmapAttrs.hovertext,
3940
transpose: heatmapAttrs.transpose,
4041
atype: heatmapAttrs.xtype,
4142
btype: heatmapAttrs.ytype,

src/traces/heatmap/attributes.js

+5
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,11 @@ module.exports = extendFlat({
3333
editType: 'calc',
3434
description: 'Sets the text elements associated with each z value.'
3535
},
36+
hovertext: {
37+
valType: 'data_array',
38+
editType: 'calc',
39+
description: 'Same as `text`.'
40+
},
3641
transpose: {
3742
valType: 'boolean',
3843
dflt: false,

src/traces/heatmap/calc.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,8 @@ module.exports = function calc(gd, trace) {
131131
x: xArray,
132132
y: yArray,
133133
z: z,
134-
text: trace._text || trace.text
134+
text: trace._text || trace.text,
135+
hovertext: trace._hovertext || trace.hovertext
135136
};
136137

137138
if(xIn && xIn.length === xArray.length - 1) cd0.xCenter = xIn;

src/traces/heatmap/convert_column_xyz.js

+8
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ module.exports = function convertColumnData(trace, ax1, ax2, var1Name, var2Name,
1818
var col2 = ax2.makeCalcdata(trace, var2Name);
1919
var textCol = trace.text;
2020
var hasColumnText = (textCol !== undefined && Lib.isArray1D(textCol));
21+
var hoverTextCol = trace.hovertext;
22+
var hasColumnHoverText = (hoverTextCol !== undefined && Lib.isArray1D(hoverTextCol));
2123
var i, j;
2224

2325
var col1dv = Lib.distinctVals(col1);
@@ -26,6 +28,7 @@ module.exports = function convertColumnData(trace, ax1, ax2, var1Name, var2Name,
2628
var col2vals = col2dv.vals;
2729
var newArrays = [];
2830
var text;
31+
var hovertext;
2932

3033
for(i = 0; i < arrayVarNames.length; i++) {
3134
newArrays[i] = Lib.init2dArray(col2vals.length, col1vals.length);
@@ -34,6 +37,9 @@ module.exports = function convertColumnData(trace, ax1, ax2, var1Name, var2Name,
3437
if(hasColumnText) {
3538
text = Lib.init2dArray(col2vals.length, col1vals.length);
3639
}
40+
if(hasColumnHoverText) {
41+
hovertext = Lib.init2dArray(col2vals.length, col1vals.length);
42+
}
3743

3844
for(i = 0; i < colLen; i++) {
3945
if(col1[i] !== BADNUM && col2[i] !== BADNUM) {
@@ -48,6 +54,7 @@ module.exports = function convertColumnData(trace, ax1, ax2, var1Name, var2Name,
4854
}
4955

5056
if(hasColumnText) text[i2][i1] = textCol[i];
57+
if(hasColumnHoverText) hovertext[i2][i1] = hoverTextCol[i];
5158
}
5259
}
5360

@@ -57,4 +64,5 @@ module.exports = function convertColumnData(trace, ax1, ax2, var1Name, var2Name,
5764
trace['_' + arrayVarNames[j]] = newArrays[j];
5865
}
5966
if(hasColumnText) trace._text = text;
67+
if(hasColumnHoverText) trace._hovertext = hovertext;
6068
};

src/traces/heatmap/defaults.js

+1
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ module.exports = function supplyDefaults(traceIn, traceOut, defaultColor, layout
2929
}
3030

3131
coerce('text');
32+
coerce('hovertext');
3233
coerce('hovertemplate');
3334

3435
handleStyleDefaults(traceIn, traceOut, coerce, layout);

src/traces/heatmap/hover.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,9 @@ module.exports = function hoverPoints(pointData, xval, yval, hovermode, hoverLay
9393
if(zmask && !zmask[ny][nx]) zVal = undefined;
9494

9595
var text;
96-
if(Array.isArray(cd0.text) && Array.isArray(cd0.text[ny])) {
96+
if(Array.isArray(cd0.hovertext) && Array.isArray(cd0.hovertext[ny])) {
97+
text = cd0.hovertext[ny][nx];
98+
} else if(Array.isArray(cd0.text) && Array.isArray(cd0.text[ny])) {
9799
text = cd0.text[ny][nx];
98100
}
99101

src/traces/histogram/attributes.js

+12-1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ var barAttrs = require('../bar/attributes');
1212
var hovertemplateAttrs = require('../../components/fx/hovertemplate_attributes');
1313
var makeBinAttrs = require('./bin_attributes');
1414
var constants = require('./constants');
15+
var extendFlat = require('../../lib/extend').extendFlat;
1516

1617
module.exports = {
1718
x: {
@@ -29,7 +30,17 @@ module.exports = {
2930
].join(' ')
3031
},
3132

32-
text: barAttrs.text,
33+
text: extendFlat({}, barAttrs.text, {
34+
description: [
35+
'Sets hover text elements associated with each bar.',
36+
'If a single string, the same string appears over all bars.',
37+
'If an array of string, the items are mapped in order to the',
38+
'this trace\'s coordinates.'
39+
].join(' ')
40+
}),
41+
hovertext: extendFlat({}, barAttrs.hovertext, {
42+
description: 'Same as `text`.'
43+
}),
3344
orientation: barAttrs.orientation,
3445

3546
histfunc: {

src/traces/histogram/defaults.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ module.exports = function supplyDefaults(traceIn, traceOut, defaultColor, layout
3030
}
3131

3232
coerce('text');
33+
coerce('hovertext');
34+
coerce('hovertemplate');
3335

3436
var orientation = coerce('orientation', (y && !x) ? 'h' : 'v');
3537
var sampleLetter = orientation === 'v' ? 'x' : 'y';
@@ -57,8 +59,6 @@ module.exports = function supplyDefaults(traceIn, traceOut, defaultColor, layout
5759
// autobin(x|y) are only included here to appease Plotly.validate
5860
coerce('autobin' + sampleLetter);
5961

60-
coerce('hovertemplate');
61-
6262
handleStyleDefaults(traceIn, traceOut, coerce, defaultColor, layout);
6363

6464
Lib.coerceSelectionMarkerOpacity(traceOut, coerce);

src/traces/isosurface/attributes.js

+7
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,13 @@ var attrs = module.exports = overrideAll(extendFlat({
226226
'these elements will be seen in the hover labels.'
227227
].join(' ')
228228
},
229+
hovertext: {
230+
valType: 'string',
231+
role: 'info',
232+
dflt: '',
233+
arrayOk: true,
234+
description: 'Same as `text`.'
235+
},
229236
hovertemplate: hovertemplateAttrs()
230237
},
231238

src/traces/isosurface/convert.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ proto.handlePick = function(selection) {
7373
this.data.value[selectIndex]
7474
];
7575

76-
var text = this.data.text;
76+
var text = this.data.hovertext || this.data.text;
7777
if(Array.isArray(text) && text[selectIndex] !== undefined) {
7878
selection.textLabel = text[selectIndex];
7979
} else if(text) {

src/traces/isosurface/defaults.js

+1
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ module.exports = function supplyDefaults(traceIn, traceOut, defaultColor, layout
8484
// Coerce remaining properties
8585
[
8686
'text',
87+
'hovertext',
8788
'hovertemplate',
8889
'lighting.ambient',
8990
'lighting.diffuse',

src/traces/mesh3d/attributes.js

+8
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,14 @@ module.exports = extendFlat({
9090
'these elements will be seen in the hover labels.'
9191
].join(' ')
9292
},
93+
hovertext: {
94+
valType: 'string',
95+
role: 'info',
96+
dflt: '',
97+
arrayOk: true,
98+
editType: 'calc',
99+
description: 'Same as `text`.'
100+
},
93101
hovertemplate: hovertemplateAttrs({editType: 'calc'}),
94102

95103
delaunayaxis: {

src/traces/mesh3d/convert.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ proto.handlePick = function(selection) {
4040
this.data.z[selectIndex]
4141
];
4242

43-
var text = this.data.text;
43+
var text = this.data.hovertext || this.data.text;
4444
if(Array.isArray(text) && text[selectIndex] !== undefined) {
4545
selection.textLabel = text[selectIndex];
4646
} else if(text) {

src/traces/mesh3d/defaults.js

+1
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ module.exports = function supplyDefaults(traceIn, traceOut, defaultColor, layout
8888
}
8989

9090
coerce('text');
91+
coerce('hovertext');
9192
coerce('hovertemplate');
9293

9394
// disable 1D transforms

src/traces/ohlc/attributes.js

+8
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,14 @@ module.exports = {
104104
'this trace\'s sample points.'
105105
].join(' ')
106106
},
107+
hovertext: {
108+
valType: 'string',
109+
role: 'info',
110+
dflt: '',
111+
arrayOk: true,
112+
editType: 'calc',
113+
description: 'Same as `text`.'
114+
},
107115

108116
tickwidth: {
109117
valType: 'number',

src/traces/ohlc/calc.js

+2
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ function calcCommon(gd, trace, x, ya, ptFunc) {
5656
var c = ya.makeCalcdata(trace, 'close');
5757

5858
var hasTextArray = Array.isArray(trace.text);
59+
var hasHovertextArray = Array.isArray(trace.hovertext);
5960

6061
// we're optimists - before we have any changing data, assume increasing
6162
var increasing = true;
@@ -87,6 +88,7 @@ function calcCommon(gd, trace, x, ya, ptFunc) {
8788
pt.dir = increasing ? 'increasing' : 'decreasing';
8889

8990
if(hasTextArray) pt.tx = trace.text[i];
91+
if(hasHovertextArray) pt.htx = trace.hovertext[i];
9092

9193
cd.push(pt);
9294
} else {

src/traces/ohlc/defaults.js

+1
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ module.exports = function supplyDefaults(traceIn, traceOut, defaultColor, layout
3131
handleDirection(traceIn, traceOut, coerce, 'decreasing');
3232

3333
coerce('text');
34+
coerce('hovertext');
3435
coerce('tickwidth');
3536

3637
layout._requestRangeslider[traceOut.xaxis] = true;

0 commit comments

Comments
 (0)