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

Massive whitespace above and below graph #1984

Open
sadata7 opened this issue Apr 14, 2021 · 35 comments · Fixed by unoplatform/uno#8430
Open

Massive whitespace above and below graph #1984

sadata7 opened this issue Apr 14, 2021 · 35 comments · Fixed by unoplatform/uno#8430
Labels
Graph: Flow Status: Triage Needs to be verified, categorized, etc Type: Bug / Error Something isn't working or is incorrect

Comments

@sadata7
Copy link

sadata7 commented Apr 14, 2021

Describe the bug
Very large charts result in massive amounts of excess whitespace above and below the diagram making it practically unusable. I was using mermaid to chart a family tree with approximately 400 relationships/nodes. Performance is very acceptable for such an application, so it's unfortunate that I've encountered this issue.

To Reproduce
Steps to reproduce the behavior:
The family tree contains confidential information so I cannot post it, but the problem can easily be reproduced by repeating the simple relationship below. I'm showing 5 repetitions below. The problem starts manifesting itself after about 50 repetitions and becomes extremely problematic at around 150, getting progressively worse as more elements are added to the graph.

flowchart BT
A-->B-->C-->D-->E
A-->B-->C-->D-->E
A-->B-->C-->D-->E
A-->B-->C-->D-->E
A-->B-->C-->D-->E

50 repetitions:
Selection_055

150 repetitions:
Selection_056

Here's what I'm experiencing with the actual family tree. The first example is using the VS Code mermaid extension. Please note the size of the scrollbar handle on the right to get an idea how much empty space is above and below the diagram in addition to the empty space in the visible portion.

Selection_053

The second example is using mermaid in Joplin. Here's what PDF output looks like, and the same amount of empty space is present in the live view.

Selection_054

The problem can also be reproduced in the Live Mermaid Editor. Here's what happens with 500 repetitions of the aforementioned example:

Selection_057

Expected behavior
The size should be limited to the visible extent of the graph.

Screenshots
See above.

Desktop (please complete the following information):

  • any OS

Smartphone (please complete the following information):

  • any device

Additional context
Add any other context about the problem here.

@sadata7 sadata7 added Status: Triage Needs to be verified, categorized, etc Type: Bug / Error Something isn't working or is incorrect labels Apr 14, 2021
@blacksun1
Copy link

Adding to this, I am getting the same issue with very long sequence diagrams when previewing in Visual Studio Code and in the live editor. I was using Markdown PDF by yzane.markdown-pdf version 1.4.4 and VS Code 1.55.2 on Windows.

Curiously, I don't get the same issue when I generate a PNG or SVG image using the same diagram with the npm package @mermaid-js/mermaid-cli. I'm using version 8.9.2 of mermaid-cli on Windows with nodejs version v14.16.0

@blacksun1
Copy link

This is how the cli renders the flow chart as discussed above with 200 repetitions

FlowChart

As you can see, it does now have spacing to the right which I don't think is an issue.

This, however, is how it looks when embedded into a markdown document and previewed using VSCode

image

Notice the spacing on the top and bottom.

@imeikas
Copy link

imeikas commented May 4, 2021

For SVGs I could fix the whitespace by removing the height value from svg tag. Tested only in Firefox.

<svg ... height="2583" style="max-width: 2670px;" viewBox="-50 -10 2670 2583">

to

<svg ... style="max-width: 2670px" viewBox="-50 -10 2670 2583">

Hope this helps track down the issue.

@naletups
Copy link

naletups commented May 4, 2021

For me, the same issue arises for a sequence diagram, for which there are 100 lines (including a 8x participant block and some 15 opt and alt blocks). But it starts already for as few as 25 lines without any opt or alt blocks. The effect is the worse, the wider the figure is.

If you put the following into the live editor, you'll see already quite some spacing at top and bottom. If you add/remove participants you'll see the effect. Unfortunately, it also depends on the screen resolution/window viewport width.

sequenceDiagram
 autonumber
 participant A
 participant B
 participant C
 participant D
 participant E
 participant F
 participant G
A->>B: Task
A->>B: Task
A->>B: Task
A->>B: Task
A->>B: Task
A->>B: Task
A->>B: Task
A->>B: Task
A->>B: Task
A->>B: Task
A->>B: Task
A->>B: Task
A->>B: Task
A->>B: Task
A->>B: Task
A->>B: Task
Loading

@kurtlawrence
Copy link

I am getting similar behaviour with flowcharts

@jlfwilliams
Copy link

Having this same issue, would love a fix!

@thegiantbeast
Copy link

thegiantbeast commented Nov 8, 2021

If it helps on anything, this regression was introduced with 8.8.1 release -> 4dc805d

@thegiantbeast
Copy link

