Skip to content

Commit

Permalink
Merge pull request #5607 from LucaVazz/fix-choropleth-interactions-fo…
Browse files Browse the repository at this point in the history
…r-firefox

Fix geo plot hover interaction for Firefox
  • Loading branch information
archmoj authored Jun 1, 2021
2 parents 18e512c + a9da031 commit d36b491
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 1 deletion.
36 changes: 36 additions & 0 deletions src/lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -715,6 +715,18 @@ lib.isIOS = function() {
return IS_IOS_REGEX.test(window.navigator.userAgent);
};

var FIREFOX_VERSION_REGEX = /Firefox\/(\d+)\.\d+/;
lib.getFirefoxVersion = function() {
var match = FIREFOX_VERSION_REGEX.exec(window.navigator.userAgent);
if(match && match.length === 2) {
var versionInt = parseInt(match[1]);
if(!isNaN(versionInt)) {
return versionInt;
}
}
return null;
};

lib.isD3Selection = function(obj) {
return obj instanceof d3.selection;
};
Expand Down Expand Up @@ -1304,3 +1316,27 @@ lib.join2 = function(arr, mainSeparator, lastSeparator) {
lib.bigFont = function(size) {
return Math.round(1.2 * size);
};

var firefoxVersion = lib.getFirefoxVersion();
// see https://bugzilla.mozilla.org/show_bug.cgi?id=1684973
var isProblematicFirefox = firefoxVersion !== null && firefoxVersion < 86;

/**
* Return the mouse position from the last event registered by D3.
* @returns An array with two numbers, representing the x and y coordinates of the mouse pointer
* at the event relative to the targeted node.
*/
lib.getPositionFromD3Event = function() {
if(isProblematicFirefox) {
// layerX and layerY are non-standard, so we only fallback to them when we have to:
return [
d3.event.layerX,
d3.event.layerY
];
} else {
return [
d3.event.offsetX,
d3.event.offsetY
];
}
};
2 changes: 1 addition & 1 deletion src/plots/geo/geo.js
Original file line number Diff line number Diff line change
Expand Up @@ -506,7 +506,7 @@ proto.updateFx = function(fullLayout, geoLayout) {
}

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

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

0 comments on commit d36b491

Please sign in to comment.