Generation of diagrams like flowcharts or sequence diagrams from text in a similar manner as markdown
Go to file
knsv d6c26ab2cd Merge remote-tracking branch 'origin/master' 2014-11-26 18:51:06 +01:00
conf Style in place for edges 2014-11-13 19:51:05 +01:00
dist Small fix, Cleaner add node code 2014-11-26 18:50:12 +01:00
node_modules/jison/node_modules/ebnf-parser Version 0.1.0 2014-11-16 19:00:01 +01:00
scripts Adding missing files 2014-11-13 19:53:31 +01:00
src Small fix, Cleaner add node code 2014-11-26 18:50:12 +01:00
test Fix for br tags within nodes for new line 2014-11-25 22:58:57 +01:00
.travis.yml Setting up continuous integration using travis 2014-11-25 23:23:40 +01:00
LICENSE Initial commit 2014-11-02 00:52:32 +01:00
README.md Update README.md 2014-11-25 23:28:21 +01:00
bower.json Better text handling for flowcharts 2014-11-25 18:58:47 +01:00
gulpfile.js Better text handling for flowcharts 2014-11-25 18:58:47 +01:00
karma.conf.js Style in place for edges 2014-11-13 19:51:05 +01:00
package.json Fix for br tags within nodes for new line 2014-11-25 23:16:44 +01:00

README.md

mermaid Build Status

Generation of diagrams and flowcharts 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 the following image

graph TD;
    A-->B;
    A-->C;
    B-->D;
    C-->D;

would render this lovely chart:

Example 1

#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 will 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 mermaid 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];

Example 2

#Syntax

Graph

This statement declares a new graph and the direction of the graph layout.

graph TD

This declares a graph oriented from top to bottom.

Example 3

graph LR

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

Example 4

Nodes

A node (default)

id1;

Single node

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];

Text in node

A node with round edges

id1(This is the text in the box);

Node with round edges

A node (rhombus)

id1{This is the text in the box};

Decision box

Styling a node

It is possible to apply specific styles such as a thicker border or a different background color to a node.

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;

Node with styles

Classes

More convenient then defining the style everytime is to define a class of styles and attach this class to the nodes that should have a different look.

a class definition looks like the example below:

    classDef className fill:#f9f,stroke:#333,stroke-width:4px;

Attachment of a class to a node is done as per below:

    class nodeId1 className;

It is also possible to attach a class to a list of nodes in one statement:

    class nodeId1,nodeId2 className;

Default class

If a class is named default it will be assigned to all classes without specific class definitions.

    classDef default fill:#f9f,stroke:#333,stroke-width:4px;

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-->B;

Link with arrowhead

A---B;

Open link

A---|This is the text|B;

Text on links

Credits

Many thanks to the d3 and dagre-d3 projects for providing the graphical layout and drawing libraries!!!