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

Text cut off in Mermaid #1345

Open
jeppevinkel opened this issue Oct 13, 2022 · 13 comments
Open

Text cut off in Mermaid #1345

jeppevinkel opened this issue Oct 13, 2022 · 13 comments
Labels
🐞 bug Something isn't working 🙃 upstream

Comments

@jeppevinkel
Copy link

Large Mermaid diagrams have parts that get cut off when generated as SVG.

This example diagram from Mermaid causes issues

classDiagram
Class01 <|-- AveryLongClass : Cool
Class03 *-- Class04
Class05 o-- Class06
Class07 .. Class08
Class09 --> C2 : Where am i?
Class09 --* C3
Class09 --|> Class07
Class07 : equals()
Class07 : Object[] elementData
Class01 : size()
Class01 : int chimp
Class01 : int gorilla
Class08 <--> C2: Cool label
classDiagram
Class01 <|-- AveryLongClass : Cool
Class03 *-- Class04
Class05 o-- Class06
Class07 .. Class08
Class09 --> C2 : Where am i?
Class09 --* C3
Class09 --|> Class07
Class07 : equals()
Class07 : Object[] elementData
Class01 : size()
Class01 : int chimp
Class01 : int gorilla
Class08 <--> C2: Cool label
Loading
@ggrossetie
Copy link
Member

I believe this is a font issue, here's how it looks like with Kroki:

image

@ggrossetie ggrossetie changed the title Larve Mermaid SVG cut off Text cut off in Mermaid Oct 15, 2022
@ggrossetie ggrossetie added the 🐞 bug Something isn't working label Oct 15, 2022
@ggrossetie
Copy link
Member

By default, Mermaid is using the following font: "trebuchet ms",verdana,arial,sans-serif.

@ggrossetie
Copy link
Member

ggrossetie commented Oct 15, 2022

Probably related to mermaid-js/mermaid#1540
It might be better to use "Noto" by default. My guess is that "trebuchet ms",verdana,arial,sans-serif will render (very) differently on Linux, macOS and Windows.

@ggrossetie
Copy link
Member

For reference, here's how the font looks on the container:

As you can see, the font rendering is different and text is not cut off.
Not sure if there's a solution since as far as I know all fonts render differently depending on the OS. One idea would be to use something like https://github.com/vercel/satori to convert the (HTML) text to SVG (i.e., <path>)

@ggrossetie
Copy link
Member

Mermaid could use something like https://github.com/danmarshall/google-font-to-svg-path which relies on https://maker.js.org/ to convert all text to SVG path that would be neat!

@ggrossetie
Copy link
Member

I did some tests and unfortunately each solution has drawbacks.
I also feel like this "issue" should be fix upstream. I had decent results using https://github.com/shrhdk/text-to-svg with Noto Sans.

@codingluke
Copy link

I encountered this too! Would be great to have it fixed :) on mermaid.live and here on github it works correct. Anyway great tool!

@yuriykuzin
Copy link

I also have this issue with pie chart diagrams, while it's ok on mermaid.live.

Screenshot 2024-02-27 at 13 22 23
pie title iPhone Usage Distribution
    "Social Media" : 35
    "Calls" : 15
    "Email" : 20
    "Gaming" : 10
    "Music & Podcasts" : 10
    "Photography" : 5
    "Navigation" : 5

@ggrossetie
Copy link
Member

It's the same issue.
Rendering Mermaid server-side will produce these inconsistencies since the label width/height computation relies on fonts and fonts do not render exactly the same on two machines.

@boris-moduscreate
Copy link

Given that font is a configureable option in Mermaid.js would you consider making it an option which can be passed to Kroki?

@ggrossetie
Copy link
Member

The problem is that the font might or might not exist server-side and might or might not render the same server-side. For now, the best workaround is to use a font that displays as uniformly as possible across all operating systems and web browsers.

@boris-moduscreate
Copy link

Yeah I absolutely agree, but the question is who decides what font to use? Do we wait for mermaid to fix it? Does Kroki set a default you believe is best? Should the Kroki docker image have the mermaid default font installed into it? Should the end user be able to provide an override font (assuming it is available)? We self-host Kroki so we don't really care which option is chosen, but we would like to fix it sooner rather than later if possible. Ultimately it's your project and we will defer to your preferred approach here.

@nithom
Copy link

nithom commented Aug 29, 2024

A workaround for us is to tweak the margin settings for generated mermaid diagrams in https://github.com/yuzutech/kroki/blob/main/mermaid/src/task.js.

Within this.mermaidConfig, you can add something like

themeCSS: '.nodeLabel { margin: 3px 20px 3px; }'

This probably still might not work for some fonts, though.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🐞 bug Something isn't working 🙃 upstream
Projects
None yet
Development

No branches or pull requests

6 participants