From b0eb6dbdee15a75c5838ea6bfefa570361a12c39 Mon Sep 17 00:00:00 2001 From: archmoj Date: Thu, 5 Aug 2021 09:59:22 -0400 Subject: [PATCH 1/2] revert changes to hover.js --- src/components/fx/hover.js | 32 +++++++++++++------------------- 1 file changed, 13 insertions(+), 19 deletions(-) diff --git a/src/components/fx/hover.js b/src/components/fx/hover.js index 0d7915aebda..e9e92749801 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,11 @@ 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 texts = getHoverLabelText(hoverData[j], true, hovermode, fullLayout, t0); var text = texts[0]; var name = texts[1]; - var pt = unifiedHoverData[j]; + var pt = hoverData[j]; pt.name = name; if(name !== '') { pt.text = name + ' : ' + text; @@ -1093,7 +1087,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 +1102,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 +1115,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; From c52953dd8c652a423667e6c82d3bce572e7bc5da Mon Sep 17 00:00:00 2001 From: archmoj Date: Thu, 5 Aug 2021 10:18:31 -0400 Subject: [PATCH 2/2] do not display points with none hoverinfo in unified modes --- src/components/fx/hover.js | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/components/fx/hover.js b/src/components/fx/hover.js index e9e92749801..1190a7f1a95 100644 --- a/src/components/fx/hover.js +++ b/src/components/fx/hover.js @@ -1049,10 +1049,13 @@ function createHoverText(hoverData, opts, gd) { // prepare items for the legend mockLegend.entries = []; for(var j = 0; j < hoverData.length; j++) { - var texts = getHoverLabelText(hoverData[j], true, hovermode, fullLayout, t0); + 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 = hoverData[j]; + pt.name = name; if(name !== '') { pt.text = name + ' : ' + text;