mermaid icon indicating copy to clipboard operation
mermaid copied to clipboard

Subgraph label spacing is missing left/right and bottom spacing

Open aeneasr opened this issue 5 years ago • 26 comments

Describe the bug

When creating a flowchart with multiple nested subgraphs, spacing is missing below the label (see screenshot section). Additionally, when the subgraph is narrow, there is spacing missing on the left and right of the label.

To Reproduce Check out this live editor link.

Expected behavior For better readability, there should be some spacing below / left and right of the label. I was not able to figure out how to configure that.

Screenshots Screenshot_2020-01-16 Mermaid live editor

Desktop (please complete the following information):

  • OS: macOS
  • Browser: Chrome, Firefox
  • Version: mermaid-js.github.io/mermaid-live-editor accessed on 2020/1/16

Smartphone (please complete the following information):

  • Not applicable

Additional context No context, just a thank you because I'm using mermaid everywhere!

aeneasr avatar Jan 16 '20 09:01 aeneasr

Also when you put a <br/> in the description of the subgraph it does not fit, and the spacing is not changing. Style css options with padding and margin also do not work.

@aeneasr As a work arround i alwasys use an empty subgraph in the subgraph to create more spacing. See subgraph 1 etc.. https://mermaid-js.github.io/mermaid-live-editor/#/edit/eyJjb2RlIjoiZ3JhcGggTFJcblxuc3ViZ3JhcGggcGlbUHVibGljIEludGVybmV0XVxuICAgIEJbQnJvd3Nlcl1cbmVuZFxuXG5zdWJncmFwaCB2cGNbVlBDIC8gQ2xvdWQgLyBEb2NrZXIgTmV0d29ya11cbnN1YmdyYXBoIDFcbnN1YmdyYXBoIFwiRGVtaWxpdGFyaXplZCBab25lIC8gRE1aXCJcbiAgICBPS1tPUlkgT2F0aGtlZXBlciA6NDQ1NV1cbiAgICBCIC0tPiBPS1xuZW5kXG5cbiAgICBPSyAtLT4gU0FEXG4gICAgT0sgLS0-IFNBTFVcbiAgICBPSyAtLT4gU0FMSVxuICAgIE9LIC0tPiBTQVJcbiAgICBPSyAtLT4gU0FBXG4gICAgT0sgLS0-IEtQXG5cbiAgICBzdWJncmFwaCBcIlByaXZhdGUgU3VibmV0IC8gSW50cmFuZXRcIlxuICAgIHN1YmdyYXBoIDNcbiAgICBLWyBPUlkgS3JhdG9zIF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hZGRpbmc6MjBweCxtYXJnaW46MjBweCxzdHJva2U6IzMzMyxzdHJva2Utd2lkdGg6NHB4bGluZS1oZWlnaHQ6MjBweCIsIm1lcm1haWQiOnsidGhlbWUiOiJuZXV0cmFsIiwiZmxvd2NoYXJ0Ijp7InJhbmtTcGFjaW5nIjozMCwibm9kZVNwYWNpbmciOjMwLCJjdXJ2ZSI6ImJhc2lzIn19LCJ1cGRhdGVFZGl0b3IiOmZhbHNlfQ

shebanian avatar Jan 29 '20 13:01 shebanian

Any updates on this? It would be great if the padding auto-adjusted, or at least if we could have some manual padding option.

CarlaFernandez avatar Jul 08 '21 07:07 CarlaFernandez

Bumping this again. Having the same issue.

zimonitrome avatar Sep 17 '21 07:09 zimonitrome

Any updates on this?

gaoxiaoliangz avatar Oct 26 '21 09:10 gaoxiaoliangz

I'm having this as well.

edwarnicke avatar Nov 15 '21 13:11 edwarnicke

This really needs to be resolved please! - takes ages to rearrange/reconfigure the nested boxes in order for the subplot headers to not be obscured

MikePreston avatar Nov 29 '21 16:11 MikePreston

Same problem. To solve this you can add new features :

  • <br> adding a padding
  • adding a TAG (like titlePlacement) to set subgraph tilte placing (Left-rigth, left-center.....)

ledadu avatar Dec 16 '21 15:12 ledadu

b-b-b-bump! subgraphs overlapping parent titles is a bug worth prioritizing, IMHO.

EDIT: The best solution I can come up with is to use &nbsp to move the title, which only works in certain situations.

flowchart LR
subgraph Internet
style Internet stroke-dasharray: 5 5
D[Client]
end
subgraph lan [Internal Network &nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp]
  style lan stroke-dasharray: 5 5
  A[Pomerium]
  D--oA
  A<==>B
  subgraph docker [Docker Network]
  style docker margin-top: 10
    B[Sidecar]
    C[Service]
  end
end

Ugly code, but the render ain't bad.

image

alexfornuto avatar Dec 29 '21 22:12 alexfornuto

It's possible to add subgraphs with custom CSS set to "fill:none,stroke:none". This essentially adds padding.

For example, to fix @alexfornuto's previous chart without using &nbsp.

flowchart LR
classDef subgraph_padding fill:none,stroke:none
subgraph Internet
style Internet stroke-dasharray: 5 5
D[Client]
end
subgraph lan [Internal Network]
subgraph subgraph_padding1 [ ]
  style lan stroke-dasharray: 5 5
  A[Pomerium]
  D--oA
  A<==>B
  subgraph docker [Docker Network]
  style docker margin-top: 10
    B[Sidecar]
    C[Service]
  end
end
end
class subgraph_padding1 subgraph_padding

image

Similarlly, to fix @aeneasr's origional flowchart, see this live editor link.

Repkap11 avatar Jan 31 '22 18:01 Repkap11

