Skip to content

Commit d20bdc1

Browse files
committed
add support for scalar hover 'text' in surface traces
1 parent 8ae2d0e commit d20bdc1

File tree

3 files changed

+21
-4
lines changed

3 files changed

+21
-4
lines changed

src/traces/surface/attributes.js

+11-2
Original file line numberDiff line numberDiff line change
@@ -113,9 +113,18 @@ var attrs = module.exports = overrideAll({
113113
},
114114

115115
text: {
116-
valType: 'data_array',
117-
description: 'Sets the text elements associated with each z value.'
116+
valType: 'string',
117+
role: 'info',
118+
dflt: '',
119+
arrayOk: true,
120+
editType: 'calc',
121+
description: [
122+
'Sets the text elements associated with each z value.',
123+
'If trace `hoverinfo` contains a *text* flag and *hovertext* is not set,',
124+
'these elements will be seen in the hover labels.'
125+
].join(' ')
118126
},
127+
119128
surfacecolor: {
120129
valType: 'data_array',
121130
description: [

src/traces/surface/convert.js

+5-2
Original file line numberDiff line numberDiff line change
@@ -67,10 +67,13 @@ proto.handlePick = function(selection) {
6767
];
6868

6969
var text = this.data.text;
70-
if(text && text[selectIndex[1]] && text[selectIndex[1]][selectIndex[0]] !== undefined) {
70+
if(Array.isArray(text) && text[selectIndex[1]] && text[selectIndex[1]][selectIndex[0]] !== undefined) {
7171
selection.textLabel = text[selectIndex[1]][selectIndex[0]];
72+
} else if(text) {
73+
selection.textLabel = text;
74+
} else {
75+
selection.textLabel = '';
7276
}
73-
else selection.textLabel = '';
7477

7578
selection.data.dataCoordinate = selection.dataCoordinate.slice();
7679

test/jasmine/tests/gl3d_plot_interact_test.js

+5
Original file line numberDiff line numberDiff line change
@@ -298,6 +298,11 @@ describe('Test gl3d plots', function() {
298298
.then(_hover)
299299
.then(function() {
300300
assertHoverText(null, null, null, 'one two');
301+
302+
return Plotly.restyle(gd, 'text', 'yo!');
303+
})
304+
.then(function() {
305+
assertHoverText(null, null, null, 'yo!');
301306
})
302307
.then(done);
303308
});

0 commit comments

Comments
 (0)