Skip to content
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(classifier): smooth image dragging for pan/zoom #6065

Open
wants to merge 7 commits into
base: master
Choose a base branch
from

Conversation

eatyourgreens
Copy link
Contributor

@eatyourgreens eatyourgreens commented Apr 27, 2024

  • Refactor SVGPanZoom to use a ref for zoom, rather than component state. Hopefully, this will lead to fewer rerenders when dragging a zoomed image, and smoother performance.
  • Use a ref to store pointer coordinates in the draggable decorator, to avoid unnecessary rerenders.
  • Move the cropped SVG viewbox into a nested SVG, for better performance when dragging a zoomed image.
  • Remove the 1.5 easing factor on dragged images, so that they 'stick' to the pointer when dragged.
  • Use focus-visible so that focus rings are only shown for keyboard interactions.
  • refactor the useKeyZoom hook to support rotated images.

Screen recordings from Firefox 125 running on an M3 MacBook (Sonoma 14.4.1.)

Pan and zoom with a trackpad:

Screen.Recording.2024-04-30.at.09.35.20.mov

Pan and zoom with a trackpad at a very high zoom level:

Screen.Recording.2024-04-30.at.10.18.27.mov

Keyboard focus with Tab and shift-Tab:

Screen.Recording.2024-04-30.at.09.43.05.mov

Package

  • lib-classifier

Linked Issue and/or Talk Post

How to Review

Zoom and pan an image in the dev classifier, using both the keyboard and a trackpad/mouse to pan the zoomed image.

You can test the focus styling by tabbing through the page, to check that drawn marks have focus styling when focused (WCAG Success Criterion 2.4.7: focus visible.) When a mark has keyboard focus, Enter will open any associated subtask popup, which should also be fully keyboard accessible. Backspace will delete the focused mark (WCAG Success Criterion 2.1.1: Keyboard.)

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

  • Tests are passing locally and on Github
  • Documentation is up to date and changelog has been updated if appropriate
  • You can yarn panic && yarn bootstrap or docker-compose up --build and FEM works as expected
  • FEM works in all major desktop browsers: Firefox, Chrome, Edge, Safari (Use Browserstack account as needed)
  • FEM works in a mobile browser

General UX

Example Staging Project: i-fancy-cats

  • All pages of a FEM project load: Home Page, Classify Page, and About Pages
  • Can submit a classification
  • Can sign-in and sign-out
  • The component is accessible

Bug Fix

  • The PR creator has listed user actions to use when testing if bug is fixed
  • The bug is fixed
  • Unit tests are added or updated

@eatyourgreens
Copy link
Contributor Author

eatyourgreens commented Apr 27, 2024

NB. I'm testing this (and recording the screen video) on a very-much overpowered M3 MacBook Pro. It'd be useful to get tests from machines that are more in line with what typical volunteers use. I might be seeing smooth dragging movement simply because I'm using a fast machine.

@coveralls
Copy link

coveralls commented Apr 27, 2024

Coverage Status

coverage: 79.293% (-0.03%) from 79.323%
when pulling 665d5b0 on eatyourgreens:refactor-pan-zoom
into 9a7a630 on zooniverse:master.

@eatyourgreens eatyourgreens force-pushed the refactor-pan-zoom branch 3 times, most recently from 1aef573 to 7614043 Compare April 29, 2024 16:02
@eatyourgreens eatyourgreens changed the title fix: smoother image dragging for pan/zoom refactor: smoother image dragging for pan/zoom Apr 29, 2024
@eatyourgreens eatyourgreens changed the title refactor: smoother image dragging for pan/zoom fix: smooth image dragging for pan/zoom Apr 30, 2024
@eatyourgreens eatyourgreens force-pushed the refactor-pan-zoom branch 2 times, most recently from 0fdf304 to 7c42250 Compare April 30, 2024 09:02
Comment on lines 68 to 82
<svg
ref={canvasLayer}
viewBox={viewBox}
>
{children}
{enableInteractionLayer && (
<InteractionLayer
frame={frame}
height={height}
scale={scale}
subject={subject}
width={width}
/>
)}
</svg>
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This nested SVG fixes #2273, #5110, and #6067.

@eatyourgreens
Copy link
Contributor Author

eatyourgreens commented Apr 30, 2024

Noting that the image is cropped if you try to drag it outside a rotated view box, even though there’s visibly available space in the browser viewport. I’m not sure if that would be a blocker.

To reproduce that, rotate an image by 90° or 270°, then drag it left or right. The width of the rotated view box (the actual height of the image) is narrower than the width of the subject viewer.

EDIT: fixed by styling the nested <svg> with overflow: visible.

@eatyourgreens eatyourgreens force-pushed the refactor-pan-zoom branch 2 times, most recently from d014044 to 1aed5f9 Compare May 1, 2024 13:24
@eatyourgreens
Copy link
Contributor Author

Here's a screen recording from Chrome 124, also running on an M3 MacBook.

Screen.Recording.2024-05-02.at.17.24.35.mov

@eatyourgreens eatyourgreens force-pushed the refactor-pan-zoom branch 5 times, most recently from 3d70251 to 3febd39 Compare May 8, 2024 14:00
@eatyourgreens eatyourgreens changed the title fix: smooth image dragging for pan/zoom fix(classifier): smooth image dragging for pan/zoom May 19, 2024
- Refactor `SVGPanZoom` to use a ref for `zoom`, rather than component state. Hopefully, this will lead to fewer rerenders when dragging a zoomed image, and smoother performance.
- Use a ref to store pointer coordinates in the `draggable` decorator, to avoid unnecessary rerenders.
- Move the cropped SVG viewbox into a nested SVG, for better performance when dragging a zoomed image.
- Remove the `1.5` easing factor on dragged images, so that they 'stick' to the pointer when dragged.
- Use `focus-visible` so that focus rings are only shown for keyboard interactions.
- remove unused variables.
- use a ref to remember the current pointerId across renders.
- clean up pointer capture.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants