Skip to content

Commit b91fd3b

Browse files
committed
[proof of concept] add 'hovertext' attribute
1 parent 8782089 commit b91fd3b

File tree

4 files changed

+22
-2
lines changed

4 files changed

+22
-2
lines changed

src/traces/scatter/arrays_to_calcdata.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ var Lib = require('../../lib');
1616
module.exports = function arraysToCalcdata(cd, trace) {
1717

1818
Lib.mergeArray(trace.text, cd, 'tx');
19+
Lib.mergeArray(trace.hovertext, cd, 'htx');
1920
Lib.mergeArray(trace.customdata, cd, 'data');
2021
Lib.mergeArray(trace.textposition, cd, 'tp');
2122
if(trace.textfont) {

src/traces/scatter/attributes.js

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,23 @@ module.exports = {
8383
'If a single string, the same string appears over',
8484
'all the data points.',
8585
'If an array of string, the items are mapped in order to the',
86-
'this trace\'s (x,y) coordinates.'
86+
'this trace\'s (x,y) coordinates.',
87+
'If trace `hoverinfo` contains a *text* flag and *hovertext* is not set,',
88+
'these elements will be seen in the hover labels.'
89+
].join(' ')
90+
},
91+
hovertext: {
92+
valType: 'string',
93+
role: 'info',
94+
dflt: '',
95+
arrayOk: true,
96+
description: [
97+
'Sets hover text elements associated with each (x,y) pair.',
98+
'If a single string, the same string appears over',
99+
'all the data points.',
100+
'If an array of string, the items are mapped in order to the',
101+
'this trace\'s (x,y) coordinates.',
102+
'To be seen, trace `hoverinfo` must contain a *text* flag.'
87103
].join(' ')
88104
},
89105
mode: {

src/traces/scatter/defaults.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ module.exports = function supplyDefaults(traceIn, traceOut, defaultColor, layout
3838

3939
coerce('customdata');
4040
coerce('text');
41+
coerce('hovertext');
4142
coerce('mode', defaultMode);
4243
coerce('ids');
4344

src/traces/scatter/hover.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,9 @@ module.exports = function hoverPoints(pointData, xval, yval, hovermode) {
7272
yLabelVal: di.y
7373
});
7474

75-
if(di.tx) pointData.text = di.tx;
75+
if(di.htx) pointData.text = di.htx;
76+
else if(trace.hovertext) pointData.text = trace.hovertext;
77+
else if(di.tx) pointData.text = di.tx;
7678
else if(trace.text) pointData.text = trace.text;
7779

7880
ErrorBars.hoverInfo(di, trace, pointData);

0 commit comments

Comments
 (0)