Skip to content

Commit

Permalink
generalize Fx.hover to non-cartesian cases:
Browse files Browse the repository at this point in the history
- 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
  • Loading branch information
etpinard committed May 25, 2016
1 parent e369300 commit 858a338
Showing 1 changed file with 38 additions and 20 deletions.
58 changes: 38 additions & 20 deletions src/plots/cartesian/graph_interact.js
Original file line number Diff line number Diff line change
Expand Up @@ -310,27 +310,45 @@ function hover(gd, evt, subplot) {

if(!subplot) subplot = 'xy';

// if the user passed in an array of subplots,
// use those instead of finding overlayed plots
var subplots = Array.isArray(subplot) ? subplot : [subplot];

var fullLayout = gd._fullLayout,
plotinfo = fullLayout._plots[subplot],

//If the user passed in an array of subplots, use those instead of finding overlayed plots
subplots = Array.isArray(subplot) ?
subplot :
// list of all overlaid subplots to look at
[subplot].concat(plotinfo.overlays
.map(function(pi) { return pi.id; })),

xaArray = subplots.map(function(spId) {
var ternary = (gd._fullLayout[spId] || {})._ternary;
if(ternary) return ternary.xaxis;
return Axes.getFromId(gd, spId, 'x');
}),
yaArray = subplots.map(function(spId) {
var ternary = (gd._fullLayout[spId] || {})._ternary;
if(ternary) return ternary.yaxis;
return Axes.getFromId(gd, spId, 'y');
}),
hovermode = evt.hovermode || fullLayout.hovermode;
plots = fullLayout._plots || [],
plotinfo = plots[subplot];

// list of all overlaid subplots to look at
if(plotinfo) {
var overlayedSubplots = plotinfo.overlays.map(function(pi) {
return pi.id;
});

subplots = subplots.concat(overlayedSubplots);
}

var len = subplots.length,
xaArray = new Array(len),
yaArray = new Array(len);

for(var i = 0; i < len; i++) {
var spId = subplots[i];

// 'cartesian' case
var plotObj = plots[spId];
if(plotObj) {
xaArray[i] = plotObj.xaxis;
yaArray[i] = plotObj.yaxis;
continue;
}

// other subplot types
var _subplot = fullLayout[spId]._subplot;
xaArray[i] = _subplot.xaxis;
yaArray[i] = _subplot.yaxis;
}

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

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

0 comments on commit 858a338

Please sign in to comment.