Skip to content

Commit c3624d1

Browse files
committed
show box/violin position when hovering over pts
... instead of showing the point's position.
1 parent cc45972 commit c3624d1

File tree

3 files changed

+45
-4
lines changed

3 files changed

+45
-4
lines changed

src/traces/box/hover.js

+14-4
Original file line numberDiff line numberDiff line change
@@ -240,15 +240,25 @@ function hoverOnPoints(pointData, xval, yval) {
240240
name: trace.name,
241241
x0: xc - rad,
242242
x1: xc + rad,
243-
xLabelVal: pt.x,
244243
y0: yc - rad,
245244
y1: yc + rad,
246-
yLabelVal: pt.y,
247245
spikeDistance: pointData.distance
248246
});
249-
var pLetter = trace.orientation === 'h' ? 'y' : 'x';
250-
var pa = trace.orientation === 'h' ? ya : xa;
247+
248+
var pa;
249+
if(trace.orientation === 'h') {
250+
pa = ya;
251+
closePtData.xLabelVal = pt.x;
252+
closePtData.yLabelVal = di.pos;
253+
} else {
254+
pa = xa;
255+
closePtData.xLabelVal = di.pos;
256+
closePtData.yLabelVal = pt.y;
257+
}
258+
259+
var pLetter = pa._id.charAt(0);
251260
closePtData[pLetter + 'Spike'] = pa.c2p(di.pos, true);
261+
252262
fillHoverText(pt, trace, closePtData);
253263

254264
return closePtData;

test/jasmine/tests/box_test.js

+15
Original file line numberDiff line numberDiff line change
@@ -335,6 +335,21 @@ describe('Test box hover:', function() {
335335
'(q1: 0.5, day 2)', '(q3: 0.9, day 2)', '(median: 0.7, day 2)'],
336336
name: ['', '', '', '', '', 'carrots'],
337337
hOrder: [0, 4, 5, 1, 3, 2]
338+
}, {
339+
desc: 'on boxpoints with numeric positions | hovermode:closest',
340+
mock: {
341+
data: [{
342+
type: 'box',
343+
boxpoints: 'all',
344+
jitter: 0,
345+
x: [2, 2, 2, 2, 2],
346+
y: [13.1, 14.2, 14, 13, 13.3]
347+
}],
348+
layout: {hovermode: 'closest'}
349+
},
350+
pos: [202, 335],
351+
nums: '(2, 13.1)',
352+
name: ''
338353
}].forEach(function(specs) {
339354
it('should generate correct hover labels ' + specs.desc, function(done) {
340355
run(specs).catch(failTest).then(done);

test/jasmine/tests/violin_test.js

+16
Original file line numberDiff line numberDiff line change
@@ -523,6 +523,22 @@ describe('Test violin hover:', function() {
523523
],
524524
name: ['', '', '', '', 'kale'],
525525
hOrder: [0, 3, 4, 2, 1]
526+
}, {
527+
desc: 'on points with numeric positions | orientation:h | hovermode:closest',
528+
mock: {
529+
data: [{
530+
type: 'violin',
531+
points: 'all',
532+
jitter: 0,
533+
orientation: 'h',
534+
y: [2, 2, 2, 2, 2],
535+
x: [13.1, 14.2, 14, 13, 13.3]
536+
}],
537+
layout: {hovermode: 'closest'}
538+
},
539+
pos: [417, 309],
540+
nums: '(14, 2)',
541+
name: ''
526542
}]
527543
.forEach(function(specs) {
528544
it('should generate correct hover labels ' + specs.desc, function(done) {

0 commit comments

Comments
 (0)