Skip to content

Commit b116dc1

Browse files
author
Domino987
committed
move filter to unified only
1 parent 6c181f6 commit b116dc1

File tree

1 file changed

+15
-15
lines changed

1 file changed

+15
-15
lines changed

src/components/fx/hover.js

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -813,10 +813,7 @@ function hoverDataKey(d) {
813813

814814
var EXTRA_STRING_REGEX = /<extra>([\s\S]*)<\/extra>/;
815815

816-
function createHoverText(allHoverData, opts, gd) {
817-
var hoverData = allHoverData.filter(function(d) {
818-
return d.hoverinfo !== 'none';
819-
});
816+
function createHoverText(hoverData, opts, gd) {
820817
var fullLayout = gd._fullLayout;
821818
var hovermode = opts.hovermode;
822819
var rotateLabels = opts.rotateLabels;
@@ -1028,11 +1025,14 @@ function createHoverText(allHoverData, opts, gd) {
10281025

10291026
// Show a single hover label
10301027
if(helpers.isUnifiedHover(hovermode)) {
1028+
var unifiedHoverData = hoverData.filter(function(d) {
1029+
return d.hoverinfo !== 'none';
1030+
});
10311031
// Delete leftover hover labels from other hovermodes
10321032
container.selectAll('g.hovertext').remove();
10331033

10341034
// Return early if nothing is hovered on
1035-
if(hoverData.length === 0) return;
1035+
if(unifiedHoverData.length === 0) return;
10361036

10371037
// mock legend
10381038
var mockLayoutIn = {
@@ -1054,11 +1054,11 @@ function createHoverText(allHoverData, opts, gd) {
10541054

10551055
// prepare items for the legend
10561056
mockLegend.entries = [];
1057-
for(var j = 0; j < hoverData.length; j++) {
1058-
var texts = getHoverLabelText(hoverData[j], true, hovermode, fullLayout, t0);
1057+
for(var j = 0; j < unifiedHoverData.length; j++) {
1058+
var texts = getHoverLabelText(unifiedHoverData[j], true, hovermode, fullLayout, t0);
10591059
var text = texts[0];
10601060
var name = texts[1];
1061-
var pt = hoverData[j];
1061+
var pt = unifiedHoverData[j];
10621062
pt.name = name;
10631063
if(name !== '') {
10641064
pt.text = name + ' : ' + text;
@@ -1093,7 +1093,7 @@ function createHoverText(allHoverData, opts, gd) {
10931093
var tbb = legendContainer.node().getBoundingClientRect();
10941094
var tWidth = tbb.width + 2 * HOVERTEXTPAD;
10951095
var tHeight = tbb.height + 2 * HOVERTEXTPAD;
1096-
var winningPoint = hoverData[0];
1096+
var winningPoint = unifiedHoverData[0];
10971097
var avgX = (winningPoint.x0 + winningPoint.x1) / 2;
10981098
var avgY = (winningPoint.y0 + winningPoint.y1) / 2;
10991099
// When a scatter (or e.g. heatmap) point wins, it's OK for the hovelabel to occlude the bar and other points.
@@ -1108,11 +1108,11 @@ function createHoverText(allHoverData, opts, gd) {
11081108
lyTop = avgY - HOVERTEXTPAD;
11091109
lyBottom = avgY + HOVERTEXTPAD;
11101110
} else {
1111-
lyTop = Math.min.apply(null, hoverData.map(function(c) { return Math.min(c.y0, c.y1); }));
1112-
lyBottom = Math.max.apply(null, hoverData.map(function(c) { return Math.max(c.y0, c.y1); }));
1111+
lyTop = Math.min.apply(null, unifiedHoverData.map(function(c) { return Math.min(c.y0, c.y1); }));
1112+
lyBottom = Math.max.apply(null, unifiedHoverData.map(function(c) { return Math.max(c.y0, c.y1); }));
11131113
}
11141114
} else {
1115-
lyTop = lyBottom = Lib.mean(hoverData.map(function(c) { return (c.y0 + c.y1) / 2; })) - tHeight / 2;
1115+
lyTop = lyBottom = Lib.mean(unifiedHoverData.map(function(c) { return (c.y0 + c.y1) / 2; })) - tHeight / 2;
11161116
}
11171117

11181118
var lxRight, lxLeft;
@@ -1121,11 +1121,11 @@ function createHoverText(allHoverData, opts, gd) {
11211121
lxRight = avgX + HOVERTEXTPAD;
11221122
lxLeft = avgX - HOVERTEXTPAD;
11231123
} else {
1124-
lxRight = Math.max.apply(null, hoverData.map(function(c) { return Math.max(c.x0, c.x1); }));
1125-
lxLeft = Math.min.apply(null, hoverData.map(function(c) { return Math.min(c.x0, c.x1); }));
1124+
lxRight = Math.max.apply(null, unifiedHoverData.map(function(c) { return Math.max(c.x0, c.x1); }));
1125+
lxLeft = Math.min.apply(null, unifiedHoverData.map(function(c) { return Math.min(c.x0, c.x1); }));
11261126
}
11271127
} else {
1128-
lxRight = lxLeft = Lib.mean(hoverData.map(function(c) { return (c.x0 + c.x1) / 2; })) - tWidth / 2;
1128+
lxRight = lxLeft = Lib.mean(unifiedHoverData.map(function(c) { return (c.x0 + c.x1) / 2; })) - tWidth / 2;
11291129
}
11301130

11311131
var xOffset = xa._offset;

0 commit comments

Comments
 (0)