From 5124e4509ecf1fabb231d91a59a45d0b0c766362 Mon Sep 17 00:00:00 2001 From: Domino987 Date: Wed, 24 May 2023 23:09:42 +0200 Subject: [PATCH 1/5] return empty array for no hover points --- src/components/fx/hover.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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; From 313fec0fe8c32b16625fa937e309b525d767fddf Mon Sep 17 00:00:00 2001 From: Domino987 Date: Wed, 24 May 2023 23:13:42 +0200 Subject: [PATCH 2/5] Add test for #6614 --- test/jasmine/tests/hover_label_test.js | 35 ++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/test/jasmine/tests/hover_label_test.js b/test/jasmine/tests/hover_label_test.js index f180412454f..ba197f35e6b 100644 --- a/test/jasmine/tests/hover_label_test.js +++ b/test/jasmine/tests/hover_label_test.js @@ -4725,6 +4725,41 @@ 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); From 789860d454d22eb988b1d7c29d8ba7efb1a7b299 Mon Sep 17 00:00:00 2001 From: Domino987 Date: Wed, 24 May 2023 23:24:11 +0200 Subject: [PATCH 3/5] Create draflog --- draftlogs/6615_fix.md | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 draftlogs/6615_fix.md 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! From 77e1520fb715bfd9a35647d1a4615b8d4fb2d087 Mon Sep 17 00:00:00 2001 From: Domino987 Date: Wed, 24 May 2023 23:34:45 +0200 Subject: [PATCH 4/5] linting --- test/jasmine/tests/hover_label_test.js | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/test/jasmine/tests/hover_label_test.js b/test/jasmine/tests/hover_label_test.js index ba197f35e6b..9b83baaeaba 100644 --- a/test/jasmine/tests/hover_label_test.js +++ b/test/jasmine/tests/hover_label_test.js @@ -4725,12 +4725,12 @@ 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], + x: [1,100], y: [1, 1] }, { name: 'B', @@ -4739,7 +4739,7 @@ describe('hovermode: (x|y)unified', function() { hoverinfo: 'none' }], layout: { - xaxis: {range: [40,60]}, + xaxis: {range: [40,60]}, hovermode: 'x unified', showlegend: false, width: 500, @@ -4754,7 +4754,6 @@ describe('hovermode: (x|y)unified', function() { }) .then(function() { _hover(gd, { xpx: 200, ypx: 200 }); - expect(gd._hoverdata, undefined); assertHoverLabelContent({}); }) From ca4a4b1dfaaca7548f29a21365812b62770ce68d Mon Sep 17 00:00:00 2001 From: Domino987 Date: Thu, 25 May 2023 07:02:56 +0200 Subject: [PATCH 5/5] linting v2 --- test/jasmine/tests/hover_label_test.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/test/jasmine/tests/hover_label_test.js b/test/jasmine/tests/hover_label_test.js index 9b83baaeaba..440d588e098 100644 --- a/test/jasmine/tests/hover_label_test.js +++ b/test/jasmine/tests/hover_label_test.js @@ -4730,16 +4730,16 @@ describe('hovermode: (x|y)unified', function() { Plotly.newPlot(gd, { data: [{ name: 'A', - x: [1,100], + x: [1, 100], y: [1, 1] }, { name: 'B', y: [1], - x:[50], + x: [50], hoverinfo: 'none' }], layout: { - xaxis: {range: [40,60]}, + xaxis: {range: [40, 60]}, hovermode: 'x unified', showlegend: false, width: 500,