-
-
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
bug: interactions misaligned when plot is inside transform: scale()-ed element #888
Comments
Ah. I guess you must be the first person to use plotly.js with CSS transforms. Thanks for reporting. |
I'm having the same issue. Any news on this? |
This is also preventing click events from firing properly |
Implementation notes from when I rediscovered this issue just now: If the page transforms the Seems from the comments here like the problems extend beyond just |
@alexcjohnson yes, moving between screens with a different
...hm this works on Chrome on FF but not (yet?) on Safari. So, polling might be safer atm. |
I'm having this problem too. My app requires zooming entire charts, and because of this bug I have to make duplicate enlarged versions of every chart, and swap them out every time the user zooms. Here is a codepen that demonstrates my use case. On a side note: notice that I'm implementing click-to-zoom using pure HTML+CSS. This is because I can't get a click event in the main plot area to work because of the transparent div overlays. Here are my semi-failed attempts at doing it in Javascript: |
The I am using Any idea how this could be fixed? |
I think this is the same problem I have with plotly plots embedded in reveal.js slides which get scaled to fit the window size. If reveal.js is forced to scale=1 then hover and mouse coordinates behave correctly, but this is not a solution because then slides do not fill the screen :) |
I faced the same issue with reveal.js. My workaround is to add a CSS transform which precisely undoes Reveal's scaling and then scale the plot with its width and height attributes. Something along the lines of
I added the EDIT: I just noticed this workaround doesn't seem to work in Chrome, only in Firefox. |
@alexcjohnson, how about putting the responsibility for detecting the transform on the user? Maybe the |
FYI Plottable's fixed this here: https://github.com/palantir/plottable/blob/b6e36fbd4d8d7cba579d853b9f35cc260d1243bf/src/utils/mathUtils.ts#L173 . The gist is to walk up the DOM tree and account for the |
Another report from #4343 Due to a specific requirement of fitting multiple charts which are added dynamically and arranged horizontally in available viewport without scroll I am using transform scale for example transform: translateZ(0) scale(0.50, 0.50) on charts based on available space, although the whole chart is scaled down uniformly but when mouse hover over is done on chart I observe there is offset between mouse location and hover popup location shown in attached screen shot Using resize() or relayout does not give crisp chats when they are scale down due to uneven transform of chart and labels. I have created code pen to explain issue |
This issue has been tagged with A community PR for this feature would certainly be welcome, but our experience is deeper features like this are difficult to complete without the Plotly maintainers leading the effort. Sponsorship range: $10k-$15k What Sponsorship includes:
Please include the link to this issue when contacting us to discuss. |
I have a fix working for the hover aspect of this bug. It is similar to Palantir's plottable fix mentioned above, in that it traverses the DOM ancestors of the event target element to produce a transform matrix, then applies the inverse of that to a point. However, there are multiple mouse interactions affected by this issue (such as clicking and dragging, hover, and probably others I can't think of or don't know about), and the fix applied to the hover case is a bit specific. To be precise - it transforms xpx and ypx in the components/fx/hover.js _hover() call thus:
I would like guidance on what a fix PR for this should look like - is it going to have to be a fix for every interaction in the same vein as the hover code above, or is there a more general way of doing things, e.g. transforming further up the chain? I've tried doing that, with little success - I think my lack of knowledge of the codebase is limiting me. |
Another workaround solution for this problem is to change main charting library from Plotly to mpld3. Of course, is not ideal and depends highly on your use case, but solves the initial problem ;). You can find more info on the issue, as well as some example code in my sample repository. |
#5193 with some adjustments is getting close to address this issue. |
This issue was tagged as "needs sponsorship" and was instead resolved by the contribution of an excellent pull request for this long-standing issue. Thank you so much for taking the initiative on this @alexhartstone! |
Misalignment is happening for me in Chrome 92.0.4515.159 (Plotly.py 5.2.2, Jupyter Lab 3.0.16) but not in Firefox 91.0.2. Found the same behavior in both OSX and Linux, i.e., works in FF but not Chrome-based browsers. Slides were created with I also saw the misalignment in tooltips in plots created by altair and mpld3. |
This is still happening for me with Chrome. Working correctly in Firefox. |
This is still happening on Chrome and Microsoft Edge. Unfortunately, I can't install FireFox on my computer. Your help fixing this bug or at least providing a workaround would be greatly appreciated. |
This is also unfortunately still happening for me too on Chrome. It does work as expected on Firefox, across a wide range of wondow sizes. |
See http://codepen.io/hellochar/pen/JKgXPE and mouse around.
Looks like plotly.js miscalculates where the mouse is positioned if the plot itself is rendered inside an element with a
transform: scale()
CSS property set. The tooltips don't match up with where the mouse is. This is most apparent when you try to click+drag an area of the plot and it clearly shows the locations don't match up.The buttons in the toolbar line up correctly, as does the hitbox for dragging the axes or enabling/disabling specific traces.
Also it looks like if you're at the top-left corner of the plot, the mouse position is accurate (that is, the (0, 0) origin point is handled correctly; only the scaling factor is off).
Also see palantir/plottable#1644 which looks to be the same issue in Plottable.
Let me know if that makes sense and if there's something else I can do!
The text was updated successfully, but these errors were encountered: