Skip to content
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

Add 'hovertext' attribute to all traces that support hover 'text' #3553

Merged
merged 3 commits into from
Feb 19, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/traces/barpolar/attributes.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,9 @@ module.exports = {
'this trace\'s coordinates.'
].join(' ')
}),
// hovertext: barAttrs.hovertext,
hovertext: extendFlat({}, barAttrs.hovertext, {
description: 'Same as `text`.'
}),

// textposition: {},
// textfont: {},
Expand Down
2 changes: 1 addition & 1 deletion src/traces/barpolar/defaults.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ module.exports = function supplyDefaults(traceIn, traceOut, defaultColor, layout
coerce('width');

coerce('text');
coerce('hovertext');
coerce('hovertemplate');
// coerce('hovertext');

// var textPosition = coerce('textposition');
// var hasBoth = Array.isArray(textPosition) || textPosition === 'auto';
Expand Down
3 changes: 3 additions & 0 deletions src/traces/box/attributes.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,9 @@ module.exports = {
'To be seen, trace `hoverinfo` must contain a *text* flag.'
].join(' ')
}),
hovertext: extendFlat({}, scatterAttrs.hovertext, {
description: 'Same as `text`.'
}),
whiskerwidth: {
valType: 'number',
min: 0,
Expand Down
3 changes: 2 additions & 1 deletion src/traces/box/calc.js
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,8 @@ function initNestedArray(len) {

function arraysToCalcdata(pt, trace, i) {
var trace2calc = {
text: 'tx'
text: 'tx',
hovertext: 'htx'
};

for(var k in trace2calc) {
Expand Down
1 change: 1 addition & 0 deletions src/traces/box/defaults.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ function handlePointsDefaults(traceIn, traceOut, coerce, opts) {
coerce('unselected.marker.size');

coerce('text');
coerce('hovertext');
} else {
delete traceOut.marker;
}
Expand Down
1 change: 1 addition & 0 deletions src/traces/candlestick/attributes.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ module.exports = {
decreasing: directionAttrs(OHLCattrs.decreasing.line.color.dflt),

text: OHLCattrs.text,
hovertext: OHLCattrs.hovertext,
whiskerwidth: extendFlat({}, boxAttrs.whiskerwidth, { dflt: 0 }),

hoverlabel: OHLCattrs.hoverlabel,
Expand Down
1 change: 1 addition & 0 deletions src/traces/candlestick/defaults.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ module.exports = function supplyDefaults(traceIn, traceOut, defaultColor, layout
handleDirection(traceIn, traceOut, coerce, 'decreasing');

coerce('text');
coerce('hovertext');
coerce('whiskerwidth');

layout._requestRangeslider[traceOut.xaxis] = true;
Expand Down
3 changes: 3 additions & 0 deletions src/traces/choropleth/attributes.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ module.exports = extendFlat({
text: extendFlat({}, scatterGeoAttrs.text, {
description: 'Sets the text elements associated with each location.'
}),
hovertext: extendFlat({}, scatterGeoAttrs.hovertext, {
description: 'Same as `text`.'
}),
marker: {
line: {
color: scatterGeoMarkerLineAttrs.color,
Expand Down
1 change: 1 addition & 0 deletions src/traces/choropleth/defaults.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ module.exports = function supplyDefaults(traceIn, traceOut, defaultColor, layout
coerce('locationmode');

coerce('text');
coerce('hovertext');
coerce('hovertemplate');

coerce('marker.line.color');
Expand Down
8 changes: 8 additions & 0 deletions src/traces/cone/attributes.js
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,14 @@ var attrs = {
'these elements will be seen in the hover labels.'
].join(' ')
},
hovertext: {
valType: 'string',
role: 'info',
dflt: '',
arrayOk: true,
editType: 'calc',
description: 'Same as `text`.'
},
hovertemplate: hovertemplateAttrs({editType: 'calc'}, {keys: ['norm']})
};

Expand Down
2 changes: 1 addition & 1 deletion src/traces/cone/convert.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ proto.handlePick = function(selection) {
Math.sqrt(uu * uu + vv * vv + ww * ww)
];

var text = this.data.text;
var text = this.data.hovertext || this.data.text;
if(Array.isArray(text) && text[selectIndex] !== undefined) {
selection.textLabel = text[selectIndex];
} else if(text) {
Expand Down
1 change: 1 addition & 0 deletions src/traces/cone/defaults.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ module.exports = function supplyDefaults(traceIn, traceOut, defaultColor, layout
colorscaleDefaults(traceIn, traceOut, layout, coerce, {prefix: '', cLetter: 'c'});

coerce('text');
coerce('hovertext');
coerce('hovertemplate');

// disable 1D transforms (for now)
Expand Down
1 change: 1 addition & 0 deletions src/traces/contour/attributes.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ module.exports = extendFlat({
y0: heatmapAttrs.y0,
dy: heatmapAttrs.dy,
text: heatmapAttrs.text,
hovertext: heatmapAttrs.hovertext,
transpose: heatmapAttrs.transpose,
xtype: heatmapAttrs.xtype,
ytype: heatmapAttrs.ytype,
Expand Down
1 change: 1 addition & 0 deletions src/traces/contour/defaults.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ module.exports = function supplyDefaults(traceIn, traceOut, defaultColor, layout
}

coerce('text');
coerce('hovertext');
coerce('hovertemplate');

var isConstraint = (coerce('contours.type') === 'constraint');
Expand Down
1 change: 1 addition & 0 deletions src/traces/contourcarpet/attributes.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ module.exports = extendFlat({
b0: heatmapAttrs.y0,
db: heatmapAttrs.dy,
text: heatmapAttrs.text,
hovertext: heatmapAttrs.hovertext,
transpose: heatmapAttrs.transpose,
atype: heatmapAttrs.xtype,
btype: heatmapAttrs.ytype,
Expand Down
5 changes: 5 additions & 0 deletions src/traces/heatmap/attributes.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,11 @@ module.exports = extendFlat({
editType: 'calc',
description: 'Sets the text elements associated with each z value.'
},
hovertext: {
valType: 'data_array',
editType: 'calc',
description: 'Same as `text`.'
},
transpose: {
valType: 'boolean',
dflt: false,
Expand Down
3 changes: 2 additions & 1 deletion src/traces/heatmap/calc.js
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,8 @@ module.exports = function calc(gd, trace) {
x: xArray,
y: yArray,
z: z,
text: trace._text || trace.text
text: trace._text || trace.text,
hovertext: trace._hovertext || trace.hovertext
};

if(xIn && xIn.length === xArray.length - 1) cd0.xCenter = xIn;
Expand Down
8 changes: 8 additions & 0 deletions src/traces/heatmap/convert_column_xyz.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ module.exports = function convertColumnData(trace, ax1, ax2, var1Name, var2Name,
var col2 = ax2.makeCalcdata(trace, var2Name);
var textCol = trace.text;
var hasColumnText = (textCol !== undefined && Lib.isArray1D(textCol));
var hoverTextCol = trace.hovertext;
var hasColumnHoverText = (hoverTextCol !== undefined && Lib.isArray1D(hoverTextCol));
var i, j;

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

for(i = 0; i < arrayVarNames.length; i++) {
newArrays[i] = Lib.init2dArray(col2vals.length, col1vals.length);
Expand All @@ -34,6 +37,9 @@ module.exports = function convertColumnData(trace, ax1, ax2, var1Name, var2Name,
if(hasColumnText) {
text = Lib.init2dArray(col2vals.length, col1vals.length);
}
if(hasColumnHoverText) {
hovertext = Lib.init2dArray(col2vals.length, col1vals.length);
}

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

if(hasColumnText) text[i2][i1] = textCol[i];
if(hasColumnHoverText) hovertext[i2][i1] = hoverTextCol[i];
}
}

Expand All @@ -57,4 +64,5 @@ module.exports = function convertColumnData(trace, ax1, ax2, var1Name, var2Name,
trace['_' + arrayVarNames[j]] = newArrays[j];
}
if(hasColumnText) trace._text = text;
if(hasColumnHoverText) trace._hovertext = hovertext;
};
1 change: 1 addition & 0 deletions src/traces/heatmap/defaults.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ module.exports = function supplyDefaults(traceIn, traceOut, defaultColor, layout
}

coerce('text');
coerce('hovertext');
coerce('hovertemplate');

handleStyleDefaults(traceIn, traceOut, coerce, layout);
Expand Down
4 changes: 3 additions & 1 deletion src/traces/heatmap/hover.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,9 @@ module.exports = function hoverPoints(pointData, xval, yval, hovermode, hoverLay
if(zmask && !zmask[ny][nx]) zVal = undefined;

var text;
if(Array.isArray(cd0.text) && Array.isArray(cd0.text[ny])) {
if(Array.isArray(cd0.hovertext) && Array.isArray(cd0.hovertext[ny])) {
text = cd0.hovertext[ny][nx];
} else if(Array.isArray(cd0.text) && Array.isArray(cd0.text[ny])) {
text = cd0.text[ny][nx];
}

Expand Down
13 changes: 12 additions & 1 deletion src/traces/histogram/attributes.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ var barAttrs = require('../bar/attributes');
var hovertemplateAttrs = require('../../components/fx/hovertemplate_attributes');
var makeBinAttrs = require('./bin_attributes');
var constants = require('./constants');
var extendFlat = require('../../lib/extend').extendFlat;

module.exports = {
x: {
Expand All @@ -29,7 +30,17 @@ module.exports = {
].join(' ')
},

text: barAttrs.text,
text: extendFlat({}, barAttrs.text, {
description: [
'Sets hover text elements associated with each bar.',
'If a single string, the same string appears over all bars.',
'If an array of string, the items are mapped in order to the',
'this trace\'s coordinates.'
].join(' ')
}),
hovertext: extendFlat({}, barAttrs.hovertext, {
description: 'Same as `text`.'
}),
orientation: barAttrs.orientation,

histfunc: {
Expand Down
4 changes: 2 additions & 2 deletions src/traces/histogram/defaults.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ module.exports = function supplyDefaults(traceIn, traceOut, defaultColor, layout
}

coerce('text');
coerce('hovertext');
coerce('hovertemplate');

var orientation = coerce('orientation', (y && !x) ? 'h' : 'v');
var sampleLetter = orientation === 'v' ? 'x' : 'y';
Expand Down Expand Up @@ -58,8 +60,6 @@ module.exports = function supplyDefaults(traceIn, traceOut, defaultColor, layout
// autobin(x|y) are only included here to appease Plotly.validate
coerce('autobin' + sampleLetter);

coerce('hovertemplate');

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

Lib.coerceSelectionMarkerOpacity(traceOut, coerce);
Expand Down
7 changes: 7 additions & 0 deletions src/traces/isosurface/attributes.js
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,13 @@ var attrs = module.exports = overrideAll(extendFlat({
'these elements will be seen in the hover labels.'
].join(' ')
},
hovertext: {
valType: 'string',
role: 'info',
dflt: '',
arrayOk: true,
description: 'Same as `text`.'
},
hovertemplate: hovertemplateAttrs()
},

Expand Down
2 changes: 1 addition & 1 deletion src/traces/isosurface/convert.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ proto.handlePick = function(selection) {
this.data.value[selectIndex]
];

var text = this.data.text;
var text = this.data.hovertext || this.data.text;
if(Array.isArray(text) && text[selectIndex] !== undefined) {
selection.textLabel = text[selectIndex];
} else if(text) {
Expand Down
1 change: 1 addition & 0 deletions src/traces/isosurface/defaults.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ module.exports = function supplyDefaults(traceIn, traceOut, defaultColor, layout
// Coerce remaining properties
[
'text',
'hovertext',
'hovertemplate',
'lighting.ambient',
'lighting.diffuse',
Expand Down
8 changes: 8 additions & 0 deletions src/traces/mesh3d/attributes.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,14 @@ module.exports = extendFlat({
'these elements will be seen in the hover labels.'
].join(' ')
},
hovertext: {
valType: 'string',
role: 'info',
dflt: '',
arrayOk: true,
editType: 'calc',
description: 'Same as `text`.'
},
hovertemplate: hovertemplateAttrs({editType: 'calc'}),

delaunayaxis: {
Expand Down
2 changes: 1 addition & 1 deletion src/traces/mesh3d/convert.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ proto.handlePick = function(selection) {
this.data.z[selectIndex]
];

var text = this.data.text;
var text = this.data.hovertext || this.data.text;
if(Array.isArray(text) && text[selectIndex] !== undefined) {
selection.textLabel = text[selectIndex];
} else if(text) {
Expand Down
1 change: 1 addition & 0 deletions src/traces/mesh3d/defaults.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ module.exports = function supplyDefaults(traceIn, traceOut, defaultColor, layout
}

coerce('text');
coerce('hovertext');
coerce('hovertemplate');

// disable 1D transforms
Expand Down
8 changes: 8 additions & 0 deletions src/traces/ohlc/attributes.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,14 @@ module.exports = {
'this trace\'s sample points.'
].join(' ')
},
hovertext: {
valType: 'string',
role: 'info',
dflt: '',
arrayOk: true,
editType: 'calc',
description: 'Same as `text`.'
},

tickwidth: {
valType: 'number',
Expand Down
2 changes: 2 additions & 0 deletions src/traces/ohlc/calc.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ function calcCommon(gd, trace, x, ya, ptFunc) {
var c = ya.makeCalcdata(trace, 'close');

var hasTextArray = Array.isArray(trace.text);
var hasHovertextArray = Array.isArray(trace.hovertext);

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

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

cd.push(pt);
} else {
Expand Down
1 change: 1 addition & 0 deletions src/traces/ohlc/defaults.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ module.exports = function supplyDefaults(traceIn, traceOut, defaultColor, layout
handleDirection(traceIn, traceOut, coerce, 'decreasing');

coerce('text');
coerce('hovertext');
coerce('tickwidth');

layout._requestRangeslider[traceOut.xaxis] = true;
Expand Down
Loading