13

I want to draw a mermaid diagram containing arrows that do not join with nodes:

graph LR
    A(Sample Text)
    -->A
    A-->B
    B-->A 
    B-->

-->A and B--> fails, likely because the arrow requires both input and output nodes. Is there a workaround? Can I make the node invisible or blank?

Mateen Ulhaq
  • 24,552
  • 19
  • 101
  • 135
TiFr3D
  • 459
  • 1
  • 4
  • 11

5 Answers5

12

How about this?

graph LR
    START[ ]-->A[Sample Text]
    A-->B
    B-->A 
    B-->STOP[ ]
    
    style START fill:#FFFFFF00, stroke:#FFFFFF00;
    style STOP  fill:#FFFFFF00, stroke:#FFFFFF00;

Output diagram is:

--> sample text <--> B -->

Mateen Ulhaq
  • 24,552
  • 19
  • 101
  • 135
Prem
  • 11,775
  • 1
  • 19
  • 33
11

Simply tag the node with :::hidden to hide it:

graph LR
    START:::hidden --> A
    A --> B --> A 
    B --> END:::hidden

    classDef hidden display: none;

Output:

Mateen Ulhaq
  • 24,552
  • 19
  • 101
  • 135
5

Something similar to another comment, but using opacity:

graph LR
    START[ ]-->A[Sample Text]
    A-->B
    B-->A 
    B-->STOP[ ]

    style START fill-opacity:0, stroke-opacity:0;
    style STOP  fill-opacity:0, stroke-opacity:0;
Mateen Ulhaq
  • 24,552
  • 19
  • 101
  • 135
  • Using opacity is better because the solution is independent of the background color. – Jan Aug 23 '22 at 17:27
1

Easier and better if you want to continue from your invisible point:

a --> end[ ]
style end height:0px;

Seems like sometime github rendering have problem with the above, in this case use:

style end height:1px;
style end width:1px;
kofifus
  • 17,260
  • 17
  • 99
  • 173
-1

A more simple way which I found here

digraph {
    rankdir=LR;
    nowhere [style=invis,shape=point]
    nowhere -> on
    on -> off [label = "Push"]
    off -> on [label = "Push"]
}

Output is something like

State diagram of a push button

Madhusoodan P
  • 681
  • 9
  • 20