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

refactor(drawing-tools): drag handle sizing #6685

Merged
merged 2 commits into from
Feb 13, 2025

Conversation

eatyourgreens
Copy link
Contributor

@eatyourgreens eatyourgreens commented Feb 13, 2025

  • Remove defaultProps from functional components.
  • Refactor transcription lines to use translation and scale transforms for the line handles.
  • Style drag handles and point marks with non-scaling-size.
  • Fixes a small issue, introduced by refactor(classifier): use native browser SVG scaling for drawing tools #6066, where drag handles aren't rendered in the correct proportion with respect to marks.

Here are screenshots of the sizing issue:

Main branch (drag handles are too small):
A green rectangle drawn on top of a small subject image. The drag handles at the corners of the rectangle are too small, not much bigger than the line stroke width.

This branch (drag handles are correctly proportioned):
A green rectangle drawn on top of a small subject image. The drag handles at the corners of the rectangle are correctly proportioned with respect to the line stroke width.

Test cases in the dev classifier:

Please request review from @zooniverse/frontend team or an individual member of that team.

Package

lib-classifier

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

Refactoring

  • The PR creator has described the reason for refactoring
  • The refactored component(s) continue to work as expected

@eatyourgreens eatyourgreens force-pushed the drag-handle-sizing branch 6 times, most recently from 86c3933 to 5e8a416 Compare February 13, 2025 14:51

const StyledCircle = styled('circle')`
stroke-width: 2;
&:hover {
cursor: move;
}
`
const RADIUS = screen.width > 900 ? 4 : 10
const RADIUS = screen.width > 900 ? 3 * STROKE_WIDTH : 5 * STROKE_WIDTH
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I thought it would be safer to make the drag handle size a multiple of the base stroke width here. If the stroke width changes, the default handle size will change proportionately.

Copy link
Contributor

Choose a reason for hiding this comment

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

Nice! I thought maybe it should be 2 * STROKE_WIDTH for the first condition (to match the previous calculation), but I think 3 is the right amount after reviewing visually.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, 4px seems a bit small to me, so I bumped it to 6.

@mcbouslog mcbouslog self-assigned this Feb 13, 2025
@mcbouslog mcbouslog self-requested a review February 13, 2025 15:52
Copy link
Contributor

@mcbouslog mcbouslog left a comment

Choose a reason for hiding this comment

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

This looks good, thank you @eatyourgreens !

Tested locally on projects linked and additional staging project with drawing tools.
Per your suggestion I had been trying non-scaling-size, but was missing the related transform that makes it work.


const StyledCircle = styled('circle')`
stroke-width: 2;
&:hover {
cursor: move;
}
`
const RADIUS = screen.width > 900 ? 4 : 10
const RADIUS = screen.width > 900 ? 3 * STROKE_WIDTH : 5 * STROKE_WIDTH
Copy link
Contributor

Choose a reason for hiding this comment

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

Nice! I thought maybe it should be 2 * STROKE_WIDTH for the first condition (to match the previous calculation), but I think 3 is the right amount after reviewing visually.

- Remove `defaultProps` from functional components.
- Refactor transcription lines to use translation and scale transforms for the line handles.
- Style drag handles and point marks with `non-scaling-size`.
- Fixes a small issue where drag handles aren't rendered in the correct proportion with respect to marks.

return (
<g onPointerUp={active ? onFinish : undefined}>
<g transform={`scale(${1 / scale})`} onPointerUp={active ? onFinish : undefined}>
Copy link
Contributor Author

Choose a reason for hiding this comment

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

The SVG spec says that non-scaling-size ignores scale transforms, but points render much too large without scaling them down here. Could be a case of browsers not implementing the SVG spec, I'm not sure.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

These scale transforms may not be needed once the SVG zoom is handled with scale transforms, rather than cropping the viewbox.

@eatyourgreens
Copy link
Contributor Author

By the way, CI is failing because coveralls.io had a major outage yesterday and they're still recovering. https://status.coveralls.io/ says use this workaround to avoid blocking CI pipelines:

fail-on-error: false if using Coveralls GitHub Action.

@eatyourgreens
Copy link
Contributor Author

eatyourgreens commented Feb 13, 2025

Per your suggestion I had been trying non-scaling-size, but was missing the related transform that makes it work.

The spec says that non-scaling-size ignores any scaling transforms applied from the element's parent, so I'm confused that I had to scale circles down to the correct radius for a given image size.

EDIT: according to the first comment here, only non-scaling-stroke has been implemented in browsers. 🙄
https://stackoverflow.com/questions/77930441/difficulties-with-understanding-the-svg-specs-description-of-the-vector-effect

@mcbouslog mcbouslog merged commit 031f718 into zooniverse:master Feb 13, 2025
7 checks passed
@eatyourgreens eatyourgreens deleted the drag-handle-sizing branch February 13, 2025 17:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants