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: wheel zoom normalization #5165

Merged
merged 5 commits into from May 11, 2022

Conversation

johtso
Copy link
Contributor

@johtso johtso commented May 9, 2022

Playing around with the wheel zoom normalization to try and get it to behave nicely on trackpads.

It seems the go-to logic for getting some kinds of normalization between different browsers / devices is some hand-me-down facebook code. https://github.com/basilfx/normalize-wheel

I've tried this in firefox and chrome with both a mouse wheel and trackpad, and it seems to behave fine.

The only thing that could be slightly better is the velocity when very zoomed in, currently it moves at bit fast. Would just be a question of tweaking the maths a little..

https://www.loom.com/share/dff08cfe53d04719bcf7da624b4d6149

Fixes #4385

I think the normalize-wheel repo is just a copy of what's on npm with types added? In that case it might be better to use the NPM version and just add the types locally?

@vercel
Copy link

vercel bot commented May 9, 2022

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Updated
excalidraw ✅ Ready (Inspect) Visit Preview May 11, 2022 at 7:40PM (UTC)
excalidraw-package-example ✅ Ready (Inspect) Visit Preview May 11, 2022 at 7:40PM (UTC)

@johtso
Copy link
Contributor Author

johtso commented May 9, 2022

From playing around a little more, I actually think that if anything, me may actually want to reduce the zoom amount when very zoomed out.

@dwelle
Copy link
Member

dwelle commented May 9, 2022

From playing around a little more, I actually think that if anything, me may actually want to reduce the zoom amount when very zoomed out.

are we talking about trackapad or in general?

@dwelle
Copy link
Member

dwelle commented May 9, 2022

are we talking about trackapad or in general?

Ok, playing with it, it's definitely wild. On macbook trackpad, it's high, but manageable — but we should still lower it across all levels of zoom, not just when zoomed out.

But mouse wheel is not not very usable after the change — previously zooming with mouse wheel was very solid, so I'd try to match the same.

@johtso
Copy link
Contributor Author

johtso commented May 11, 2022

After taking another look, I think the whole "normalization" thing was a bit of a red herring. The real issue was that we were rounding every zoom change to the nearest "zoom step", and because trackpads produce lots of tiny wheel events, they never hit the next zoom step until you are swiping way too fast.

Removing that rounding, things are a fair bit better.

The speed of zooming is still way too fast when over 100%, but I'm not sure how to improve that without affecting the mechanical scroll wheel behaviour which is okay at the moment. I don't know of any way to distinguish between a mechanical scroll wheel and a trackpad. Possibly we could do something as simple as changing behaviour if the delta is over a certain amount..

@johtso
Copy link
Contributor Author

johtso commented May 11, 2022

With the "reduced amplification for small deltas" tweak things are working quite nicely!

Comment on lines 5660 to 5665
// reduced amplification for small deltas (small movements on a trackpad)
const smallDeltaAdjustment = Math.min(1, absDelta / 20);
newZoom +=
Math.log10(Math.max(1, this.state.zoom.value)) *
-sign *
smallDeltaAdjustment;
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
// reduced amplification for small deltas (small movements on a trackpad)
const smallDeltaAdjustment = Math.min(1, absDelta / 20);
newZoom +=
Math.log10(Math.max(1, this.state.zoom.value)) *
-sign *
smallDeltaAdjustment;
newZoom +=
Math.log10(Math.max(1, this.state.zoom.value)) *
-sign *
// reduced amplification for small deltas (small movements on a trackpad)
Math.min(1, absDelta / 20)

I think it's better to inline this.

Btw, doesn't that expression amplifies (clamped to 1) instead of reducing the amplification?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's going to result in multiplying by a number between 0 and 1, so it will reduce the amplification.

Copy link
Member

Choose a reason for hiding this comment

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

nvm. Even though I myself said we're clamping to 1, my mind was for some reason in >1 numbers :).

Co-authored-by: David Luzar <luzar.david@gmail.com>
Copy link
Member

@dwelle dwelle left a comment

Choose a reason for hiding this comment

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

alright, awesome work! :)

@dwelle dwelle merged commit 33bb23d into excalidraw:master May 11, 2022
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.

Pinch-to-zoom is unresponsive and jumps between zoom levels
2 participants