Mermaid Inconsistent Diagram Sizes Cropped/Squashed

Steps to reproduce

Different mermaid diagrams display wildly different size and scaling behaviors as more information is added to them:

Here’s the code I used for all of them:

Code for diagrams

Flowchart

flowchart LR
    A[Christmas] -->|Get money| B(Go shopping)
    B --> C{Let me think}
    C -->|One| D[Laptop]
    C -->|Two| E[iPhone]
    C -->|Three| F[fa:fa-car Car]
    C -->|Four| X[xanax]
    C -->|Five| Y[yeah]
    C -->|Six| Z[zilch]
    D -->|Test| G[b]
    E -->|Test| H[bl]
    X --> I[bla]
    Y --> J[blah]
    Z --> K[blahb]
    G --> P[blahbl]
    H --> Q[blahbla]
    I --> R[blahblah]
    J --> S[blahblahb]
    K --> T[blahblahbl]

Gitgraph Diagram

%%{init: { 'logLevel': 'debug', 'theme': 'base' } }%%
      gitGraph
        commit
        branch hotfix
        checkout hotfix
        commit
        branch develop
        checkout develop
        commit id:"ash" tag:"abc"
        branch featureB
        checkout featureB
        commit type:HIGHLIGHT
        checkout main
        checkout hotfix
        commit type:NORMAL
        checkout develop
        commit type:REVERSE
        checkout featureB
        commit
        checkout main
        merge hotfix
        checkout featureB
        commit
        checkout develop
        branch featureA
        commit
        checkout develop
        merge hotfix
        checkout featureA
        commit
        checkout featureB
        commit
        checkout develop
        merge featureA
        branch release
        checkout release
        commit
        checkout main
        commit
        checkout release
        merge main
        checkout develop
        merge release

State Diagram

stateDiagram
	direction LR
    [*] --> Still
    Still --> [*]

    Still --> Moving
    Moving --> Still
    Moving --> Crash
    Crash --> blah
    blah --> superblah
    superblah --> uberblah
    uberblah --> single
    single --> tuple 
    tuple --> quadruple
    quadruple --> quintuple
    quintuple --> sextuple 
    sextuple --> septuple
    septuple --> one
    one --> two
    two --> three
    three --> four
    four --> five
    five --> six
    six --> seven
    seven --> eight
    eight --> nine
    nine --> ten
    ten --> eleven
    eleven --> twelve
    twelve --> [*]

User Journey

journey
    title My working day
    section Go to work
      Make tea: 5: Me
      Go upstairs: 3: Me
      Do work: 1: Me, Cat
    section Go home
      Go downstairs: 5: Me
      Sit down: 5: Me
	section Go to work 2
      Make tea: 5: Me
      Go upstairs: 3: Me
      Do work: 1: Me, Cat
    section Go home 2
      Go downstairs: 5: Me
      Sit down: 5: Me
	section Go to work 3
      Make tea: 5: Me
      Go upstairs: 3: Me
      Do work: 1: Me, Cat
    section Go home 3
      Go downstairs: 5: Me
      Sit down: 5: Me

Timeline

timeline
    title Timeline of Industrial Revolution
    section 17th-20th century
        Industry 1.0 : Machinery, Water power, Steam <br>power
        Industry 2.0 : Electricity, Internal combustion engine, Mass production
        Industry 3.0 : Electronics, Computers, Automation
    section 21st century
        Industry 4.0 : Internet, Robotics, Internet of Things
        Industry 5.0 : Artificial intelligence, Big data,3D printing
    section 17th-20th century
        Industry 1.0 : Machinery, Water power, Steam <br>power
        Industry 2.0 : Electricity, Internal combustion engine, Mass production
        Industry 3.0 : Electronics, Computers, Automation
    section 21st century
        Industry 4.0 : Internet, Robotics, Internet of Things
        Industry 5.0 : Artificial intelligence, Big data,3D printing

Gantt

gantt
    dateFormat  YYYY-MM-DD
    title       Adding GANTT diagram functionality to mermaid
    excludes    weekends
    %% (`excludes` accepts specific dates in YYYY-MM-DD format, days of the week ("sunday") or "weekends", but not the word "weekdays".)

    section A section
    Completed task            :done,    des1, 2014-01-06,2014-01-08
    Active task               :active,  des2, 2014-01-09, 3d
    Future task               :         des3, after des2, 5d
    Future task2              :         des4, after des3, 5d
    Future task3              :         des5, after des4, 6d
    Future task4              :         des6, after des5, 2d

    section Critical tasks
    Completed task in the critical line :crit, done, 2014-01-06,24h
    Implement parser and jison          :crit, done, after des1, 2d
    Create tests for parser             :crit, active, 3d
    Future task in critical line        :crit, 5d
    Create tests for renderer           :2d
    Add to mermaid                      :1d
    Functionality added                 :milestone, 2014-01-25, 0d

    section Documentation
    Describe gantt syntax               :active, a1, after des1, 3d
    Add gantt diagram to demo page      :after a1  , 20h
    Add another diagram to demo page    :doc1, after a1  , 48h

    section Last section
    Describe gantt syntax               :after doc1, 3d
    Add gantt diagram to demo page      :20h
    Add another diagram to demo page    :48h

Did you follow the troubleshooting guide? Yes.

Expected result

It would be best if all diagrams displayed in a consistent way that made them readable regardless of how much info is inside them.

I think the best way to do this would be to allow all diagrams to expand and extend off the edge instead of shrinking, and make them all horizontally scrollable with CSS code as shown below to access the cut-off sections. Doing so would make them readable regardless of their horizontal size.

.markdown-source-view .mermaid {
  overflow: scroll;
}

Environment

