Skip to content

Support multi-line text labels by splitting on newlines#301

Merged
thomasp85 merged 3 commits intoposit-dev:mainfrom
teunbrand:multiline_text
Apr 13, 2026
Merged

Support multi-line text labels by splitting on newlines#301
thomasp85 merged 3 commits intoposit-dev:mainfrom
teunbrand:multiline_text

Conversation

@teunbrand
Copy link
Copy Markdown
Collaborator

@teunbrand teunbrand commented Apr 13, 2026

This PR fixes an issue discussed with Thomas off-Github.

Essentially vegalite doesn't process newlines as new lines, but accepts an array of strings instead.
We now split our labels text with newlines into arrays of strings.

teunbrand and others added 2 commits April 13, 2026 12:30
TextRenderer now detects newlines in label values and converts them to
arrays of strings for Vega-Lite rendering. Handles both actual newline
characters (from database columns, CHAR(10), imported data) and literal
\n from SQL string literals.

Uses platform-agnostic .lines() method to handle \n, \r\n, and \r.
Single-line labels remain unchanged.

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
@thomasp85
Copy link
Copy Markdown
Collaborator

We also need to do this for titles etc

Extended newline splitting from text geom labels to all label types:
- Chart titles and subtitles
- Axis labels (x, y, and all position aesthetics)
- Legend titles (color, stroke, and all non-position aesthetics)

Created shared split_label_on_newlines() function used by:
1. Chart title/subtitle rendering (mod.rs)
2. Axis label rendering (encoding.rs)
3. Legend title rendering (encoding.rs)
4. Text geom label data (layer.rs TextRenderer)

This ensures consistent newline handling across all label contexts.
Users can now use \n in any LABEL clause for multi-line text.

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Copy link
Copy Markdown
Collaborator

@thomasp85 thomasp85 left a comment

Choose a reason for hiding this comment

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

LGTM

@thomasp85 thomasp85 merged commit 37633f0 into posit-dev:main Apr 13, 2026
15 checks passed
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.

2 participants