Skip to content
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
12 changes: 10 additions & 2 deletions src/traces/bar/hover.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ function hoverOnBars(pointData, xval, yval, hovermode) {
var trace = cd[0].trace;
var t = cd[0].t;
var isClosest = (hovermode === 'closest');
var isWaterfall = (trace.type === 'waterfall');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm. I guess it would be annoying to move this logic in waterfall/hover.js. 😞

var maxHoverDistance = pointData.maxHoverDistance;
var maxSpikeDistance = pointData.maxSpikeDistance;

Expand Down Expand Up @@ -82,10 +83,17 @@ function hoverOnBars(pointData, xval, yval, hovermode) {
}

function sizeFn(di) {
var v = sizeVal;
var b = di.b;
var s = di[sizeLetter];

if(isWaterfall) {
s += Math.abs(di.rawS || 0);
}

// add a gradient so hovering near the end of a
// bar makes it a little closer match
return Fx.inbox(di.b - sizeVal, di[sizeLetter] - sizeVal,
maxHoverDistance + (di[sizeLetter] - sizeVal) / (di[sizeLetter] - di.b) - 1);
return Fx.inbox(b - v, s - v, maxHoverDistance + (s - v) / (s - b) - 1);
}

if(trace.orientation === 'h') {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@
"margin": { "l": 150 },
"height": 800,
"width": 800,
"hovermode": "closest",
"showlegend": true
}
}
9 changes: 8 additions & 1 deletion test/jasmine/tests/waterfall_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1257,6 +1257,13 @@ describe('waterfall hover', function() {
expect(out.style).toEqual([0, '#3D9970', 0, 13.23]);
assertPos(out.pos, [11.87, 59.33, 52.71, 52.71]);
});

it('should return the correct hover point data (case closest - decreasing case)', function() {
var out = _hover(gd, 0.8, 4, 'closest');

expect(out.style).toBeCloseToArray([1, '#FF4136', 1, -9.47]);
assertPos(out.pos, [137, 181, 266, 266]);
});
});

describe('text labels', function() {
Expand Down Expand Up @@ -1371,6 +1378,7 @@ describe('waterfall hover', function() {
[-3.9, 1, 'closest'],
[5.9, 1.9, 'closest'],
[-3.9, -10, 'x'],
[1, 2.1, 'closest'],
[5.9, 19, 'x']
].forEach(function(hoverSpec) {
var out = _hover(gd, hoverSpec[0], hoverSpec[1], hoverSpec[2]);
Expand All @@ -1382,7 +1390,6 @@ describe('waterfall hover', function() {
// then a few that are off the edge so yield nothing
[
[1, -0.1, 'closest'],
[1, 2.1, 'closest'],
[-4.1, 1, 'closest'],
[6.1, 1, 'closest'],
[-4.1, 1, 'x'],
Expand Down