Worked on readme file
3.8 KiB
mermaid
Generation of diagram and flowchart from text in a similar manner as markdown.
Ever wanted to simplify documentation and avoid heavy tools like visio when explaining your code?
This is why mermaid was born, a simple markdown-like script language for generating charts from text via javascript.
The code below would render to the image
graph TD;
A-->B;
A-->C;
B-->D;
C-->D;
would render this lovely chart:
#Installation
Either use the bower package manager as per below:
bower install mermaid --save-dev
Or download javascript files:
This file bundles mermaid with d3 and dagre-d3.
With this file you need to include d3 and dagre-d3 yourself.
Usage
Include mermaid on your web page:
<script src="mermaid.full.min.js"></script>
Further down on your page mer maid will look for tags with class="mermaid"
from these tags mermaid will try to
read the chart definiton which will be replaced with the svg chart.
A chart defined like this:
<div class="mermaid">
CHART DEFINITION GOES HERE
</div>
Would end up like this:
<div class="mermaid" id="mermaidChart0">
<svg>
Chart ends up here
</svg>
</div>
An id is also added to mermaid tags without id.
A graph example
graph LR;
A[Hard edge]-->|Link text|B(Round edge);
B-->C{Decision};
C-->|One|D[Result one];
C-->|Two|E[Result two];
#Syntax
Graph
This statement declares a new graph and the direction of the graph layout.
graph TD
Would declare a graph oriented from top to bottom.
graph LR
Would declare a graph oriented from left to right.
Nodes
A node (default)
id1;
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.
id1[This is the text in the box];
A node with round edges
id1(This is the text in the box);
A node (rhombus)
id1{This is the text in the box};
Styling a node
It is possible to give a node specific styling as thicker border or a different background color.
graph LR;
id1(Start)-->id2(Stop);
style id1 fill:#f9f,stroke:#333,stroke-width:4px;
style id2 fill:#ccf,stroke:#f66,stroke-width:2px,stroke-dasharray: 5, 5;
Links between nodes
Nodes can be connected with links/edges. It is spoosible to have different types of links and it is also possible to attach a text string to a link.
A link with arrow head
A-->B;
An open link
A---B;
Text on links
A---|This is the text|B;
Credits
Many thanks to the d3 and dagre-d3 projects that is used for graph layout and drawing!!!