Skip to content

Commit beb73eb

Browse files
authored
Merge pull request #6615 from Domino987/hoverinfo_none
Fix for #6614
2 parents 11984a2 + bcc3d59 commit beb73eb

File tree

3 files changed

+37
-1
lines changed

3 files changed

+37
-1
lines changed

draftlogs/6615_fix.md

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
- 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)),
2+
with thanks to @Domino987 for the contribution!

src/components/fx/hover.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1126,7 +1126,7 @@ function createHoverText(hoverData, opts) {
11261126
container.selectAll('g.hovertext').remove();
11271127
var groupedHoverData = hoverData.filter(function(data) {return data.hoverinfo !== 'none';});
11281128
// Return early if nothing is hovered on
1129-
if(groupedHoverData.length === 0) return;
1129+
if(groupedHoverData.length === 0) return [];
11301130

11311131
// mock legend
11321132
var hoverlabel = fullLayout.hoverlabel;

test/jasmine/tests/hover_label_test.js

+34
Original file line numberDiff line numberDiff line change
@@ -4726,6 +4726,40 @@ describe('hovermode: (x|y)unified', function() {
47264726
.then(done, done.fail);
47274727
});
47284728

4729+
it('should not fail if only hoverinfo: "none" are current visible', function(done) {
4730+
Plotly.newPlot(gd, {
4731+
data: [{
4732+
name: 'A',
4733+
x: [1, 100],
4734+
y: [1, 1]
4735+
}, {
4736+
name: 'B',
4737+
y: [1],
4738+
x: [50],
4739+
hoverinfo: 'none'
4740+
}],
4741+
layout: {
4742+
xaxis: {range: [40, 60]},
4743+
hovermode: 'x unified',
4744+
showlegend: false,
4745+
width: 500,
4746+
height: 500,
4747+
margin: {
4748+
t: 50,
4749+
b: 50,
4750+
l: 50,
4751+
r: 50
4752+
}
4753+
}
4754+
})
4755+
.then(function() {
4756+
_hover(gd, { xpx: 200, ypx: 200 });
4757+
expect(gd._hoverdata, undefined);
4758+
assertHoverLabelContent({});
4759+
})
4760+
.then(done, done.fail);
4761+
});
4762+
47294763
it('y unified should work for x/y cartesian traces', function(done) {
47304764
var mockCopy = Lib.extendDeep({}, mock);
47314765
mockCopy.layout.hovermode = 'y unified';

0 commit comments

Comments
 (0)