What is mermaid?
Mermaid is a JavaScript-based diagramming and charting tool that renders Markdown-inspired text definitions to create and dynamically modify diagrams. It is particularly useful for creating flowcharts, sequence diagrams, class diagrams, state diagrams, Gantt charts, and more.
What are mermaid's main functionalities?
Flowcharts
Mermaid allows you to create flowcharts using a simple syntax. The above code creates a flowchart with decision points and different paths.
```mermaid
flowchart TD
A[Start] --> B{Is it?}
B -->|Yes| C[OK]
B -->|No| D[Not OK]
C --> E[End]
D --> E[End]
```
Sequence Diagrams
Sequence diagrams can be created to represent interactions between different participants over time. The code sample shows a simple interaction between Alice and Bob.
```mermaid
sequenceDiagram
participant Alice
participant Bob
Alice->>Bob: Hello Bob, how are you?
Bob-->>Alice: I am good thanks!
```
Gantt Charts
Mermaid supports Gantt charts for project planning and scheduling. The code sample demonstrates how to define tasks and their durations.
```mermaid
gantt
title A Gantt Diagram
dateFormat YYYY-MM-DD
section Section
A task :a1, 2023-01-01, 30d
Another task :after a1 , 20d
section Another
Task in sec :2023-01-12 , 12d
another task : 24d
```
Class Diagrams
Class diagrams can be used to represent the structure of a system by showing its classes, attributes, and methods. The code sample shows a simple class diagram with inheritance.
```mermaid
classDiagram
class Animal
Animal : +String name
Animal : +int age
Animal : +void eat()
Animal : +void sleep()
class Dog
Dog : +String breed
Dog : +void bark()
Animal <|-- Dog
```
State Diagrams
State diagrams represent the states of an object and transitions between those states. The code sample shows a simple state diagram with different states and transitions.
```mermaid
stateDiagram-v2
[*] --> Still
Still --> [*]
Still --> Moving
Moving --> Still
Moving --> Crash
Crash --> [*]
```
Other packages similar to mermaid
flowchart.js
Flowchart.js is a simple library to create flowcharts using JavaScript. It is less feature-rich compared to Mermaid but is easier to use for basic flowchart needs.
js-sequence-diagrams
js-sequence-diagrams is a library specifically for creating sequence diagrams. It offers a more focused approach to sequence diagrams but lacks the versatility of Mermaid.
chart.js
Chart.js is a popular library for creating various types of charts and graphs. While it does not support diagrams like flowcharts or sequence diagrams, it excels in creating data-driven charts.
d3
D3.js is a powerful library for creating complex and interactive data visualizations. It offers more flexibility and control compared to Mermaid but requires a steeper learning curve.
mermaid
Special note regarding version 8.2
In version 8.2 a security improvement was introduced. A securityLevel configuration was introduced which sets the level of trust to be used on the parsed diagrams.
strict
: (default) tags in text are encoded, click functionality is disabledloose
: tags in text are allowed, click functionality is enabledClosed issues:
ā ļø Note : This changes the default behaviour of mermaid so that after upgrade to 8.2, if the securityLevel is not configured, tags in flowcharts are encoded as tags and clicking is prohibited.
If your application is taking resposibility for the diagram source security you can set the securityLevel accordingly. By doing this clicks and tags are again allowed.
mermaidAPI.initialize({
securityLevel: 'loose'
});
š Keep a steady pulse: mermaid needs more Collaborators #866
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.
Mermaid was nomiated and won the JS Open Source Awards (2019) in the catory The most existing use of technology!!! Thanks to all involved, people committing pull requests, people answering questions and special thanks to Tyler Long who is helping me maintain the project.
Flowchart
graph TD;
A-->B;
A-->C;
B-->D;
C-->D;
Sequence diagram
sequenceDiagram
participant Alice
participant Bob
Alice->>John: Hello John, how are you?
loop Healthcheck
John->>John: Fight against hypochondria
end
Note right of John: Rational thoughts <br/>prevail!
John-->>Alice: Great!
John->>Bob: How about you?
Bob-->>John: Jolly good!
Gantt diagram
gantt
dateFormat YYYY-MM-DD
title Adding GANTT diagram to mermaid
excludes weekdays 2014-01-10
section A section
Completed task :done, des1, 2014-01-06,2014-01-08
Active task :active, des2, 2014-01-09, 3d
Future task : des3, after des2, 5d
Future task2 : des4, after des3, 5d
Class diagram - :exclamation: experimental
classDiagram
Class01 <|-- AveryLongClass : Cool
Class03 *-- Class04
Class05 o-- Class06
Class07 .. Class08
Class09 --> C2 : Where am i?
Class09 --* C3
Class09 --|> Class07
Class07 : equals()
Class07 : Object[] elementData
Class01 : size()
Class01 : int chimp
Class01 : int gorilla
Class08 <--> C2: Cool label
Git graph - :exclamation: experimental
gitGraph:
options
{
"nodeSpacing": 150,
"nodeRadius": 10
}
end
commit
branch newbranch
checkout newbranch
commit
commit
checkout master
commit
commit
merge newbranch
Installation
CDN
https://unpkg.com/mermaid@<version>/dist/
Replace <version>
with expected version number.
Example: https://unpkg.com/mermaid@7.1.0/dist/
Node.js
yarn add mermaid
Documentation
https://mermaidjs.github.io
Sibling projects
Request for assistance
Things are piling up and I have hard time keeping up. To remedy this
it would be great if we could form a core team of developers to cooperate
with the future development mermaid.
As part of this team you would get write access to the repository and would
represent the project when answering questions and issues.
Together we could continue the work with things like:
- adding more types of diagrams like mindmaps, ert diagrams etc
- improving existing diagrams
Don't hesitate to contact me if you want to get involved.
For contributors
Setup
yarn install
Build
yarn build:watch
Lint
yarn lint
We use JavaScript Standard Style.
We recommend you installing editor plugins so you can get real time lint result.
Test
yarn test
Manual test in browser:
open dist/index.html
Release
For those who have the permission to do so:
Update version number in package.json
.
npm publish
Command above generates files into the dist
folder and publishes them to npmjs.org.
Credits
Many thanks to the d3 and dagre-d3 projects for providing the graphical layout and drawing libraries!
Thanks also to the js-sequence-diagram project for usage of the grammar for the sequence diagrams. Thanks to Jessica Peter for inspiration and starting point for gantt rendering.
Mermaid was created by Knut Sveidqvist for easier documentation.
Tyler Long has became a collaborator since April 2017.
Here is the full list of the projects contributors.