Skip to content

Commit 8cf9e02

Browse files
committed
fix hoverData 'posref' for horiz traces in hovermode:'closest'
- that 'posref' val is used to sort the labels before the during the 'avoid-overlap' algo.
1 parent 364cdec commit 8cf9e02

File tree

3 files changed

+47
-2
lines changed

3 files changed

+47
-2
lines changed

src/components/fx/hover.js

+1-2
Original file line numberDiff line numberDiff line change
@@ -1080,7 +1080,6 @@ function createHoverText(hoverData, opts, gd) {
10801080
// information then.
10811081
function hoverAvoidOverlaps(hoverData, ax, fullLayout) {
10821082
var nummoves = 0;
1083-
10841083
var axSign = 1;
10851084

10861085
// make groups of touching points
@@ -1326,7 +1325,7 @@ function cleanPoint(d, hovermode) {
13261325
fill('fontColor', 'htc', 'hoverlabel.font.color');
13271326
fill('nameLength', 'hnl', 'hoverlabel.namelength');
13281327

1329-
d.posref = hovermode === 'y' ?
1328+
d.posref = (hovermode === 'y' || (hovermode === 'closest' && trace.orientation === 'h')) ?
13301329
(d.xa._offset + (d.x0 + d.x1) / 2) :
13311330
(d.ya._offset + (d.y0 + d.y1) / 2);
13321331

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

+23
Original file line numberDiff line numberDiff line change
@@ -489,6 +489,29 @@ 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+
pos: [430, 130],
496+
nums: ['max: 0.9', 'min: 0.1', 'q1: 0.2', 'q3: 0.7', 'x: 0.7963605, kde: 0.445', 'median: 0.4'],
497+
name: ['', '', '', '', '', 'kale'],
498+
axis: '2018 - day 2',
499+
hOrder: [0, 4, 3, 5, 2, 1]
500+
}, {
501+
desc: 'orientation:h | hovermode:closest',
502+
mock: require('@mocks/violin_grouped_horz-multicategory.json'),
503+
patch: function(fig) {
504+
fig.layout.hovermode = 'closest';
505+
return fig;
506+
},
507+
pos: [430, 130],
508+
nums: [
509+
'(max: 0.9, 2018 - day 2)', '(min: 0.1, 2018 - day 2)',
510+
'(q1: 0.2, 2018 - day 2)', '(q3: 0.7, 2018 - day 2)',
511+
'(x: 0.7963605, kde: 0.445, 2018 - day 2)', '(median: 0.4, 2018 - day 2)'
512+
],
513+
name: ['', '', '', '', '', 'kale'],
514+
hOrder: [0, 4, 3, 5, 2, 1]
492515
}]
493516
.forEach(function(specs) {
494517
it('should generate correct hover labels ' + specs.desc, function(done) {

0 commit comments

Comments
 (0)