Skip to content

Commit 858a338

Browse files
committed
generalize Fx.hover to non-cartesian cases:
- don't assume that fullLayout._plots is defined - don't assume that fullLayout._plots[''] is defined - use fullLayout[spId]._subplot.{x,y}axis as subplot x/y axes in non-cartesian cases - perf: replace two .map calls with one for loop
1 parent e369300 commit 858a338

File tree

1 file changed

+38
-20
lines changed

1 file changed

+38
-20
lines changed

src/plots/cartesian/graph_interact.js

+38-20
Original file line numberDiff line numberDiff line change
@@ -310,27 +310,45 @@ function hover(gd, evt, subplot) {
310310

311311
if(!subplot) subplot = 'xy';
312312

313+
// if the user passed in an array of subplots,
314+
// use those instead of finding overlayed plots
315+
var subplots = Array.isArray(subplot) ? subplot : [subplot];
316+
313317
var fullLayout = gd._fullLayout,
314-
plotinfo = fullLayout._plots[subplot],
315-
316-
//If the user passed in an array of subplots, use those instead of finding overlayed plots
317-
subplots = Array.isArray(subplot) ?
318-
subplot :
319-
// list of all overlaid subplots to look at
320-
[subplot].concat(plotinfo.overlays
321-
.map(function(pi) { return pi.id; })),
322-
323-
xaArray = subplots.map(function(spId) {
324-
var ternary = (gd._fullLayout[spId] || {})._ternary;
325-
if(ternary) return ternary.xaxis;
326-
return Axes.getFromId(gd, spId, 'x');
327-
}),
328-
yaArray = subplots.map(function(spId) {
329-
var ternary = (gd._fullLayout[spId] || {})._ternary;
330-
if(ternary) return ternary.yaxis;
331-
return Axes.getFromId(gd, spId, 'y');
332-
}),
333-
hovermode = evt.hovermode || fullLayout.hovermode;
318+
plots = fullLayout._plots || [],
319+
plotinfo = plots[subplot];
320+
321+
// list of all overlaid subplots to look at
322+
if(plotinfo) {
323+
var overlayedSubplots = plotinfo.overlays.map(function(pi) {
324+
return pi.id;
325+
});
326+
327+
subplots = subplots.concat(overlayedSubplots);
328+
}
329+
330+
var len = subplots.length,
331+
xaArray = new Array(len),
332+
yaArray = new Array(len);
333+
334+
for(var i = 0; i < len; i++) {
335+
var spId = subplots[i];
336+
337+
// 'cartesian' case
338+
var plotObj = plots[spId];
339+
if(plotObj) {
340+
xaArray[i] = plotObj.xaxis;
341+
yaArray[i] = plotObj.yaxis;
342+
continue;
343+
}
344+
345+
// other subplot types
346+
var _subplot = fullLayout[spId]._subplot;
347+
xaArray[i] = _subplot.xaxis;
348+
yaArray[i] = _subplot.yaxis;
349+
}
350+
351+
var hovermode = evt.hovermode || fullLayout.hovermode;
334352

335353
if(['x', 'y', 'closest'].indexOf(hovermode) === -1 || !gd.calcdata ||
336354
gd.querySelector('.zoombox') || gd._dragging) {

0 commit comments

Comments
 (0)