Skip to content

Commit e7b02c0

Browse files
committed
more robust handling of splom in fx/hover.js
1 parent 60df466 commit e7b02c0

File tree

3 files changed

+38
-11
lines changed

3 files changed

+38
-11
lines changed

src/components/fx/helpers.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,30 @@
1111
var Lib = require('../../lib');
1212

1313
// look for either subplot or xaxis and yaxis attributes
14+
// does not handle splom case
1415
exports.getSubplot = function getSubplot(trace) {
1516
return trace.subplot || (trace.xaxis + trace.yaxis) || trace.geo;
1617
};
1718

19+
// is trace in given list of subplots?
20+
// does handle splom case
21+
exports.isTraceInSubplots = function isTraceInSubplot(trace, subplots) {
22+
if(trace.type === 'splom') {
23+
var xaxes = trace.xaxes || [];
24+
var yaxes = trace.yaxes || [];
25+
for(var i = 0; i < xaxes.length; i++) {
26+
for(var j = 0; j < yaxes.length; j++) {
27+
if(subplots.indexOf(xaxes[i] + yaxes[j]) !== -1) {
28+
return true;
29+
}
30+
}
31+
}
32+
return false;
33+
}
34+
35+
return subplots.indexOf(exports.getSubplot(trace)) !== -1;
36+
};
37+
1838
// convenience functions for mapping all relevant axes
1939
exports.flat = function flat(subplots, v) {
2040
var out = new Array(subplots.length);

src/components/fx/hover.js

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,7 @@ function _hover(gd, evt, subplot, noHoverEvent) {
215215
var hoverdistance = fullLayout.hoverdistance === -1 ? Infinity : fullLayout.hoverdistance;
216216
var spikedistance = fullLayout.spikedistance === -1 ? Infinity : fullLayout.spikedistance;
217217

218-
// hoverData: the set of candidate points we've found to highlight
218+
// hoverData: the set of candidate points we've found to highlight
219219
var hoverData = [],
220220

221221
// searchData: the data to search in. Mostly this is just a copy of
@@ -265,8 +265,7 @@ function _hover(gd, evt, subplot, noHoverEvent) {
265265
for(curvenum = 0; curvenum < gd.calcdata.length; curvenum++) {
266266
cd = gd.calcdata[curvenum];
267267
trace = cd[0].trace;
268-
// FIXME: find more efficient way to check splom trace
269-
if((trace.hoverinfo !== 'skip' && subplots.indexOf(helpers.getSubplot(trace)) !== -1) || trace.type === 'splom') {
268+
if(trace.hoverinfo !== 'skip' && helpers.isTraceInSubplots(trace, subplots)) {
270269
searchData.push(cd);
271270
}
272271
}
@@ -339,10 +338,15 @@ function _hover(gd, evt, subplot, noHoverEvent) {
339338
// the rest of this function from running and failing
340339
if(['carpet', 'contourcarpet'].indexOf(trace._module.name) !== -1) continue;
341340

342-
subplotId = helpers.getSubplot(trace);
343-
344-
// FIXME: detect proper subplot index for splom
345-
subploti = trace.type === 'splom' ? 0 : subplots.indexOf(subplotId);
341+
if(trace.type === 'splom') {
342+
// splom traces do not generate overlay subplots,
343+
// it is safe to assume here splom traces correspond to the 0th subplot
344+
subploti = 0;
345+
subplotId = subplots[subploti];
346+
} else {
347+
subplotId = helpers.getSubplot(trace);
348+
subploti = subplots.indexOf(subplotId);
349+
}
346350

347351
// within one trace mode can sometimes be overridden
348352
mode = hovermode;

src/traces/splom/index.js

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -206,16 +206,19 @@ function hoverPoints(pointData, xval, yval, hovermode) {
206206
var xpx = xa.c2p(xval);
207207
var ypx = ya.c2p(yval);
208208
var maxDistance = pointData.distance;
209-
var dimLength = trace.dimensions.length;
209+
var dimensions = trace.dimensions;
210210

211-
// TODO: get data for xa, ya
212211
var xi, yi;
213-
for(var i = 0; i < dimLength; i++) {
212+
for(var i = 0; i < dimensions.length; i++) {
214213
if(trace.xaxes[i] === xa._id) xi = i;
215214
if(trace.yaxes[i] === ya._id) yi = i;
216215
}
217216

218-
console.log(xi, yi);
217+
var x = dimensions[xi].values;
218+
var y = dimensions[yi].values;
219+
220+
221+
console.log(x, y);
219222
}
220223

221224
function selectPoints(searchInfo, polygon) {

0 commit comments

Comments
 (0)