-
Notifications
You must be signed in to change notification settings - Fork 29
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(lib-classifier): canvas context for SVG drawing tools #6491
base: master
Are you sure you want to change the base?
fix(lib-classifier): canvas context for SVG drawing tools #6491
Conversation
...mponents/Classifier/components/SubjectViewer/components/InteractionLayer/InteractionLayer.js
Outdated
Show resolved
Hide resolved
const svgContext = useContext(SVGContext) | ||
const canvasRef = useRef() | ||
svgContext.canvas = canvasRef.current |
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'm not 100% sure if this is the best way to update a reference within a context object, but it works in Chrome, Safari, and Firefox.
SVGContext.canvas
is a reference to the element that the draggable
decorator (and drawing tools in general) will use to calculate the screen CTM for pointer interactions (ie. to get SVG coordinates from pointer coordinates.)
...mponents/Classifier/components/SubjectViewer/components/InteractionLayer/InteractionLayer.js
Outdated
Show resolved
Hide resolved
@@ -68,7 +66,6 @@ function SingleImageViewer({ | |||
transform={transform} | |||
> | |||
<SVGImageCanvas | |||
ref={canvasLayer} |
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.
This ref was originally used for dragging interactions, which caused the Firefox bug.
6565c8d
to
e958109
Compare
22f3fae
to
79fea74
Compare
I think this has broken dragging/pan with the mouse (across browsers). In pan/zoom mode, when clicking then dragging the subject image, I get the following console error:
However, if I remove the changes to |
Oh, I think that might be because the draggable image is dragged in a different context to draggable drawing marks. Marks should get the CTM from the The fix here was for the drawn marks, so it probably would break the draggable image. |
I tried this quickly, but it breaks the drawing tools. Dragging the image also doesn't work as expected with the CTM that's used by the drawing tools. I'm not sure why the image and drawing tools are using different CTMs. I find that clicking and dragging a zoomed-in image, after drawing some marks, causes the image to jump around unexpectedly. I think you mentioned this bug, or a similar bug, on #6390. The transformation matrix for clicks on the image is generating the wrong x,y coordinates in SVG space. |
I'll push my changes up, since they're easy to revert and this branch is already broken anyway. |
0e7a945
to
960252c
Compare
Since pushing my latest commit, I'm not seeing those problems any more in Firefox, so maybe I've fixed the problem? It's still bothering me a bit that the image and drawn marks are using different transformation matrixes. It seems like both should have the same transformations applied to them. |
Thinking about this some more, EDIT: I tried this. It breaks the coordinate transformations for drag handles, which are rendered relative to the parent mark. Line 28 in 3e8f2ee
|
Make sure that `SVGContext.canvas` is a reference to the SVG `rect` element that's used as a drawing canvas, so that creating new drawing marks and editing existing marks both use the same screen CTM when calculating the pointer position. This fixes a bug in Firefox where the `draggable` decorator doesn't correctly track the active pointer, in the context of a zoomed SVG image.
960252c
to
5219203
Compare
Make sure that
SVGContext.canvas
is a reference to the SVGrect
element that's used as a drawing canvas, so that creating new drawing marks and editing existing marks both use the same screen CTM when calculating the pointer position in SVG space.This fixes a bug in Firefox where the
draggable
decorator doesn't correctly track the active pointer, in the context of a zoomed SVG image.Please request review from
@zooniverse/frontend
team or an individual member of that team.Package
Linked Issue and/or Talk Post
How to Review
On I Fancy Cats, you should be able to draw while zoomed in, without seeing any of the mismatched positioning described in #6490. You can try it out by drawing an ellipse while zoomed in, or by placing a point then dragging the point to a new position.
Try it out in Firefox and Chrome, while zoomed in and also after rotating the image. Pointer interactions should be correctly mapped to the SVG image now, regardless of any external transformation.
While drawing, in any browser, you should be able to pan and zoom with the keyboard too.
The stroke width of drawn marks should also stay the same as you zoom in. Lines shouldn’t be thicker at increased magnification.
Checklist
PR Creator - Please cater the checklist to fit the review needed for your code changes.
PR Reviewer - Use the checklist during your review. Each point should be checkmarked or discussed before PR approval.
General
yarn panic && yarn bootstrap
ordocker-compose up --build
and FEM works as expectedGeneral UX
Example Staging Project: i-fancy-cats
Bug Fix