-
-
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
Fix geo plot hover interaction for Firefox #5607
Conversation
Demo of the fix: Tested with
|
Thanks very much for the information, investigation and PR.
|
…ix-choropleth-interactions-for-firefox
Hey, thanks for having a look! 1.Indeed, I can sadly reproduce it not working for Firefox v <= 85 or the current Firefox ESR (78.10.0esr). What would be the preferred way to proceed? We could test the user agent string and fallback to 2.I'll have a look how well the change works with parcats, parcoords and sliders in a bit |
Given the fact that FireFox >=86 is pretty new, I think we still need to handle versions <=85 as well. Lines 708 to 716 in a5a5de9
plotly.js/src/lib/preserve_drawing_buffer.js Lines 44 to 60 in a5a5de9
|
Added functions for both steps into lib - at first just in the index.js, since I'd argue its not complicated enough to warrant its own file. Updated the pen and retested including Firefox ESR (78.10.0esr) and works fine for all now. However, I can't really make sense out of the test failures, when trying it locally it seems all to work. |
Some tests are flaky. I re-run the CircleCI and they should pass. |
The bad character problem is really NOT related to your PR. So please do not worry about that. |
Regarding the other trace types:
I'll have a closer look at the parcats problem in Firefox ESR and the sliders in the coming days. |
|
On another note. It appears there are similar bugs related to plotly.js/src/plots/geo/zoom.js Line 135 in a5a5de9
(and if you search for d3.mouse ) which again could possibly be addressed using your fix around d3.mouse .
|
Unfortunately I'm already over-stretching the time I've allocated for this issue. So I'd appreciate to focus this PR on the geo hover, take on the parcats hover as best effort and record the problems with parcoords and/or sliders into new tickets to be tackled in the future. |
@LucaVazz thanks very much for the hard work and great contribution. |
…-choropleth-interactions-for-firefox
Thank you as well @archmoj for your great help :) I've merged master into the fix branch, hopefully its good to go now. |
@archmoj / @alexcjohnson Would this change by the way be a candidate for 2.0.0 or would it likely land in a following release? |
That's a bug we could fix either in 2.0.0 or 2.0.1. |
The failing tests are in
and using FireFox
both should pass. |
…-choropleth-interactions-for-firefox
…lotly#5607)" This reverts commit ff60f21.
@archmoj I've merged master and reverted the parcats change. |
@LucaVazz, OK thanks very much. |
@@ -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); |
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
…-choropleth-interactions-for-firefox
* @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 comment
The 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 comment
The 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 comment
The 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
or a ternary operator, but pulling the conditional out of the function and into the initial script evaluation, for better performance. I agree that ternaries can be confusing when used on such large expressions, but we can do something like:
if (isProblematicFirefox) {
lib.getPositionFromD3Event = function() {...}
} else {
lib.getPositionFromD3Event = function() {...}
}
LGTM. |
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.
💃 LGTM, with or without the one comment about inverting the function/conditional.
Thanks for the review @alexcjohnson and thanks again for all the help in getting it integrated properly @archmoj |
Related to #5525.
This PR fixes the hover interaction for geo plots (i.e. choropleth) in Firefox and extends the test suite for choropleths to also test for translate3d transforms.
Background:
d3.mouse
depends on thegetScreenCTM
function provided by the browser: https://github.com/plotly/d3/blob/v3.5.18/src/event/mouse.js#L27