Skip to content

Commit 46a177a

Browse files
committed
skip of traces that don't exist in Fx.hover()
- this used to result in: 'TypeError: Cannot read property '0' of undefined'
1 parent 4c3b4b4 commit 46a177a

File tree

2 files changed

+19
-6
lines changed

2 files changed

+19
-6
lines changed

src/components/fx/hover.js

+8-6
Original file line numberDiff line numberDiff line change
@@ -330,12 +330,14 @@ function _hover(gd, evt, subplot, noHoverEvent) {
330330
// user specified an array of points to highlight
331331
hovermode = 'array';
332332
for(itemnum = 0; itemnum < evt.length; itemnum++) {
333-
cd = gd.calcdata[evt[itemnum].curveNumber||0];
334-
trace = cd[0].trace;
335-
if(cd[0].trace.hoverinfo !== 'skip') {
336-
searchData.push(cd);
337-
if(trace.orientation === 'h') {
338-
hasOneHorizontalTrace = true;
333+
cd = gd.calcdata[evt[itemnum].curveNumber || 0];
334+
if(cd) {
335+
trace = cd[0].trace;
336+
if(cd[0].trace.hoverinfo !== 'skip') {
337+
searchData.push(cd);
338+
if(trace.orientation === 'h') {
339+
hasOneHorizontalTrace = true;
340+
}
339341
}
340342
}
341343
}

test/jasmine/tests/finance_test.js

+11
Original file line numberDiff line numberDiff line change
@@ -1241,6 +1241,17 @@ describe('finance trace hover via Fx.hover():', function() {
12411241
name: ['trace 0', 'trace 1']
12421242
}, 'hover over 3rd items (aka 2nd visible items)');
12431243
})
1244+
.then(function() {
1245+
Lib.clearThrottle();
1246+
return Plotly.react(gd, [gd.data[0]], gd.layout);
1247+
})
1248+
.then(function() { hover(281, 252); })
1249+
.then(function() {
1250+
assertHoverLabelContent({
1251+
nums: 'hover off by 1\nopen: 7\nhigh: 7\nlow: 7\nclose: 7 ▲',
1252+
name: ''
1253+
}, 'after removing 2nd trace');
1254+
})
12441255
.catch(failTest)
12451256
.then(done);
12461257
});

0 commit comments

Comments
 (0)