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

Fix #3011: Support left- and right-alignment for multi-line messages and notes #3194

Merged
merged 1 commit into from Aug 4, 2022

Conversation

hype09
Copy link
Contributor

@hype09 hype09 commented Jul 3, 2022

📑 Summary

Previously, messages and notes that had multiple lines (via <br>-tags) were only displayed correctly
when using the default center value for the messageAlign and noteAlign configuration options.
Using left or right for the alignment options caused the text to collapse and become illegible,
as outlined in issue #3011.

Now, texts in messages and notes are always vertically centered and alignment options correctly apply for
both single and multi-line content.

Resolves #3011

📏 Design Decisions

This comes as a side-effect from how the internal valign text-rendering option was configured for
messages and notes:

// Example from `sequenceRenderer.js: drawMessage()`
textObj.anchor = conf.messageAlign;
textObj.valign = conf.messageAlign;

Both the anchor option (which controls left-right alignment) and the valign option (which controls
vertical top-down placement) were set to the same value, the user-provided messageAlign config option.

While left and right are valid values for the anchor option, they were effectively no-ops for the
valign option, which only supports top, start, middle, center, bottom, and end.

To fix the issue, the valign property is now always set to center for notes and messages.
Similarly, the dominantBaseline option of texts is now always set to middle, rather than setting it to
either text-{before,after}-edge, which caused left-aligned multi-line text to always be "top-left" aligned
inside a note (or "bottom-right" when attempting to right-align).

📋 Tasks

Make sure you

  • 📖 have read the contribution guidelines
  • 💻 have added unit/e2e tests (if appropriate)
  • 🔖 targeted develop branch

… messages and notes

Previously, messages and notes that had multiple lines (via `<br>`-tags) were only displayed correctly
when using the default `center` value for the `messageAlign` and `noteAlign` configuration options.
Using `left` or `right` for the alignment options caused the text to collapse and become illegible,
as outlined in issue mermaid-js#3011.

This comes as a side-effect from how the internal `valign` text-rendering option was configured for
messages and notes:

```js
// Example from `sequenceRenderer.js: drawMessage()`
textObj.anchor = conf.messageAlign;
textObj.valign = conf.messageAlign;
```

Both the `anchor` option (which controls left-right alignment) and the `valign` option (which controls
vertical top-down placement) were set to the same value, the user-provided `messageAlign` config option.

While `left` and `right` are valid values for the `anchor` option, they were effectively no-ops for the
`valign` option, which only supports `top`, `start`, `middle`, `center`, `bottom`, and `end`.

To fix the issue, the `valign` property is now always set to `center` for notes and messages.
Similarly, the `dominantBaseline` option of texts is now always set to `middle`, rather than setting it to
either `text-{before,after}-edge`, which caused left-aligned multi-line text to always be "top-left" aligned
inside a note (or "bottom-right" when attempting to right-align).

Now, texts in messages and notes are always vertically centered and alignment options correctly apply for
both single and multi-line content.
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.

Sequence Diagrams with messageAlign smash text with <br>
2 participants