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

Split long strings without spaces #353

Closed
MLopez-Ibanez opened this issue Jun 6, 2022 · 2 comments
Closed

Split long strings without spaces #353

MLopez-Ibanez opened this issue Jun 6, 2022 · 2 comments

Comments

@MLopez-Ibanez
Copy link

MLopez-Ibanez commented Jun 6, 2022

Currently, label_wrap() only splits a string if there are spaces, however, there is no way (as far as I can tell) to force wrapping even if there is no space to ensure we do not overflow the specified width.

Example:

label_wrap(10)("Incomprehensibility")

should produce "Incomprehe\nnsibility".

@MLopez-Ibanez
Copy link
Author

Other interesting variants could be:

label_wrap(10, camel_case=TRUE)("defaultOptionA")

which splits (if needed) at "(?<=[[:lower:]])(?=[[:upper:]])" thus, "default\nOptionA".

and specify allowed split characters:

label_wrap(10, split="[[:space:]_]")("default_option_a")

will produce "default\noption_a".

Note that all the above can work together in a well-defined way:

label_wrap(10, force=TRUE, split="[[:space:]_]", camel_case=TRUE)("defaultOptionA_allowed_wheneverpossible")

would produce "default\nOptionA\nallowed\nwheneverpo\nssible"

@thomasp85
Copy link
Member

This is outside the scope of scales as word wrapping is it's own horrible beast safe for very simple cases such as what scales provide. ggtext/gridtext offers a much richer word-wrapping featureset

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

No branches or pull requests

2 participants