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

align monospaceWidth with defaultWidth? #1879

Closed
Fil opened this issue Sep 28, 2023 · 0 comments · Fixed by #1880
Closed

align monospaceWidth with defaultWidth? #1879

Fil opened this issue Sep 28, 2023 · 0 comments · Fixed by #1880
Labels
enhancement New feature or request question Further information is needed

Comments

@Fil
Copy link
Contributor

Fil commented Sep 28, 2023

Our estimates for string lengths (default or monospace) are in an arbitrary unit, with a meaning close to “% of font size".

If we measure the actual width of a string rendered as MONOSPACE text (say with a font-size of 11px), we get a (constant) width of ~6.6 pixels per character. This is estimated by monospaceWidth to a value of 100. The ratio between a string's estimated width in arbitrary unit and measured width in pixels is then equal to 100/6.6 = 15.15.

For strings rendered as DEFAULT text, the ratio has a bit more variability, but it oscillates between 9.2 and 10.2, so around 9.6. This means that we can't compare the (estimated) widths of monospace with default text.

A more systematic approach would be to adjust the default value of 100 to something like 63, so that the two estimates match. This would be a slightly breaking change, but it would feel more consistent going forward. (We could then use monospaceWidth as is in #1722, instead of having to rescale it.)

https://observablehq.com/@observablehq/monospacewidth-vs-defaultwidth

@Fil Fil added enhancement New feature or request question Further information is needed labels Sep 28, 2023
Fil added a commit that referenced this issue Sep 28, 2023
@Fil Fil closed this as completed in #1880 Oct 12, 2023
Fil added a commit that referenced this issue Oct 12, 2023
chaichontat pushed a commit to chaichontat/plot that referenced this issue Jan 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request question Further information is needed
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant