diff --git a/src/components/fx/hover.js b/src/components/fx/hover.js index 0d7915aebda..1190a7f1a95 100644 --- a/src/components/fx/hover.js +++ b/src/components/fx/hover.js @@ -772,12 +772,9 @@ function _hover(gd, evt, subplot, noHoverEvent) { hoverdistance: fullLayout.hoverdistance }; - var actualHoverData = hoverData.filter(function(d) { - return d.hoverinfo !== 'none'; - }); - var hoverLabels = actualHoverData.length && createHoverText(actualHoverData, labelOpts, gd); + var hoverLabels = createHoverText(hoverData, labelOpts, gd); - if(hoverLabels && !helpers.isUnifiedHover(hovermode)) { + if(!helpers.isUnifiedHover(hovermode)) { hoverAvoidOverlaps(hoverLabels, rotateLabels ? 'xa' : 'ya', fullLayout); alignHoverText(hoverLabels, rotateLabels, fullLayout._invScaleX, fullLayout._invScaleY); } // TODO: tagName hack is needed to appease geo.js's hack of using evt.target=true @@ -1025,14 +1022,11 @@ function createHoverText(hoverData, opts, gd) { // Show a single hover label if(helpers.isUnifiedHover(hovermode)) { - var unifiedHoverData = hoverData.filter(function(d) { - return d.hoverinfo !== 'none'; - }); // Delete leftover hover labels from other hovermodes container.selectAll('g.hovertext').remove(); // Return early if nothing is hovered on - if(unifiedHoverData.length === 0) return; + if(hoverData.length === 0) return; // mock legend var mockLayoutIn = { @@ -1054,11 +1048,14 @@ function createHoverText(hoverData, opts, gd) { // prepare items for the legend mockLegend.entries = []; - for(var j = 0; j < unifiedHoverData.length; j++) { - var texts = getHoverLabelText(unifiedHoverData[j], true, hovermode, fullLayout, t0); + for(var j = 0; j < hoverData.length; j++) { + var pt = hoverData[j]; + if(pt.hoverinfo === 'none') continue; + + var texts = getHoverLabelText(pt, true, hovermode, fullLayout, t0); var text = texts[0]; var name = texts[1]; - var pt = unifiedHoverData[j]; + pt.name = name; if(name !== '') { pt.text = name + ' : ' + text; @@ -1093,7 +1090,7 @@ function createHoverText(hoverData, opts, gd) { var tbb = legendContainer.node().getBoundingClientRect(); var tWidth = tbb.width + 2 * HOVERTEXTPAD; var tHeight = tbb.height + 2 * HOVERTEXTPAD; - var winningPoint = unifiedHoverData[0]; + var winningPoint = hoverData[0]; var avgX = (winningPoint.x0 + winningPoint.x1) / 2; var avgY = (winningPoint.y0 + winningPoint.y1) / 2; // When a scatter (or e.g. heatmap) point wins, it's OK for the hovelabel to occlude the bar and other points. @@ -1108,11 +1105,11 @@ function createHoverText(hoverData, opts, gd) { lyTop = avgY - HOVERTEXTPAD; lyBottom = avgY + HOVERTEXTPAD; } else { - lyTop = Math.min.apply(null, unifiedHoverData.map(function(c) { return Math.min(c.y0, c.y1); })); - lyBottom = Math.max.apply(null, unifiedHoverData.map(function(c) { return Math.max(c.y0, c.y1); })); + lyTop = Math.min.apply(null, hoverData.map(function(c) { return Math.min(c.y0, c.y1); })); + lyBottom = Math.max.apply(null, hoverData.map(function(c) { return Math.max(c.y0, c.y1); })); } } else { - lyTop = lyBottom = Lib.mean(unifiedHoverData.map(function(c) { return (c.y0 + c.y1) / 2; })) - tHeight / 2; + lyTop = lyBottom = Lib.mean(hoverData.map(function(c) { return (c.y0 + c.y1) / 2; })) - tHeight / 2; } var lxRight, lxLeft; @@ -1121,11 +1118,11 @@ function createHoverText(hoverData, opts, gd) { lxRight = avgX + HOVERTEXTPAD; lxLeft = avgX - HOVERTEXTPAD; } else { - lxRight = Math.max.apply(null, unifiedHoverData.map(function(c) { return Math.max(c.x0, c.x1); })); - lxLeft = Math.min.apply(null, unifiedHoverData.map(function(c) { return Math.min(c.x0, c.x1); })); + lxRight = Math.max.apply(null, hoverData.map(function(c) { return Math.max(c.x0, c.x1); })); + lxLeft = Math.min.apply(null, hoverData.map(function(c) { return Math.min(c.x0, c.x1); })); } } else { - lxRight = lxLeft = Lib.mean(unifiedHoverData.map(function(c) { return (c.x0 + c.x1) / 2; })) - tWidth / 2; + lxRight = lxLeft = Lib.mean(hoverData.map(function(c) { return (c.x0 + c.x1) / 2; })) - tWidth / 2; } var xOffset = xa._offset;