Skip to content

Commit 266fced

Browse files
committed
avoid infinit hoverdistance to confuse bar hover when picking extra points
1 parent 93ab146 commit 266fced

File tree

5 files changed

+16
-11
lines changed

5 files changed

+16
-11
lines changed

src/components/fx/hover.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -490,6 +490,7 @@ function _hover(gd, evt, subplot, noHoverEvent) {
490490
if(hoverdistance !== 0) {
491491
if(trace._module && trace._module.hoverPoints) {
492492
var newPoints = trace._module.hoverPoints(pointData, xval, yval, _mode, {
493+
finiteRange: true,
493494
hoverLayer: fullLayout._hoverlayer
494495
});
495496

@@ -1868,23 +1869,25 @@ function orderRangePoints(hoverData, hovermode) {
18681869
var axLetter = hovermode.charAt(0);
18691870

18701871
var first = [];
1872+
var second = [];
18711873
var last = [];
18721874

18731875
for(var i = 0; i < hoverData.length; i++) {
18741876
var d = hoverData[i];
18751877

18761878
if(
1877-
d.trace[axLetter + 'period'] ||
18781879
Registry.traceIs(d.trace, 'bar-like') ||
18791880
Registry.traceIs(d.trace, 'box-violin')
18801881
) {
18811882
last.push(d);
1883+
} else if(d.trace[axLetter + 'period']) {
1884+
second.push(d);
18821885
} else {
18831886
first.push(d);
18841887
}
18851888
}
18861889

1887-
return first.concat(last);
1890+
return first.concat(second).concat(last);
18881891
}
18891892

18901893
function customVal(axLetter, winningPoint, fullLayout) {

src/traces/bar/hover.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ var getLineWidth = require('./helpers').getLineWidth;
99
var hoverLabelText = require('../../plots/cartesian/axes').hoverLabelText;
1010
var BADNUM = require('../../constants/numerical').BADNUM;
1111

12-
function hoverPoints(pointData, xval, yval, hovermode) {
13-
var barPointData = hoverOnBars(pointData, xval, yval, hovermode);
12+
function hoverPoints(pointData, xval, yval, hovermode, opts) {
13+
var barPointData = hoverOnBars(pointData, xval, yval, hovermode, opts);
1414

1515
if(barPointData) {
1616
var cd = barPointData.cd;
@@ -24,7 +24,7 @@ function hoverPoints(pointData, xval, yval, hovermode) {
2424
}
2525
}
2626

27-
function hoverOnBars(pointData, xval, yval, hovermode) {
27+
function hoverOnBars(pointData, xval, yval, hovermode, opts) {
2828
var cd = pointData.cd;
2929
var trace = cd[0].trace;
3030
var t = cd[0].t;
@@ -67,6 +67,8 @@ function hoverOnBars(pointData, xval, yval, hovermode) {
6767
};
6868

6969
function inbox(_minPos, _maxPos, maxDistance) {
70+
if(opts.finiteRange) maxDistance = 0;
71+
7072
// add a little to the pseudo-distance for wider bars, so that like scatter,
7173
// if you are over two overlapping bars, the narrower one wins.
7274
return Fx.inbox(_minPos - posVal, _maxPos - posVal,

src/traces/funnel/hover.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ var opacity = require('../../components/color').opacity;
44
var hoverOnBars = require('../bar/hover').hoverOnBars;
55
var formatPercent = require('../../lib').formatPercent;
66

7-
module.exports = function hoverPoints(pointData, xval, yval, hovermode) {
8-
var point = hoverOnBars(pointData, xval, yval, hovermode);
7+
module.exports = function hoverPoints(pointData, xval, yval, hovermode, opts) {
8+
var point = hoverOnBars(pointData, xval, yval, hovermode, opts);
99
if(!point) return;
1010

1111
var cd = point.cd;

src/traces/histogram/hover.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
var barHover = require('../bar/hover').hoverPoints;
44
var hoverLabelText = require('../../plots/cartesian/axes').hoverLabelText;
55

6-
module.exports = function hoverPoints(pointData, xval, yval, hovermode) {
7-
var pts = barHover(pointData, xval, yval, hovermode);
6+
module.exports = function hoverPoints(pointData, xval, yval, hovermode, opts) {
7+
var pts = barHover(pointData, xval, yval, hovermode, opts);
88

99
if(!pts) return;
1010

src/traces/waterfall/hover.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ var DIRSYMBOL = {
1010
decreasing: delta.DECREASING.SYMBOL
1111
};
1212

13-
module.exports = function hoverPoints(pointData, xval, yval, hovermode) {
14-
var point = hoverOnBars(pointData, xval, yval, hovermode);
13+
module.exports = function hoverPoints(pointData, xval, yval, hovermode, opts) {
14+
var point = hoverOnBars(pointData, xval, yval, hovermode, opts);
1515
if(!point) return;
1616

1717
var cd = point.cd;

0 commit comments

Comments
 (0)