If I switch to 8.8.0 it works as expected. Still haven't found the root cause.

@tessus
Copy link

tessus commented Nov 8, 2021

We have the same problem in Joplin. People have found a workaround by adding the following css:

.mermaid svg { height: auto; }

@knsv ^^^

@Becheler
Copy link

Becheler commented Mar 9, 2022

I am bumping into the same issue with Github rendering. Any news on this front?

@OmgImAlexis
Copy link

Also hitting this issue on github. Here's an anonymised version of what I'm using.

sequenceDiagram
  a->>b: text here
  a->>b: text here
  b->>a: text here  
  a->>b: text here
  a->>c: text here
  c->>d: text here
  c->>e: text here 
  f->>b: text here
  b->>a: text here
  a->>g: text here
  b->>h: text here
sequenceDiagram
  a->>b: text here
  a->>b: text here
  b->>a: text here  
  a->>b: text here
  a->>c: text here
  c->>d: text here
  c->>e: text here 
  f->>b: text here
  b->>a: text here
  a->>g: text here
  b->>h: text here
Loading

@dkkb
Copy link
Contributor

dkkb commented Mar 30, 2022

Also hitting this issue on github. Here's an anonymised version of what I'm using.

sequenceDiagram
  a->>b: text here
  a->>b: text here
  b->>a: text here  
  a->>b: text here
  a->>c: text here
  c->>d: text here
  c->>e: text here 
  f->>b: text here
  b->>a: text here
  a->>g: text here
  b->>h: text here

+1

@listx
Copy link

listx commented Apr 14, 2022

For context, there was a fix for this in #2312 but it was reverted in 38ef061 (presumably because it broke other things).

@Alexander89
Copy link

FYI: There is the same issue if you generate a PNG

docker run -it -v $(pwd):/data -u $UID minlag/mermaid-cli -i /data/dependencies -o /data/dependencies.png

For me, it's fine to use SVG.

@athenor
Copy link

athenor commented Jun 23, 2022

I just ran into this exact same issue in two places. I wrote a fairly long sequence diagram in VS Code, then uploaded it to GitLab as a snippet.

VS Code: 1.68.0, running on Windows 10
Extensions:

  • Markdown Preview Enhanced
  • Markdown Preview mermaid Support v1.14.2
  • Mermaid Markdown Syntax highlighting v1.3.0

Gitlab 15.0 (viewing in Firefox)

@berzi
Copy link

berzi commented Jul 27, 2022

The proposed workarounds using <style> don't work in places like Gitlab wiki. Please fix.

@LouisLeNezet
Copy link

Hi,
I ran in the same issue lately with big flowcharts in a markdown.
When exported to svg the white spaces are not present anymore.
I used the mermaid-cli command:
mmdc -i ReadMeWithMermaidCodes.md -o ReadMeWithSVG.md
to generate the new markdown.
Unfortunately I need to run this command each time I update my original file.
I would be nice to have a fix on this problem.

@Becheler
Copy link

Becheler commented Jul 27, 2022

This issue on my Github pages was solved and the massive blank is gone: that's amazing, thanks devs! ❤️ :

@berzi
Copy link

berzi commented Jul 27, 2022

This issue on my Github pages was solved and the massive blank is gone: that's amazing, thanks devs! ❤️ :

Do you mind explaining how?

@Becheler
Copy link

This issue on my Github pages was solved and the massive blank is gone: that's amazing, thanks devs! heart :

Do you mind explaining how?

If only I knew! I went back to it today after months of absence, and the blank was gone. You can find the flowchart here and the code is avaiable on the raw view of the README :) I wish I could be more useful, but mermaid is a (beautiful) mystery to me!

@nickfyson
Copy link

nickfyson commented Jul 28, 2022

👋 Padding is now being handled appropriately on the GitHub side, so that'll be why the problem is fixed in Pages! 🙂 (I believe the underlying Mermaid issue remains.)

@berzi
Copy link

berzi commented Jul 29, 2022

My issue is on Gitlab so it's not fixed for me. :(

@aadamsx
Copy link

aadamsx commented Aug 8, 2022

Same. See this issue with the Sequence Diagrams in Preview with VS Code. When exporting to various formats it remains. Are there any MM devs looking at this, it's been going on for a long time.

@tekstrand
Copy link

👀 running into this one as well. Would be nice to see the underlying issue here addressed

@trevorhardy
Copy link

Similar issue with Sphinx on ReadTheDocs

@NakitaOza
Copy link

This is how the cli renders the flow chart as discussed above with 200 repetitions

FlowChart

As you can see, it does now have spacing to the right which I don't think is an issue.

This, however, is how it looks when embedded into a markdown document and previewed using VSCode

image

Notice the spacing on the top and bottom.

