Skip to content

Commit 391074b

Browse files
committed
fixup hover on period bars - use period width
1 parent 756f498 commit 391074b

File tree

2 files changed

+83
-60
lines changed

2 files changed

+83
-60
lines changed

src/traces/bar/hover.js

+6-3
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,13 @@ function hoverOnBars(pointData, xval, yval, hovermode, opts) {
3939
function thisBarMaxPos(di) { return thisBarExtPos(di, 1); }
4040

4141
function thisBarExtPos(di, sgn) {
42-
return di[posLetter] + 0.5 * sgn * di.w;
42+
if(di.orig_p !== undefined) {
43+
return di.p + sgn * Math.abs(di.p - di.orig_p);
44+
}
45+
return di[posLetter] + sgn * di.w / 2;
4346
}
4447

45-
var minPos = isClosest ?
48+
var minPos = isClosest || trace[posLetter + 'period'] ?
4649
thisBarMinPos :
4750
function(di) {
4851
/*
@@ -60,7 +63,7 @@ function hoverOnBars(pointData, xval, yval, hovermode, opts) {
6063
return Math.min(thisBarMinPos(di), di.p - t.bardelta / 2);
6164
};
6265

63-
var maxPos = isClosest ?
66+
var maxPos = isClosest || trace[posLetter + 'period'] ?
6467
thisBarMaxPos :
6568
function(di) {
6669
return Math.max(thisBarMaxPos(di), di.p + t.bardelta / 2);

test/jasmine/tests/hover_label_test.js

+77-57
Original file line numberDiff line numberDiff line change
@@ -2967,13 +2967,6 @@ describe('hover on traces with (x|y)period positioning', function() {
29672967
nums: '(Q1, 1)'
29682968
});
29692969
})
2970-
.then(function() { _hover(380, 395); })
2971-
.then(function() {
2972-
assertHoverLabelContent({
2973-
name: 'middle (M3)',
2974-
nums: '(Q1, 2)'
2975-
});
2976-
})
29772970
.then(function() { _hover(415, 425); })
29782971
.then(function() {
29792972
assertHoverLabelContent({
@@ -3010,13 +3003,6 @@ describe('hover on traces with (x|y)period positioning', function() {
30103003
nums: '(Jan 2001, 1)'
30113004
});
30123005
})
3013-
.then(function() { _hover(665, 395); })
3014-
.then(function() {
3015-
assertHoverLabelContent({
3016-
name: 'middle (M12)',
3017-
nums: '(Jul 2001, 2)'
3018-
});
3019-
})
30203006
.then(function() { _hover(700, 425); })
30213007
.then(function() {
30223008
assertHoverLabelContent({
@@ -5215,7 +5201,7 @@ describe('hovermode: (x|y)unified', function() {
52155201

52165202
_hover(gd, { xpx: 100, ypx: 200 });
52175203
assertLabel({title: 'Jan 1, 2000', items: [
5218-
'bar : (Dec, 2)',
5204+
'bar : (Jan, 1)',
52195205
'scatter : 1.1'
52205206
]});
52215207

@@ -5326,31 +5312,41 @@ describe('hovermode: (x|y)unified', function() {
53265312
name: 'bar',
53275313
type: 'bar',
53285314
x: [
5329-
'2017-07-01',
5330-
'2017-10-01',
5331-
'2018-01-01',
5315+
'2017-01',
5316+
'2017-04',
5317+
'2017-07',
5318+
'2017-10',
5319+
'2018-01',
53325320
],
53335321
xhoverformat: 'Q%q',
53345322
xperiod: 'M3',
53355323
y: [
5336-
12,
5337-
15,
5338-
18
5324+
0,
5325+
3,
5326+
6,
5327+
9,
5328+
12
53395329
]
53405330
},
53415331
{
53425332
name: 'scatter',
53435333
type: 'scatter',
53445334
x: [
5345-
'2017-07-01',
5346-
'2017-08-01',
5347-
'2017-09-01',
5348-
'2017-10-01',
5349-
'2017-11-01',
5350-
'2017-12-01',
5351-
'2018-01-01',
5352-
'2018-02-01',
5353-
'2018-03-01',
5335+
'2017-01',
5336+
'2017-02',
5337+
'2017-03',
5338+
'2017-04',
5339+
'2017-05',
5340+
'2017-06',
5341+
'2017-07',
5342+
'2017-08',
5343+
'2017-09',
5344+
'2017-10',
5345+
'2017-11',
5346+
'2017-12',
5347+
'2018-01',
5348+
'2018-02',
5349+
'2018-03'
53545350
],
53555351
xhoverformat: '%b',
53565352
xperiod: 'M1',
@@ -5364,6 +5360,12 @@ describe('hovermode: (x|y)unified', function() {
53645360
7,
53655361
8,
53665362
9,
5363+
10,
5364+
11,
5365+
12,
5366+
13,
5367+
14,
5368+
15
53675369
]
53685370
}
53695371
],
@@ -5382,59 +5384,77 @@ describe('hovermode: (x|y)unified', function() {
53825384
}
53835385
})
53845386
.then(function(gd) {
5385-
_hover(gd, { xpx: 50, ypx: 200 });
5386-
assertLabel({title: 'Jul', items: [
5387-
'bar : (Q3, 12)',
5387+
_hover(gd, { xpx: 25, ypx: 200 });
5388+
assertLabel({title: 'Jan', items: [
5389+
'bar : (Q1, 0)',
53885390
'scatter : 1'
53895391
]});
53905392

5391-
_hover(gd, { xpx: 75, ypx: 200 });
5392-
assertLabel({title: 'Aug', items: [
5393-
'bar : (Q3, 12)',
5393+
_hover(gd, { xpx: 50, ypx: 200 });
5394+
assertLabel({title: 'Feb', items: [
5395+
'bar : (Q1, 0)',
53945396
'scatter : 2'
53955397
]});
53965398

5397-
_hover(gd, { xpx: 100, ypx: 200 });
5398-
assertLabel({title: 'Sep', items: [
5399-
'bar : (Q3, 12)',
5399+
_hover(gd, { xpx: 75, ypx: 200 });
5400+
assertLabel({title: 'Mar', items: [
5401+
'bar : (Q1, 0)',
54005402
'scatter : 3'
54015403
]});
54025404

5403-
_hover(gd, { xpx: 150, ypx: 200 });
5404-
assertLabel({title: 'Oct', items: [
5405-
'bar : (Q4, 15)',
5405+
_hover(gd, { xpx: 100, ypx: 200 });
5406+
assertLabel({title: 'Apr', items: [
5407+
'bar : (Q2, 3)',
54065408
'scatter : 4'
54075409
]});
54085410

5409-
_hover(gd, { xpx: 200, ypx: 200 });
5410-
assertLabel({title: 'Nov', items: [
5411-
'bar : (Q4, 15)',
5411+
_hover(gd, { xpx: 125, ypx: 200 });
5412+
assertLabel({title: 'May', items: [
5413+
'bar : (Q2, 3)',
54125414
'scatter : 5'
54135415
]});
54145416

5415-
_hover(gd, { xpx: 250, ypx: 200 });
5416-
assertLabel({title: 'Dec', items: [
5417-
'bar : (Q4, 15)',
5417+
_hover(gd, { xpx: 150, ypx: 200 });
5418+
assertLabel({title: 'Jun', items: [
5419+
'bar : (Q2, 3)',
54185420
'scatter : 6'
54195421
]});
54205422

5421-
_hover(gd, { xpx: 300, ypx: 200 });
5422-
assertLabel({title: 'Jan', items: [
5423-
'bar : (Q1, 18)',
5423+
_hover(gd, { xpx: 200, ypx: 200 });
5424+
assertLabel({title: 'Jul', items: [
5425+
'bar : (Q3, 6)',
54245426
'scatter : 7'
54255427
]});
54265428

5427-
_hover(gd, { xpx: 350, ypx: 200 });
5428-
assertLabel({title: 'Feb', items: [
5429-
'bar : (Q1, 18)',
5429+
_hover(gd, { xpx: 225, ypx: 200 });
5430+
assertLabel({title: 'Aug', items: [
5431+
'bar : (Q3, 6)',
54305432
'scatter : 8'
54315433
]});
54325434

5433-
_hover(gd, { xpx: 400, ypx: 200 });
5434-
assertLabel({title: 'Mar', items: [
5435-
'bar : (Q1, 18)',
5435+
_hover(gd, { xpx: 250, ypx: 200 });
5436+
assertLabel({title: 'Sep', items: [
5437+
'bar : (Q3, 6)',
54365438
'scatter : 9'
54375439
]});
5440+
5441+
_hover(gd, { xpx: 275, ypx: 200 });
5442+
assertLabel({title: 'Oct', items: [
5443+
'bar : (Q4, 9)',
5444+
'scatter : 10'
5445+
]});
5446+
5447+
_hover(gd, { xpx: 300, ypx: 200 });
5448+
assertLabel({title: 'Nov', items: [
5449+
'bar : (Q4, 9)',
5450+
'scatter : 11'
5451+
]});
5452+
5453+
_hover(gd, { xpx: 325, ypx: 200 });
5454+
assertLabel({title: 'Dec', items: [
5455+
'bar : (Q4, 9)',
5456+
'scatter : 12'
5457+
]});
54385458
})
54395459
.then(done, done.fail);
54405460
});

0 commit comments

Comments
 (0)