Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 89e52f7

Browse files
committed
warn + exit early when Fx.hover is called w/ unrecognized subplot id
1 parent 6347b0d commit 89e52f7

File tree

2 files changed

+43
-7
lines changed

2 files changed

+43
-7
lines changed

src/components/fx/hover.js

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -235,13 +235,15 @@ function _hover(gd, evt, subplot, noHoverEvent) {
235235

236236
xaArray[i] = Axes.getFromId(gd, plotObj.xaxis._id);
237237
yaArray[i] = Axes.getFromId(gd, plotObj.yaxis._id);
238-
continue;
238+
} else if(fullLayout[spId] && fullLayout[spId]._subplot) {
239+
// other subplot types
240+
var _subplot = fullLayout[spId]._subplot;
241+
xaArray[i] = _subplot.xaxis;
242+
yaArray[i] = _subplot.yaxis;
243+
} else {
244+
Lib.warn('Unrecognized subplot: ' + spId);
245+
return;
239246
}
240-
241-
// other subplot types
242-
var _subplot = fullLayout[spId]._subplot;
243-
xaArray[i] = _subplot.xaxis;
244-
yaArray[i] = _subplot.yaxis;
245247
}
246248

247249
var hovermode = evt.hovermode || fullLayout.hovermode;

test/jasmine/tests/hover_label_test.js

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,41 @@ function touch(path, options) {
3636
return;
3737
}
3838

39+
describe('Fx.hover:', function() {
40+
var gd;
41+
42+
beforeEach(function() { gd = createGraphDiv(); });
43+
44+
afterEach(destroyGraphDiv);
45+
46+
it('should warn when passing subplot ids that are not part of the graph', function(done) {
47+
spyOn(Lib, 'warn');
48+
49+
var data = [
50+
{y: [1], hoverinfo: 'y'}
51+
];
52+
53+
var layout = {
54+
xaxis: {domain: [0, 0.5]},
55+
xaxis2: {anchor: 'y2', domain: [0.5, 1]},
56+
yaxis2: {anchor: 'x2'},
57+
width: 400,
58+
height: 200,
59+
margin: {l: 0, t: 0, r: 0, b: 0},
60+
showlegend: false
61+
};
62+
63+
Plotly.plot(gd, data, layout)
64+
.then(function() {
65+
Fx.hover(gd, {xpx: 300, ypx: 100}, 'x2y2');
66+
expect(gd._hoverdata).toBe(undefined, 'did not generate hoverdata');
67+
expect(Lib.warn).toHaveBeenCalledWith('Unrecognized subplot: x2y2');
68+
})
69+
.catch(failTest)
70+
.then(done);
71+
});
72+
});
73+
3974
describe('hover info', function() {
4075
'use strict';
4176

@@ -2150,7 +2185,6 @@ describe('hover info on stacked subplots', function() {
21502185
});
21512186
});
21522187

2153-
21542188
describe('hover on many lines+bars', function() {
21552189
'use strict';
21562190

0 commit comments

Comments
 (0)