@Repkap11 This is awesome! I don't quite understand though why fill: none, stroke:none is fixing the padding... could you provide some insight?

edwarnicke avatar Jan 31 '22 19:01 edwarnicke

The trick is that it's adding a 2nd subgraph which takes up extra space, not actually fixing the problem. The 2nd subgraph is transparent so doesn't cover the title like normally happens.

If you change the CSS class to something like classDef subgraph_padding fill:red,stroke:solid it should be more clear whats going on.

Also, the text of the extra subgraph is set to a space with on this line subgraph subgraph_padding1 [ ]. [ ] means a space.

Repkap11 avatar Jan 31 '22 20:01 Repkap11

This is very similar to https://github.com/mermaid-js/mermaid/issues/2345

asafm avatar Mar 10 '22 09:03 asafm

I really like mermaid, but this issue is really annoying

tschuehly avatar Aug 02 '22 15:08 tschuehly

My workaround works similar to Repkap11's answer, by adding an extra nested subgraph with a blank value and having stroke-dasharray: 0 1 as its style; Nothing else was needed in my case. For example:

flowchart TD
    subgraph Label
        subgraph subgraph_padding_1 [ ]
            style subgraph_padding_1 stroke-dasharray: 0 1

            A --> C
            B --> C
        end
    end
C --> D

4r7if3x avatar Aug 09 '22 17:08 4r7if3x

One more vote for this one, we really need it

LuisBL avatar Sep 10 '22 11:09 LuisBL

style subgraph_padding_1 stroke-dasharray: 0 1

I couldn't get the CSS to work for me. :(

carl-3 avatar Sep 21 '22 21:09 carl-3

style subgraph_padding_1 stroke-dasharray: 0 1

I couldn't get the CSS to work for me. :(

There is a space in between [ & ], haven't you missed it?

4r7if3x avatar Sep 22 '22 05:09 4r7if3x

nope, I got that part. but had to adjust the stroke-dasharray part to get it to work (which I did eventually)

carl-3 avatar Sep 22 '22 17:09 carl-3

bumping this issue, a non-hacky fix would be nice :)

Thank you

NPKBender avatar Oct 07 '22 00:10 NPKBender

I'm new to Mermaid; just to be clear, there's no way to align the text of a subgraph?

flowchart LR
    subgraph FW ["The Label"]
    R(This) -->|"Connects"| P(That<br>there)
    end
    P -->|"Kills"| Blackbox
    style FW text-align:left

does not work:

flowchart LR
    subgraph FW ["The Label"]
    R(This) -->|"Connects"| P(That<br>there)
    end
    P -->|"Kills"| Blackbox
    style FW text-align:left

fw-aaron avatar Oct 07 '22 21:10 fw-aaron

My workaround works similar to Repkap11's answer, by adding an extra nested subgraph with a blank value and having stroke-dasharray: 0 1 as its style; Nothing else was needed in my case.

In my case, I also needed, fill:none, as in...

flowchart TD
    subgraph Label
        subgraph subgraph_padding_1 [ ]
            style subgraph_padding_1 fill:none,stroke-dasharray: 0 1
            A --> C
            B --> C
        end
    end
C --> D

CBroz1 avatar Oct 12 '22 21:10 CBroz1

Any news on this one?

stevedep avatar Nov 02 '22 06:11 stevedep

My workaround works similar to Repkap11's answer, by adding an extra nested subgraph with a blank value and having stroke-dasharray: 0 1 as its style; Nothing else was needed in my case.

In my case, I also needed, fill:none, as in...

flowchart TD
    subgraph Label
        subgraph subgraph_padding_1 [ ]
            style subgraph_padding_1 fill:none,stroke-dasharray: 0 1
            A --> C
            B --> C
        end
    end
C --> D

In my case, I used a classDef to define a new class, which is handy when you need to use it several times:

flowchart LR

subgraph Stage1[Stage 1]
    subgraph Title1 [ ]
        direction TB
        A1 --> B1
        B1 --> C1
    end
end

subgraph Stage2[Stage 2]
    subgraph Title2 [ ]
        direction TB
        A2 --> B2
        B2 --> C2
    end
end

subgraph Stage3[Stage 3]
    subgraph Title3 [ ]
        direction TB
        A3 --> B3
        B3 --> C3
    end
end


Stage1 --> Stage2
Stage2 --> Stage3

classDef Title fill:none,stroke:none;
class Title1,Title2,Title3 Title
flowchart LR

subgraph Stage1[Stage 1]
    subgraph Title1 [ ]
        direction TB
        A1 --> B1
        B1 --> C1
    end
end

subgraph Stage2[Stage 2]
    subgraph Title2 [ ]
        direction TB
        A2 --> B2
        B2 --> C2
    end
end

subgraph Stage3[Stage 3]
    subgraph Title3 [ ]
        direction TB
        A3 --> B3
        B3 --> C3
    end
end


Stage1 --> Stage2
Stage2 --> Stage3

classDef Title fill:none,stroke:none;
class Title1,Title2,Title3 Title

byryepez avatar Dec 08 '22 12:12 byryepez

This very badly deserves to be bumped

bn-l avatar Dec 15 '22 01:12 bn-l

Need someone to step up and take this issue on

jgreywolf avatar Mar 07 '23 17:03 jgreywolf

sigh...

LMS007 avatar Mar 07 '23 21:03 LMS007

++++

respirojnj avatar Apr 11 '23 11:04 respirojnj

any good news?

bigNeoneo avatar Dec 14 '23 03:12 bigNeoneo

bump!!

sgogriff avatar Jan 22 '24 14:01 sgogriff

It's been four years now and this issue is still open. Please either give us a way to modify the padding on the subgraphs or provide a solution. It's a really annoying issue.

mpaw avatar Feb 06 '24 23:02 mpaw