Skip to content

Commit d36b491

Browse files
authored
Merge pull request #5607 from LucaVazz/fix-choropleth-interactions-for-firefox
Fix geo plot hover interaction for Firefox
2 parents 18e512c + a9da031 commit d36b491

File tree

2 files changed

+37
-1
lines changed

2 files changed

+37
-1
lines changed

src/lib/index.js

+36
Original file line numberDiff line numberDiff line change
@@ -715,6 +715,18 @@ lib.isIOS = function() {
715715
return IS_IOS_REGEX.test(window.navigator.userAgent);
716716
};
717717

718+
var FIREFOX_VERSION_REGEX = /Firefox\/(\d+)\.\d+/;
719+
lib.getFirefoxVersion = function() {
720+
var match = FIREFOX_VERSION_REGEX.exec(window.navigator.userAgent);
721+
if(match && match.length === 2) {
722+
var versionInt = parseInt(match[1]);
723+
if(!isNaN(versionInt)) {
724+
return versionInt;
725+
}
726+
}
727+
return null;
728+
};
729+
718730
lib.isD3Selection = function(obj) {
719731
return obj instanceof d3.selection;
720732
};
@@ -1304,3 +1316,27 @@ lib.join2 = function(arr, mainSeparator, lastSeparator) {
13041316
lib.bigFont = function(size) {
13051317
return Math.round(1.2 * size);
13061318
};
1319+
1320+
var firefoxVersion = lib.getFirefoxVersion();
1321+
// see https://bugzilla.mozilla.org/show_bug.cgi?id=1684973
1322+
var isProblematicFirefox = firefoxVersion !== null && firefoxVersion < 86;
1323+
1324+
/**
1325+
* Return the mouse position from the last event registered by D3.
1326+
* @returns An array with two numbers, representing the x and y coordinates of the mouse pointer
1327+
* at the event relative to the targeted node.
1328+
*/
1329+
lib.getPositionFromD3Event = function() {
1330+
if(isProblematicFirefox) {
1331+
// layerX and layerY are non-standard, so we only fallback to them when we have to:
1332+
return [
1333+
d3.event.layerX,
1334+
d3.event.layerY
1335+
];
1336+
} else {
1337+
return [
1338+
d3.event.offsetX,
1339+
d3.event.offsetY
1340+
];
1341+
}
1342+
};

src/plots/geo/geo.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -506,7 +506,7 @@ proto.updateFx = function(fullLayout, geoLayout) {
506506
}
507507

508508
bgRect.on('mousemove', function() {
509-
var lonlat = _this.projection.invert(d3.mouse(this));
509+
var lonlat = _this.projection.invert(Lib.getPositionFromD3Event());
510510

511511
if(!lonlat || isNaN(lonlat[0]) || isNaN(lonlat[1])) {
512512
return dragElement.unhover(gd, d3.event);

0 commit comments

Comments
 (0)