Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Show box/violin position when hovering over pts #3441

Merged
merged 1 commit into from
Jan 21, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 14 additions & 4 deletions src/traces/box/hover.js
Original file line number Diff line number Diff line change
Expand Up @@ -240,15 +240,25 @@ function hoverOnPoints(pointData, xval, yval) {
name: trace.name,
x0: xc - rad,
x1: xc + rad,
xLabelVal: pt.x,
y0: yc - rad,
y1: yc + rad,
yLabelVal: pt.y,
spikeDistance: pointData.distance
});
var pLetter = trace.orientation === 'h' ? 'y' : 'x';
var pa = trace.orientation === 'h' ? ya : xa;

var pa;
if(trace.orientation === 'h') {
pa = ya;
closePtData.xLabelVal = pt.x;
closePtData.yLabelVal = di.pos;
} else {
pa = xa;
closePtData.xLabelVal = di.pos;
closePtData.yLabelVal = pt.y;
}

var pLetter = pa._id.charAt(0);
closePtData[pLetter + 'Spike'] = pa.c2p(di.pos, true);

fillHoverText(pt, trace, closePtData);

return closePtData;
Expand Down
15 changes: 15 additions & 0 deletions test/jasmine/tests/box_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -335,6 +335,21 @@ describe('Test box hover:', function() {
'(q1: 0.5, day 2)', '(q3: 0.9, day 2)', '(median: 0.7, day 2)'],
name: ['', '', '', '', '', 'carrots'],
hOrder: [0, 4, 5, 1, 3, 2]
}, {
desc: 'on boxpoints with numeric positions | hovermode:closest',
mock: {
data: [{
type: 'box',
boxpoints: 'all',
jitter: 0,
x: [2, 2, 2, 2, 2],
y: [13.1, 14.2, 14, 13, 13.3]
}],
layout: {hovermode: 'closest'}
},
pos: [202, 335],
nums: '(2, 13.1)',
name: ''
}].forEach(function(specs) {
it('should generate correct hover labels ' + specs.desc, function(done) {
run(specs).catch(failTest).then(done);
Expand Down
16 changes: 16 additions & 0 deletions test/jasmine/tests/violin_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -523,6 +523,22 @@ describe('Test violin hover:', function() {
],
name: ['', '', '', '', 'kale'],
hOrder: [0, 3, 4, 2, 1]
}, {
desc: 'on points with numeric positions | orientation:h | hovermode:closest',
mock: {
data: [{
type: 'violin',
points: 'all',
jitter: 0,
orientation: 'h',
y: [2, 2, 2, 2, 2],
x: [13.1, 14.2, 14, 13, 13.3]
}],
layout: {hovermode: 'closest'}
},
pos: [417, 309],
nums: '(14, 2)',
name: ''
}]
.forEach(function(specs) {
it('should generate correct hover labels ' + specs.desc, function(done) {
Expand Down