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

Sequence Diagrams with messageAlign smash text with <br> #3011

Closed
kevinawoo opened this issue May 6, 2022 · 6 comments · Fixed by #3194
Closed

Sequence Diagrams with messageAlign smash text with <br> #3011

kevinawoo opened this issue May 6, 2022 · 6 comments · Fixed by #3194
Labels
Status: Triage Needs to be verified, categorized, etc Type: Bug / Error Something isn't working or is incorrect

Comments

@kevinawoo
Copy link

kevinawoo commented May 6, 2022

Describe the bug
When create a sequence diagram with messageAlign: left config and the text contains <br> line breaks, all the lines gets smashed into the first line.

To Reproduce
Steps to reproduce the behavior:

  1. Set the config to { "sequence": { "messageAlign": "left"} }
  2. Create a sequence diagram using <br> in the message

Expected behavior
The diagram to have left aligned text with line breaks, as in #1315
image

Screenshots
image

You can see in the screenshot everything is smashed into the first line.

Code Sample
Live Editor example

```mermaid
%%{init: { 'sequence': {'messageAlign': 'left'} }}%%
sequenceDiagram
User->>Browser: Click hello
Browser->>Server: Get /hello HTTP/1.1 <br> Host: example.com <br> Accept: text/html
Server->>Browser: HTTP/1.1/ 200 OK <br> Content-Type: text/html <br> Content-Length: 42
```

Github Render:

%%{init: { 'sequence': {'messageAlign': 'left'} }}%%
sequenceDiagram
User->>Browser: Click hello
Browser->>Server: Get /hello HTTP/1.1 <br> Host: example.com <br> Accept: text/html
Server->>Browser: HTTP/1.1/ 200 OK <br> Content-Type: text/html <br> Content-Length: 42

Desktop (please complete the following information):

  • OS: macOS 12.3.1
  • Browser: Chrome
  • Version: 101.0.4951.54
@kevinawoo kevinawoo added Status: Triage Needs to be verified, categorized, etc Type: Bug / Error Something isn't working or is incorrect labels May 6, 2022
hype09 added a commit to hype09/mermaid that referenced this issue Jul 3, 2022
… 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.
@knsv knsv closed this as completed in ed29fe1 Aug 4, 2022
@kevinawoo
Copy link
Author

@PackElend I found it from https://github.com/mermaid-js/mermaid/blob/37eb0454fd2698b5bf6083bc6c75b179761a2b7a/src/docs/Setup.md#messagealign

as well as going through the source

messageAlign?: string;

@PackElend
Copy link

https://github.com/mermaid-js/mermaid/blob/37eb0454fd2698b5bf6083bc6c75b179761a2b7a/src/docs/Setup.md#messagealign
that is very well hidden :)

I asked to update the docs: #3500

by the way, what does your alignment looks like?
Should it only be aligned on the arrow itself?
image

@kevinawoo
Copy link
Author

You're right, it does look a little weird.

Seems like messageAlign moved the message left, center, or right of the connection line.

Maybe we should open a new issue to maybe introduce messageAlign: centerLeft?

@PackElend
Copy link

PackElend commented Sep 21, 2022 via email

@PackElend
Copy link

eventually it is done #3594

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Status: Triage Needs to be verified, categorized, etc Type: Bug / Error Something isn't working or is incorrect
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants