Skip to content

Add 'hovertext' attribute in scatter* traces #1523

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

Merged
merged 13 commits into from
Apr 7, 2017
Merged
1 change: 1 addition & 0 deletions src/traces/scatter/arrays_to_calcdata.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ var Lib = require('../../lib');
module.exports = function arraysToCalcdata(cd, trace) {

Lib.mergeArray(trace.text, cd, 'tx');
Lib.mergeArray(trace.hovertext, cd, 'htx');
Lib.mergeArray(trace.customdata, cd, 'data');
Lib.mergeArray(trace.textposition, cd, 'tp');
if(trace.textfont) {
Expand Down
18 changes: 17 additions & 1 deletion src/traces/scatter/attributes.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,23 @@ module.exports = {
'If a single string, the same string appears over',
'all the data points.',
'If an array of string, the items are mapped in order to the',
'this trace\'s (x,y) coordinates.'
'this trace\'s (x,y) coordinates.',
'If trace `hoverinfo` contains a *text* flag and *hovertext* is not set,',
'these elements will be seen in the hover labels.'
].join(' ')
},
hovertext: {
valType: 'string',
role: 'info',
dflt: '',
arrayOk: true,
description: [
'Sets hover text elements associated with each (x,y) pair.',
'If a single string, the same string appears over',
'all the data points.',
'If an array of string, the items are mapped in order to the',
'this trace\'s (x,y) coordinates.',
'To be seen, trace `hoverinfo` must contain a *text* flag.'
].join(' ')
},
mode: {
Expand Down
1 change: 1 addition & 0 deletions src/traces/scatter/defaults.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ module.exports = function supplyDefaults(traceIn, traceOut, defaultColor, layout

coerce('customdata');
coerce('text');
coerce('hovertext');
coerce('mode', defaultMode);
coerce('ids');

Expand Down
4 changes: 3 additions & 1 deletion src/traces/scatter/hover.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,9 @@ module.exports = function hoverPoints(pointData, xval, yval, hovermode) {
yLabelVal: di.y
});

if(di.tx) pointData.text = di.tx;
if(di.htx) pointData.text = di.htx;
else if(trace.hovertext) pointData.text = trace.hovertext;
else if(di.tx) pointData.text = di.tx;
Copy link
Contributor Author

@etpinard etpinard Mar 28, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is what I came up with:

  • If trace hoverinfo contains a 'text' flag and hovertext is not set the text elements will be seen in the hover labels
  • If trace hoverinfo contains a 'text' flag and hovertext is set, hovertext takes precedence over text i.e. the hoverinfo elements will be seen in the hover labels

else if(trace.text) pointData.text = trace.text;

ErrorBars.hoverInfo(di, trace, pointData);
Expand Down