diff --git a/draftlogs/6615_fix.md b/draftlogs/6615_fix.md new file mode 100644 index 00000000000..fd24769dc8d --- /dev/null +++ b/draftlogs/6615_fix.md @@ -0,0 +1,2 @@ +- Fix to prevent accessing undefined (hoverText.hoverLabels) in case all currently shown markers have hoverinfo: "none" [#6614]([https://github.com/plotly/plotly.js/pull/5854](https://github.com/plotly/plotly.js/issues/6614)), + with thanks to @Domino987 for the contribution! diff --git a/src/components/fx/hover.js b/src/components/fx/hover.js index 3cf438f28be..59642856e86 100644 --- a/src/components/fx/hover.js +++ b/src/components/fx/hover.js @@ -1126,7 +1126,7 @@ function createHoverText(hoverData, opts) { container.selectAll('g.hovertext').remove(); var groupedHoverData = hoverData.filter(function(data) {return data.hoverinfo !== 'none';}); // Return early if nothing is hovered on - if(groupedHoverData.length === 0) return; + if(groupedHoverData.length === 0) return []; // mock legend var hoverlabel = fullLayout.hoverlabel; diff --git a/test/jasmine/tests/hover_label_test.js b/test/jasmine/tests/hover_label_test.js index f180412454f..440d588e098 100644 --- a/test/jasmine/tests/hover_label_test.js +++ b/test/jasmine/tests/hover_label_test.js @@ -4726,6 +4726,40 @@ describe('hovermode: (x|y)unified', function() { .then(done, done.fail); }); + it('should not fail if only hoverinfo: "none" are current visible', function(done) { + Plotly.newPlot(gd, { + data: [{ + name: 'A', + x: [1, 100], + y: [1, 1] + }, { + name: 'B', + y: [1], + x: [50], + hoverinfo: 'none' + }], + layout: { + xaxis: {range: [40, 60]}, + hovermode: 'x unified', + showlegend: false, + width: 500, + height: 500, + margin: { + t: 50, + b: 50, + l: 50, + r: 50 + } + } + }) + .then(function() { + _hover(gd, { xpx: 200, ypx: 200 }); + expect(gd._hoverdata, undefined); + assertHoverLabelContent({}); + }) + .then(done, done.fail); + }); + it('y unified should work for x/y cartesian traces', function(done) { var mockCopy = Lib.extendDeep({}, mock); mockCopy.layout.hovermode = 'y unified';