# Flowcharts - Basic Syntax ## Graph This statement declares a new graph and the direction of the graph layout. This declares a graph oriented from top to bottom. ``` graph TD Start --> Stop ``` ```mermaid graph TD Start --> Stop ``` This declares a graph oriented from left to right. Possible directions are: * TB - top bottom * BT - bottom top * RL - right left * LR - left right * TD - same as TB ``` graph LR Start --> Stop ``` ```mermaid graph LR Start --> Stop ``` ## Nodes & shapes ### A node (default) ``` graph LR id ``` ```mermaid graph LR id ``` Note that the id is what is displayed in the box. ### A node with text It is also possible to set text in the box that differs from the id. If this is done several times, it is the last text found for the node that will be used. Also if you define edges for the node later on, you can omit text definitions. The one previously defined will be used when rendering the box. ``` graph LR id1[This is the text in the box] ``` ```mermaid graph LR id1[This is the text in the box] ``` ### A node with round edges ``` graph LR id1(This is the text in the box) ``` ```mermaid graph LR id1(This is the text in the box) ``` ### A node in the form of a circle ``` graph LR id1((This is the text in the circle)) ``` ```mermaid graph LR id1((This is the text in the circle)) ``` ### A node in an asymetric shape ``` graph LR id1>This is the text in the box] ``` ```mermaid graph LR id1>This is the text in the box] ``` Currently only the shape above is possible and not its mirror. *This might change with future releases.* ### A node (rhombus) ``` graph LR id1{This is the text in the box} ``` ```mermaid graph LR id1{This is the text in the box} ``` ### Trapezoid ```mermaid graph TD A[/Christmas\] ``` ### Trapezoid alt ```mermaid graph TD B[\Go shopping/] ``` ## Links between nodes Nodes can be connected with links/edges. It is possible to have different types of links or attach a text string to a link. ### A link with arrow head ``` graph LR A-->B ``` ```mermaid graph LR A-->B ``` ### An open link ``` graph LR A --- B ``` ```mermaid graph LR A --- B ``` ### Text on links ``` graph LR A-- This is the text ---B ``` ```mermaid graph LR A-- This is the text ---B ``` or ``` graph LR A---|This is the text|B ``` ```mermaid graph LR A---|This is the text|B ``` ### A link with arrow head and text ``` graph LR A-->|text|B ``` ```mermaid graph LR A-->|text|B ``` or ``` graph LR A-- text -->B ``` ```mermaid graph LR A-- text -->B ``` ### Dotted link ``` graph LR; A-.->B; ``` ```mermaid graph LR; A-.->B; ``` ### Dotted link with text ``` graph LR A-. text .-> B ``` ```mermaid graph LR A-. text .-> B ``` ### Thick link ``` graph LR A ==> B ``` ```mermaid graph LR A ==> B ``` ### Thick link with text ``` graph LR A == text ==> B ``` ```mermaid graph LR A == text ==> B ``` ## Special characters that break syntax It is possible to put text within quotes in order to render more troublesome characters. As in the example below: ``` graph LR id1["This is the (text) in the box"] ``` ```mermaid graph LR id1["This is the (text) in the box"] ``` ### Entity codes to escape characters It is possible to escape characters using the syntax examplified here. ``` graph LR A["A double quote:#quot;"] -->B["A dec char:#9829;"] ``` ```mermaid graph LR A["A double quote:#quot;"] -->B["A dec char:#9829;"] ``` ## Subgraphs ``` subgraph title graph definition end ``` An example below: ``` graph TB c1-->a2 subgraph one a1-->a2 end subgraph two b1-->b2 end subgraph three c1-->c2 end ``` ```mermaid graph TB c1-->a2 subgraph one a1-->a2 end subgraph two b1-->b2 end subgraph three c1-->c2 end ``` ## Interaction It is possible to bind a click event to a node, the click can lead to either a javascript callback or to a link which will be opened in a new browser tab. **Note**: This functionality is disabled when using securityLevel='strict' ``` click nodeId callback ``` * nodeId is the id of the node * callback is the name of a javascript function defined on the page displaying the graph, the function will be called with the nodeId as parameter. Examples of tooltip usage below: ```