Skip to content

Commit 2b02c5f

Browse files
committed
add 'hovertext' to scatterternary traces
1 parent 253a29b commit 2b02c5f

File tree

3 files changed

+49
-17
lines changed

3 files changed

+49
-17
lines changed

src/traces/scatterternary/attributes.js

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,19 @@ module.exports = {
7070
'If a single string, the same string appears over',
7171
'all the data points.',
7272
'If an array of strings, the items are mapped in order to the',
73-
'the data points in (a,b,c).'
73+
'the data points in (a,b,c).',
74+
'If trace `hoverinfo` contains a *text* flag and *hovertext* is not set,',
75+
'these elements will be seen in the hover labels.'
76+
].join(' ')
77+
}),
78+
hovertext: extendFlat({}, scatterAttrs.hovertext, {
79+
description: [
80+
'Sets hover text elements associated with each (a,b,c) point.',
81+
'If a single string, the same string appears over',
82+
'all the data points.',
83+
'If an array of strings, the items are mapped in order to the',
84+
'the data points in (a,b,c).',
85+
'To be seen, trace `hoverinfo` must contain a *text* flag.'
7486
].join(' ')
7587
}),
7688
line: {

src/traces/scatterternary/defaults.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ module.exports = function supplyDefaults(traceIn, traceOut, defaultColor, layout
6363
coerce('sum');
6464

6565
coerce('text');
66+
coerce('hovertext');
6667

6768
var defaultMode = len < constants.PTS_LINESONLY ? 'lines+markers' : 'lines';
6869
coerce('mode', defaultMode);

test/jasmine/tests/scatterternary_test.js

Lines changed: 35 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -299,9 +299,7 @@ describe('scatterternary plot and hover', function() {
299299
describe('scatterternary hover', function() {
300300
'use strict';
301301

302-
var hoverPoints = ScatterTernary.hoverPoints;
303-
304-
var gd, pointData;
302+
var gd;
305303

306304
beforeAll(function(done) {
307305
gd = createGraphDiv();
@@ -310,17 +308,20 @@ describe('scatterternary hover', function() {
310308
type: 'scatterternary',
311309
a: [0.1, 0.2, 0.3],
312310
b: [0.3, 0.2, 0.1],
313-
c: [0.1, 0.4, 0.5]
311+
c: [0.1, 0.4, 0.5],
312+
text: ['A', 'B', 'C']
314313
}];
315314

316315
Plotly.plot(gd, data).then(done);
317316
});
318317

319-
beforeEach(function() {
320-
var cd = gd.calcdata,
321-
ternary = gd._fullLayout.ternary._subplot;
318+
afterAll(destroyGraphDiv);
319+
320+
function _hover(gd, xval, yval, hovermode) {
321+
var cd = gd.calcdata;
322+
var ternary = gd._fullLayout.ternary._subplot;
322323

323-
pointData = {
324+
var pointData = {
324325
index: false,
325326
distance: 20,
326327
cd: cd[0],
@@ -329,23 +330,41 @@ describe('scatterternary hover', function() {
329330
ya: ternary.yaxis
330331
};
331332

332-
});
333-
334-
afterAll(destroyGraphDiv);
333+
return ScatterTernary.hoverPoints(pointData, xval, yval, hovermode);
334+
}
335335

336-
it('should generate extra text field on hover', function() {
337-
var xval = 0.42,
338-
yval = 0.37,
339-
hovermode = 'closest';
336+
it('should generate extra text field on hover', function(done) {
337+
var xval = 0.42;
338+
var yval = 0.37;
339+
var hovermode = 'closest';
340+
var scatterPointData;
340341

341-
var scatterPointData = hoverPoints(pointData, xval, yval, hovermode);
342+
scatterPointData = _hover(gd, xval, yval, hovermode);
342343

343344
expect(scatterPointData[0].extraText).toEqual(
344345
'Component A: 0.3333333<br>Component B: 0.1111111<br>Component C: 0.5555556'
345346
);
346347

347348
expect(scatterPointData[0].xLabelVal).toBeUndefined();
348349
expect(scatterPointData[0].yLabelVal).toBeUndefined();
350+
expect(scatterPointData[0].text).toEqual('C');
351+
352+
Plotly.restyle(gd, {
353+
text: null,
354+
hovertext: [['apple', 'banana', 'orange']]
355+
})
356+
.then(function() {
357+
scatterPointData = _hover(gd, xval, yval, hovermode);
358+
359+
expect(scatterPointData[0].extraText).toEqual(
360+
'Component A: 0.3333333<br>Component B: 0.1111111<br>Component C: 0.5555556'
361+
);
362+
363+
expect(scatterPointData[0].xLabelVal).toBeUndefined();
364+
expect(scatterPointData[0].yLabelVal).toBeUndefined();
365+
expect(scatterPointData[0].text).toEqual('orange');
366+
})
367+
.then(done);
349368
});
350369

351370
});

0 commit comments

Comments
 (0)