Skip to content

Commit d14cdab

Browse files
committed
add support for (hover) 'text' in mesh3d traces
1 parent aae3929 commit d14cdab

File tree

4 files changed

+58
-0
lines changed

4 files changed

+58
-0
lines changed

src/traces/mesh3d/attributes.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,19 @@ module.exports = extendFlat(colorAttrs('', 'calc', false), {
7878

7979
},
8080

81+
text: {
82+
valType: 'string',
83+
role: 'info',
84+
dflt: '',
85+
arrayOk: true,
86+
editType: 'calc',
87+
description: [
88+
'Sets the text elements associated with the vertices.',
89+
'If trace `hoverinfo` contains a *text* flag and *hovertext* is not set,',
90+
'these elements will be seen in the hover labels.'
91+
].join(' ')
92+
},
93+
8194
delaunayaxis: {
8295
valType: 'enumerated',
8396
role: 'info',

src/traces/mesh3d/convert.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,13 @@ proto.handlePick = function(selection) {
4040
this.data.z[selectIndex]
4141
];
4242

43+
var text = this.data.text;
44+
if(Array.isArray(text) && text[selectIndex] !== undefined) {
45+
selection.textLabel = text[selectIndex];
46+
} else if(text) {
47+
selection.textLabel = text;
48+
}
49+
4350
return true;
4451
}
4552
};

src/traces/mesh3d/defaults.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,4 +84,6 @@ module.exports = function supplyDefaults(traceIn, traceOut, defaultColor, layout
8484
else if('vertexcolor' in traceIn) coerce('vertexcolor');
8585
else coerce('color', defaultColor);
8686
}
87+
88+
coerce('text');
8789
};

test/jasmine/tests/gl3d_plot_interact_test.js

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -302,6 +302,42 @@ describe('Test gl3d plots', function() {
302302
.then(done);
303303
});
304304

305+
it('should display correct hover labels (mesh3d case)', function(done) {
306+
var x = [1, 1, 2, 3, 4, 2];
307+
var y = [2, 1, 3, 4, 5, 3];
308+
var z = [3, 7, 4, 5, 3.5, 2];
309+
var text = x.map(function(_, i) {
310+
return [
311+
'ts: ' + x[i],
312+
'hz: ' + y[i],
313+
'ftt:' + z[i]
314+
].join('<br>');
315+
});
316+
317+
function _hover() {
318+
mouseEvent('mouseover', 250, 250);
319+
return delay(20)();
320+
}
321+
322+
Plotly.newPlot(gd, [{
323+
type: 'mesh3d',
324+
x: x,
325+
y: y,
326+
z: z,
327+
text: text
328+
}], {
329+
width: 500,
330+
height: 500
331+
})
332+
.then(delay(20))
333+
.then(_hover)
334+
.then(function() {
335+
assertHoverText('x: 3', 'y: 4', 'z: 5', 'ts: 3\nhz: 4\nftt:5');
336+
})
337+
.catch(fail)
338+
.then(done);
339+
});
340+
305341
it('should be able to reversibly change trace type', function(done) {
306342
var _mock = Lib.extendDeep({}, mock2);
307343
var sceneLayout = { aspectratio: { x: 1, y: 1, z: 1 } };

0 commit comments

Comments
 (0)