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

SVGs Not Scaling Correctly #584

Closed
kitschpatrol opened this issue Nov 14, 2023 · 4 comments
Closed

SVGs Not Scaling Correctly #584

kitschpatrol opened this issue Nov 14, 2023 · 4 comments
Labels

Comments

@kitschpatrol
Copy link
Contributor

kitschpatrol commented Nov 14, 2023

Hi,

Thank you for Tweakpane.

I have a use-case where the entire Tweakpane gets scaled up with a CSS transform, e.g. a transform: scale(2.0); on a div containing the Pane.

This works really well in general since Tweakpane is all vectors, but I did notice an issue with SVG graphics like those found in the graph monitor and the FPS graph plugin. Basically, the SVG seems to get scaled twice, and then is partially clipped from view.

Tweakpane Scale Issue

I dug around a bit and it seems like this is a result of calling getBoundingClientRect() when calculating the graph's layout, which changes as a result of the scale transformation on the parent.

I have a branch here which seems to fix the issue by using the view element's .clientWidth and .clientHeight instead, which reflects the unscaled values:

Tweakpane Scale Issue Fix

I'm happy to submit this as a PR if you agree with the approach, but I'm not sure if there are unintended side-effects I haven't considered. I also noticed that getBoundingClientRect() is used in pointer-handler.ts, but haven't encountered issues with it. (I think in some cases of user input coming from the root window coordinates, you do want the scaled dimensions.)

I think Cubic Bezier from the Essentials Plugin would need the same fix as well.

I also experimented with setting the viewBox on the SVG. This approach fixes the scaling, but has the disadvantage of not scaling up the line weights.

@kitschpatrol
Copy link
Contributor Author

kitschpatrol commented Nov 15, 2023

@cocopon
Copy link
Owner

cocopon commented Nov 15, 2023

Thank you for reporting the issue. You got a point and the proposed fix looks good to me. Creating a PR would be appreciated.

PointerHandler works fine because the scale of transform affects both x/y and width/height, and the relative value doesn't change as a result.

@kitschpatrol
Copy link
Contributor Author

Great thank you. I've opened PRs on both Tweakpane and the Plugin Essentials repo with the fix.

@cocopon
Copy link
Owner

cocopon commented Dec 15, 2023

Released in 4.0.2, thank you for your contribution! (and I'll do merge your PR with plugin-essentials later)

@cocopon cocopon closed this as completed Dec 15, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants