Skip to content

Commit a2488a4

Browse files
committed
events: fix plotly events in geo plots
1 parent fe29404 commit a2488a4

File tree

2 files changed

+13
-17
lines changed

2 files changed

+13
-17
lines changed

src/plots/cartesian/graph_interact.js

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -414,12 +414,17 @@ function hover(gd, evt, subplot) {
414414

415415
// [x|y]px: the pixels (from top left) of the mouse location
416416
// on the currently selected plot area
417-
var xpx, ypx;
417+
var hasUserCalledHover = ('xpx' in evt || 'ypx' in evt),
418+
xpx, ypx;
418419

419-
// mouse event? ie is there a target element with
420-
// clientX and clientY values?
421-
if(evt.target && ('clientX' in evt) && ('clientY' in evt)) {
420+
if(hasUserCalledHover) {
421+
if('xpx' in evt) xpx = evt.xpx;
422+
else xpx = xaArray[0]._length / 2;
422423

424+
if('ypx' in evt) ypx = evt.ypx;
425+
else ypx = yaArray[0]._length / 2;
426+
}
427+
else {
423428
// fire the beforehover event and quit if it returns false
424429
// note that we're only calling this on real mouse events, so
425430
// manual calls to fx.hover will always run.
@@ -438,13 +443,6 @@ function hover(gd, evt, subplot) {
438443
return dragElement.unhoverRaw(gd, evt);
439444
}
440445
}
441-
else {
442-
if('xpx' in evt) xpx = evt.xpx;
443-
else xpx = xaArray[0]._length / 2;
444-
445-
if('ypx' in evt) ypx = evt.ypx;
446-
else ypx = yaArray[0]._length / 2;
447-
}
448446

449447
if('xval' in evt) xvalArray = flat(subplots, evt.xval);
450448
else xvalArray = p2c(xaArray, xpx);

src/plots/geo/geo.js

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -91,11 +91,9 @@ proto.plot = function(geoCalcData, fullLayout, promises) {
9191

9292
if(!lonlat || isNaN(lonlat[0]) || isNaN(lonlat[1])) return;
9393

94-
var evt = {
95-
target: true,
96-
xpx: mouse[0],
97-
ypx: mouse[1]
98-
};
94+
var evt = d3.event;
95+
evt.xpx = mouse[0];
96+
evt.ypx = mouse[1];
9997

10098
_this.xaxis.c2p = function() { return mouse[0]; };
10199
_this.xaxis.p2c = function() { return lonlat[0]; };
@@ -110,7 +108,7 @@ proto.plot = function(geoCalcData, fullLayout, promises) {
110108
});
111109

112110
_this.framework.on('click', function() {
113-
Fx.click(_this.graphDiv, { target: true });
111+
Fx.click(_this.graphDiv, d3.event);
114112
});
115113

116114
topojsonNameNew = topojsonUtils.getTopojsonName(geoLayout);

0 commit comments

Comments
 (0)