-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix geo plot hover interaction for Firefox #5607
Changes from all commits
341963e
c437006
7b3929a
7c23483
f0e8e98
c80ce55
ff60f21
37b46d0
ef1dcbf
56b3599
7b5c166
344fb91
a9da031
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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; | ||
}; | ||
|
@@ -1267,3 +1279,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() { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Non-blocking suggestion to avoid if statement inside the function: lib.getPositionFromD3Event = isProblematicFirefox ?
function() {
// layerX and layerY are non-standard, so we only fallback to them when we have to:
return [
d3.event.layerX,
d3.event.layerY
];
} : function() {
return [
d3.event.offsetX,
d3.event.offsetY
];
}; There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Personally I find ternary operators way harder to read - but I'd say that's just personal preference in the end :D There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think the point of @archmoj's comment was not so much about whether to use if (isProblematicFirefox) {
lib.getPositionFromD3Event = function() {...}
} else {
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 | ||
]; | ||
} | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It appears regex.
exec
was not used in any other places of our code.Wondering is it is possible to convert this regex.
exec
to a regex.test
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unfortunately not, as regex.test does only return true or false, but we need to evaluate the exact version of Firefox in the user agent string.
However, exec has the same compatibility as test: see mdn