Skip to content

Commit 7652b90

Browse files
authored
Merge pull request #3441 from plotly/boxpoint-hover-fix-numeric-positions
Show box/violin position when hovering over pts
2 parents e6343d9 + c3624d1 commit 7652b90

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
@@ -340,6 +340,21 @@ describe('Test box hover:', function() {
340340
'(q1: 0.5, day 2)', '(q3: 0.9, day 2)', '(median: 0.7, day 2)'],
341341
name: ['', '', '', '', '', 'carrots'],
342342
hOrder: [0, 4, 5, 1, 3, 2]
343+
}, {
344+
desc: 'on boxpoints with numeric positions | hovermode:closest',
345+
mock: {
346+
data: [{
347+
type: 'box',
348+
boxpoints: 'all',
349+
jitter: 0,
350+
x: [2, 2, 2, 2, 2],
351+
y: [13.1, 14.2, 14, 13, 13.3]
352+
}],
353+
layout: {hovermode: 'closest'}
354+
},
355+
pos: [202, 335],
356+
nums: '(2, 13.1)',
357+
name: ''
343358
}].forEach(function(specs) {
344359
it('should generate correct hover labels ' + specs.desc, function(done) {
345360
run(specs).catch(failTest).then(done);

test/jasmine/tests/violin_test.js

+16
Original file line numberDiff line numberDiff line change
@@ -543,6 +543,22 @@ describe('Test violin hover:', function() {
543543
],
544544
name: ['', '', '', '', 'kale'],
545545
hOrder: [0, 3, 4, 2, 1]
546+
}, {
547+
desc: 'on points with numeric positions | orientation:h | hovermode:closest',
548+
mock: {
549+
data: [{
550+
type: 'violin',
551+
points: 'all',
552+
jitter: 0,
553+
orientation: 'h',
554+
y: [2, 2, 2, 2, 2],
555+
x: [13.1, 14.2, 14, 13, 13.3]
556+
}],
557+
layout: {hovermode: 'closest'}
558+
},
559+
pos: [417, 309],
560+
nums: '(14, 2)',
561+
name: ''
546562
}]
547563
.forEach(function(specs) {
548564
it('should generate correct hover labels ' + specs.desc, function(done) {

0 commit comments

Comments
 (0)