Where you able to fix this? I am also facing this problem for mermaid sequence diagrams in md files.

@mgoppert
Copy link

mgoppert commented Sep 13, 2022

Try adding a custom.css in your root assets folder with this syntax

.mermaid svg { height: auto; padding: 20pt; }

@berzi
Copy link

berzi commented Sep 13, 2022

That doesn't work where you have no control over CSS, like on Gitlab Wikis.

@amaze-escape
Copy link

That doesn't work where you have no control over CSS, like on Gitlab Wikis.

I also arrived here because of this issue in gitlab wiki.

@eric-cooper
Copy link

I am experiencing similar issues with excessive top/bottom margin (whitespace) for larger flow charts.

This flowchart renders nicely here but in Docsy and in Mac version of VS Code (v1.17.2) with Markdown Preview Mermaid Support (v1.15.2) there are excessive top and bottom margins - each roughly same height as flowchart (below).

Note: setting useMaxWidth to false does make a difference but doesn't solve problem completely. ;-)

%%{init: {"flowchart": {"useMaxWidth": false}}}%%

flowchart LR
    classDef subgraph_padding fill:none,stroke:none

    COMP(Composite Application)

    subgraph STD["Procedure Camera AI Workload (25 fps)"]

      subgraph ugly_hack1 [ ]

        C1(Endoscope Camera)
        S1(Ingest Video);
        P1(Prepare Image);

        subgraph I1[Image Inference Block]
           MR1[( Model Repo)]
           TTD(Tooltip Detection)
           ASD(Anat. Struct. Detection)
        end

        E1(Export Results);
      end
    end

    subgraph SPD["PTZ Camera AI Workload (1 fps)"];

      subgraph ugly_hack2 [ ]

         C2(PTZ Camera);
         S2(Ingest Video);
         P2(Prepare Image);

        subgraph I2[Image Inference Block]
            MR2[( Model Repo)]
            PHD(Phase Detection)
            FB(Face Blur)
            OD(Object Detection)
         end

         E2(Export Results);
       end
    end

    subgraph VID[Video Controller]
      VC(Video Composite)
      VS(Video Switch)
    end
 
 subgraph SC[Shared Components]
      SMR[(Global Model Repo)]
    end

 %% create transparent subgraphs to kludge desired layout for subgraph titles. -ec 22.09.19
    class ugly_hack1 subgraph_padding
    class ugly_hack2 subgraph_padding

    COMP--contains-->STD;
    COMP--contains-->SPD;
    COMP--contains-->SC;
    COMP--contains-->VID;

%% Procedure Camera AI Workflow, etc.
    C1-->S1;
    S1-->P1;
    P1-->TTD;
    P1-->ASD;
    TTD-->E1;   
    ASD-->E1; 

%% PTZ Camera AI Workflow, etc.
    C2-->S2;
    S2-->P2;
    P2-->PHD;
    P2-->FB;
    P2-->OD;
    PHD-->E2;   
    FB-->E2;   
    OD-->E2;   

%% Video Controller and Display
    C1-->VC
    C2-->VC
    E1-->VC
    E2-->VC
    VC-->VS
    VS-->QD[Quad Display]
    VS-->SD[Single Display]
    VS-->TP[Telepresense]
    VS-->DICOM[(DICOM Database)]
    
%% Inference Workloads and Model Repos
    TTD-.uses.->MR1;
    ASD-.uses.->MR1;
    PHD-.uses.->MR2;
    FB-.uses.->MR2;
    OD-.uses.->MR2;
    MR1-.uses.->SMR;
    MR2-.uses.->SMR;

Loading

@EvertonSA
Copy link

+1

@amithkumarg
Copy link

If you are facing this issue with MermaidJS macro in Atlassian Confluence, here is how to resolve it until this issue is addressed.

@ShivamBang98
Copy link

I sort of used a workaround for this in my Confluence page. Here's what I did:

  1. Create the diagram using mermaid.live
  2. Copy the markdown and import it into draw.io (Confluence's embedded draw.io) as mentioned here - https://drawio-app.com/blog/create-mermaid-diagrams-in-draw-io/
  3. Paste the markdown separately in the same doc with the diagram.

This also solved another problem for me, which was that for larger diagrams, I was unable to expand them and see the smaller text. I was also able to wrap it up neatly inside an "expand" macro, so it ended up looking pretty neat. Attached screenshot for reference.

Screenshot 2023-08-29 at 11 19 19 PM

@ossdhaval
Copy link

We are using Mermaid in MkDocs and facing the same issue.

@o6uoq
Copy link

o6uoq commented Jul 9, 2024

Any update? This ticket is 3+ years old, simply to remove whitespace. This is enough to make some users deter to other tools over Mermaid.

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