SYSTEM INFO:
Obsidian version: v1.4.13
Installer version: v1.4.13
Operating system: Windows 10 Home 10.0.22631
Login status: logged in
Catalyst license: supporter
Insider build toggle: on
Live preview: on
Legacy editor: off
Base theme: dark
Community theme: none
Snippets enabled: 0
Restricted mode: off
Plugins installed: 7
Plugins enabled: 0

RECOMMENDATIONS:
none

3 Likes

Steps to reproduce

add a mermaid sequence diagram with more than three actors

sequenceDiagram

title OG Bug
actor User
participant A
participant B
participant C
participant D
participant E

Did you follow the troubleshooting guide? [Y/N]

Yes - I reproduced in Sandbox

Expected result

I would expect to be able to scroll horizontally

Actual result

The image is cut off

Environment

SYSTEM INFO:
Obsidian version: v1.3.7
Installer version: v1.3.7
Operating system: Darwin Kernel Version 22.3.0: Mon Jan 30 20:38:37 PST 2023; root:xnu-8792.81.3~2/RELEASE_ARM64_T6000 22.3.0
Login status: not logged in
Insider build toggle: off
Live preview: on
Legacy editor: off
Base theme: dark
Community theme: none
Snippets enabled: 0
Restricted mode: off
Plugins installed: 5
Plugins enabled: 5
1: Advanced Tables v0.19.1
2: Dataview v0.5.56
3: Excalidraw v1.9.16
4: TagFolder v0.16.10
5: Obsidian Git v2.20.7

RECOMMENDATIONS:
Community plugins: for bugs, please first try updating all your plugins to latest. If still not fixed, please try to make the issue happen in the Sandbox Vault or disable community plugins.


Additional information

2 Likes

I have same issue, so I looked into the generated HTML.

For e.g. stateDiagram, the generated SVG is displayed using a width: 100%, but for sequenceDiagram the with is set as a hard number, e.g. width: 641px.

Stops resizing right there!

Flowcharts and class diagrams have the same issue, so it might actually only be state diagrams that are capable of resizing at the moment.

It should be simple to fix though.

I’ve spent some time to improve mermaid diagrams in my theme Dune.
If you’re interested to try out my theme, then please let me know if i solved your issue :slightly_smiling_face:

1 Like
1 Like

I am encountering this.
I guess this is still an open issue?

Workarounds to avoid cropping:
a CSS snippet:

.mermaid svg {
    width: 100%;
    height: auto;
}

(from Resize and align mermaid diagrams - #12 by Nilat )

or, create the mermaid in one note (e.g. mermaid_note) and embed it in another like so ![[mermaid_note]], and this will allow for scrolling left and right to see full graph.

1 Like

Before opening a new bug report, please search the forum for duplicates and follow the Troubleshooting Guide.

  • We only consider bugs that are reproducible in the sandbox vault or a vault with no third-party plugins/no css snippets/default theme.
  • For Linux, we only accept bug reports that are reproducible with our Appimage package under Gnome or KDE.
  • Developer issues with the API should go here
  • Themes and Custom CSS issues should go here

Once you’ve done the above, delete everything above this line.

Steps to reproduce

I try to create a simple mermaid diagram, below simplified version

graph LR
    A[Client] --> B[Load Balancer]
    B --> C[Auth Filter]
    C --> D[Token Generator]
    D --> E[Auth Manager]
    E --> F[User Database]
    E --> G[Cache Service]
    F --> H[Security Context]
    G --> H

The produced graph cannot be fully displayed or scrolled in the live preview (it works in the read view)
the same bug appeared 2 years ago but it was apparently solved Mermaid graph is cropped when too wide for screen

Did you follow the troubleshooting guide? [Y/N]

Expected result

graph can be scrolled or viewed somehow

Actual result

Graph is cut

Environment

SYSTEM INFO:
	Obsidian version: v1.7.5
	Installer version: v1.7.5
	Operating system: Darwin Kernel Version 24.1.0: Thu Oct 10 21:05:14 PDT 2024; root:xnu-11215.41.3~2/RELEASE_ARM64_T8103 24.1.0
	Login status: logged in
	Language: en
	Catalyst license: insider
	Insider build toggle: on
	Live preview: on
	Base theme: adapt to system
	Community theme: none
	Snippets enabled: 0
	Restricted mode: off
	Plugins installed: 5
	Plugins enabled: 0

RECOMMENDATIONS:
	none

Additional information

Steps to reproduce

In editing mode, displaying line numbers will affect the rendering width of the marmaid

Do not display:

display line numbers:

Did you follow the troubleshooting guide? [Y/N]

Y

Expected result

Automatically adjust render width?

Actual result

Incorrect rendering width causes some parts to be hidden

Environment

SYSTEM INFO:
	Obsidian version: v1.6.5
	Installer version: v1.4.16
	Operating system: Windows 10 Pro 10.0.22621
	Login status: not logged in
	Insider build toggle: off
	Live preview: on
	Base theme: adapt to system
	Community theme: none
	Snippets enabled: 0
	Restricted mode: on

RECOMMENDATIONS:
	none

Additional information

graph TD
    A1(P操作) -->|S=S-1| B1{S < 0}
    B1 -- True --> C1[进程队列]
    B1 -- False --> D1[继续执行]
    
    A2(V操作) -->|S=S+1| B2{S <= 0}
    B2 -- True --> C2[唤醒进程队列中的一个进程]
    B2 -- False --> D2[继续执行]
1 Like

Maybe this is not a bug?Just lacks the function of moving Marmaid canvas?

In v1.8, we will add a scrollbar to mermaid diagrams in LP.
We believe the long term solution to this problem is this FR.

1 Like