-
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
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.
8525270
to
22f3fae
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