-
Notifications
You must be signed in to change notification settings - Fork 184
text wrap (lineWidth) #699
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
Conversation
|
I think this requires a little prognostication. Here are some possible futures:
In future 1, we’d want In future 2, we’d want In future 3, we’d want So if we think there’s a reasonably high probability that we want I think em is probably preferred to px, given that Plot is mostly about positioning in abstract coordinates anyway (scaled data space). I vote we do nothing.
Yes. I think for due diligence it’s probably also worth benchmarking what the performance would be like if we measured the text with canvas rather than using a hard-coded character width map. That would also make it possible to support lineWidth in px, though as I implied above I don’t think that’s a priority.
You can use
This seems conflicting with your previous input… I think I would only do these together or not at all, similar to CSS white-space, i.e.,
Yes, this is already supported. You can type option-space for a non-breaking space, or use |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TIL about %-e
Thanks for the detailed explanations—it's really neat!
I did some exploration using context.measureText, which would allow several things:
However, it was also about 10× slower than the current approach, and added some complexity (such as needing to create an invisible canvas element and attaching it to the DOM; you can’t set font-variant-numeric via the context.font attribute). So, I’m inclined to just keep it simple to start and revisit this in the future according to demand. |
yes. I was thinking that in node we don't have canvas as a dependency (only as devDependency) |
I fixed the definition of em. In CSS, 1em is not the width of a capital M, but instead an alias for the current fontSize. I had computed the default width map using 100px ui-system, but the layout is different at 10px ui-system (presumably because of hinting to align with pixel boundaries)? So, I recomputed the default width map at 10px ui-system, and then multiplied by 10 to avoid to produce integers. This will make the default metrics less accurate at larger font sizes, but I assume that most of the time text will be rendered with the default font size, and so we should prioritize that. I’ve also implemented the monospace option. I’ll add a test or two and then merge. |
Would the |
Implements text wrapping using a lineWidth option on the text mark. Fixes #688. Tasks:
Allow lineWidth to be specified in pixels? (But how?)No.Optionally ignore newlines in input?No.Optionally coalesce multiple spaces in input?No.Support tabular numerals?No.Measure text metrics dynamically with Canvas, if fast enough?No.Allow custom implementations for text metrics?No.Implement Unicode line breaking algorithm.No, too hard.Implement Unicode grapheme cluster breaking algorithm.No, too hard.Implement Knuth–Plass line breaking algorithm.No, too hard.Even though this is very rudimentary, I think it will be super useful and can be improved in the future based on usage.
I think the biggest blocker is just whether it’s okay to have lineWidth in ems. That’s the easiest thing for us to implement based on the baked-in rudimentary text metrics, but I think people are likely to get confused because they are more likely to be thinking in pixels. The problem with pixels is that the fontSize isn’t necessarily in pixels, either #378 and so we’d almost certainly need to invoke the browser’s full text metrics in order to compute it. And that also means an element will need to be attached to the DOM, and it’s slow, etc. So, I think maybe lineWidth in ems is the best option under the “worse is better” philosophy. We could also expose a hook for computing text metrics yourself, but that feels super low-level, and also not necessary since you could just specify text with newlines if you want to do the wrapping yourself.