Skip to content

Commit 07b695a

Browse files
authored
Merge pull request #3401 from plotly/horiz-box-violin-label-align-fix
Fix horizontal box/violin hover label misalignment under hovermode:'closest'
2 parents 568a376 + e3e5f31 commit 07b695a

File tree

3 files changed

+58
-2
lines changed

3 files changed

+58
-2
lines changed

src/components/fx/hover.js

+1-2
Original file line numberDiff line numberDiff line change
@@ -1082,7 +1082,6 @@ function createHoverText(hoverData, opts, gd) {
10821082
// information then.
10831083
function hoverAvoidOverlaps(hoverData, ax, fullLayout) {
10841084
var nummoves = 0;
1085-
10861085
var axSign = 1;
10871086

10881087
// make groups of touching points
@@ -1328,7 +1327,7 @@ function cleanPoint(d, hovermode) {
13281327
fill('fontColor', 'htc', 'hoverlabel.font.color');
13291328
fill('nameLength', 'hnl', 'hoverlabel.namelength');
13301329

1331-
d.posref = hovermode === 'y' ?
1330+
d.posref = (hovermode === 'y' || (hovermode === 'closest' && trace.orientation === 'h')) ?
13321331
(d.xa._offset + (d.x0 + d.x1) / 2) :
13331332
(d.ya._offset + (d.y0 + d.y1) / 2);
13341333

test/jasmine/tests/box_test.js

+23
Original file line numberDiff line numberDiff line change
@@ -312,6 +312,29 @@ describe('Test box hover:', function() {
312312
},
313313
nums: 'look:0.7',
314314
name: ''
315+
}, {
316+
desc: 'orientation:h | hovermode:y',
317+
mock: require('@mocks/box_grouped_horz.json'),
318+
pos: [430, 130],
319+
nums: [
320+
'max: 1', 'mean ± σ: 0.6833333 ± 0.2409472', 'min: 0.3',
321+
'q1: 0.5', 'q3: 0.9', 'median: 0.7'],
322+
name: ['', '', '', '', '', 'carrots'],
323+
axis: 'day 2',
324+
hOrder: [0, 4, 5, 1, 3, 2]
325+
}, {
326+
desc: 'orientation:h | hovermode:closest',
327+
mock: require('@mocks/box_grouped_horz.json'),
328+
patch: function(fig) {
329+
fig.layout.hovermode = 'closest';
330+
return fig;
331+
},
332+
pos: [430, 130],
333+
nums: [
334+
'(max: 1, day 2)', '(mean ± σ: 0.6833333 ± 0.2409472, day 2)', '(min: 0.3, day 2)',
335+
'(q1: 0.5, day 2)', '(q3: 0.9, day 2)', '(median: 0.7, day 2)'],
336+
name: ['', '', '', '', '', 'carrots'],
337+
hOrder: [0, 4, 5, 1, 3, 2]
315338
}].forEach(function(specs) {
316339
it('should generate correct hover labels ' + specs.desc, function(done) {
317340
run(specs).catch(failTest).then(done);

test/jasmine/tests/violin_test.js

+34
Original file line numberDiff line numberDiff line change
@@ -489,6 +489,40 @@ describe('Test violin hover:', function() {
489489
nums: '(96, Old Faithful)',
490490
name: '',
491491
isRotated: false
492+
}, {
493+
desc: 'orientation:h | hovermode:y',
494+
mock: require('@mocks/violin_grouped_horz-multicategory.json'),
495+
patch: function(fig) {
496+
// don't hover on kde, to avoid local vs CI discrepancies
497+
fig.data.forEach(function(t) {
498+
t.hoveron = 'violins';
499+
});
500+
return fig;
501+
},
502+
pos: [430, 130],
503+
nums: ['max: 0.9', 'min: 0.1', 'q1: 0.2', 'q3: 0.7', 'median: 0.4'],
504+
name: ['', '', '', '', 'kale'],
505+
axis: '2018 - day 2',
506+
hOrder: [0, 3, 4, 2, 1]
507+
}, {
508+
desc: 'orientation:h | hovermode:closest',
509+
mock: require('@mocks/violin_grouped_horz-multicategory.json'),
510+
patch: function(fig) {
511+
// don't hover on kde, to avoid local vs CI discrepancies
512+
fig.data.forEach(function(t) {
513+
t.hoveron = 'violins';
514+
});
515+
fig.layout.hovermode = 'closest';
516+
return fig;
517+
},
518+
pos: [430, 130],
519+
nums: [
520+
'(max: 0.9, 2018 - day 2)', '(min: 0.1, 2018 - day 2)',
521+
'(q1: 0.2, 2018 - day 2)', '(q3: 0.7, 2018 - day 2)',
522+
'(median: 0.4, 2018 - day 2)'
523+
],
524+
name: ['', '', '', '', 'kale'],
525+
hOrder: [0, 3, 4, 2, 1]
492526
}]
493527
.forEach(function(specs) {
494528
it('should generate correct hover labels ' + specs.desc, function(done) {

0 commit comments

Comments
 (0)