markdown绘图插件----mermaid简介

作者:黄永刚

mermaid简介

这里写图片描述

当撰写文档的时候,对于流程图的生成大多使用Visio等繁重的工具,没有一种轻便的工具能够画图从而简化文档的编写,就像markdown那样。

mermaid解决这个痛点,这是一个类似markdown语法的脚本语言,通过JavaScript实现图表的生成。
先来看个例子:

1.流程图(flowchart)

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

生成的图表如下所示:

这里写图片描述
2. 时序图(sequence diagram)

sequenceDiagramparticipant Aliceparticipant BobAlice->John:Hello John, how are you?loop HealthcheckJohn->John:Fight against hypochondriaendNote right of John:Rational thoughts <br/>prevail...John-->Alice:Great!John->Bob: How about you?Bob-->John: Jolly good!

生成的图表如下所示:

这里写图片描述

3.甘特图(gantt diagram)

ganttdateFormat YYYY-MM-DDtitle Adding GANTT diagram functionality to mermaidsection A sectionCompleted task  :done, des1, 2014-01-06,2014-01-08Active task     :active, des2, 2014-01-09, 3dfuture task     :     des3, after des2, 5dfuture task2    :     des4, after des3, 5dsection Critical tasksCompleted task in the critical line :crit, done, 2014-01-06,24hImplement parser and json      :crit, done, after des1, 2dCreate tests for parser       :crit, active, 3dFuture task in critical line     :crit, 5dCreate tests for renderer      :2dAdd to ,mermaid           :1d

生成的表如下:

这里写图片描述


下游项目

Mermaid 是由Knut Sveidqbist发起旨在轻便化的文档撰写。所有开发者:开发者列表

  • Gitbook-plugin
  • Light table
  • Confluence plugin
  • Using mermaid via docpad
  • Using mermaid in Jekvll
  • Using mermaid via Octopress
  • Mardown editor Haroopad
  • Plugin for atom
  • Markdown Plus
  • LightPaper 1.2+
  • Vim Plugin
    以上的这些都有集成mermaid或者开发相关的插件。

Graph

graph LRA --> B

这里写图片描述
这是申明一个由左到右,水平向右的图。\
可能方向有:
- TB - top bottom
- BT - bottom top
- RL - right left
- LR - left right
- TD - same as TB


节点与形状

默认节点

graph LR
id1


注意:’id’显示在节点内部。

文本节点

这里写图片描述

graph LR
id[This is the text in the box];
圆角节点

这里写图片描述

graph LR
id(This is the text in the box);
圆节点(The form of a circle)

这里写图片描述

graph LR
id((This is the text in the circle));
非对称节点(asymetric shape)

这里写图片描述

graph LR
id>This is the text in the box]
菱形节点(rhombus)

这里写图片描述

graph LR
id{This is the text in the box}

连接线

节点间的连接线有多种形状,而且可以在连接线中加入标签:

箭头形连接

这里写图片描述

graph LR;A-->B;
开放行连接

graph LR
A --- B
标签连接

这里写图片描述

graph LR
A -- This is the label text --- B;
箭头标签连接

A–>|text|B\
或者\
A– text –>B

这里写图片描述

graph LRA-- text -->B
虚线(dotted link,点连线)

-.->

这里写图片描述

graph LR
A-.->B

-.-.

这里写图片描述

graph LR
A-.-.B
标签虚线

-.text.->

graph LR
A-.text.->B

这里写图片描述

粗实线

==>

graph LR
A==>B

这里写图片描述

===

graph LR
A===B

这里写图片描述

标签粗线

=\=text\==>

graph LR
A==text==>B

这里写图片描述

=\=text\===

graph LR
A==text===B

这里写图片描述


特殊的语法

使用引号可以抑制一些特殊的字符的使用,可以避免一些不必要的麻烦。

graph LR\
d1[“This is the (text) in the box”]

graph LR
d1["This is the (text) in the box"]

这里写图片描述

html字符的转义字符

转义字符的使用语法:
流程图定义如下:

graph LR\
A[“A double quote:#quot;”] –> B[“A dec char:#9829;”]

渲染后的图如下:
这里写图片描述

graph LRA["A double quote:#quot;"]-->B["A dec char:#9829;"]

子图(Subgraphs)

subgraph title\
graph definition\
end

示例:

graph TBsubgraph onea1 --> a2ensubgraph twob2 --> b2endsubgraph threec1 --> c2endc1 --> a2

结果:

这里写图片描述

基础fontawesome支持

如果想加入来自frontawesome的图表字体,需要像frontawesome网站上那样引用的那样。\
详情请点击:fontawdsome

引用的语法为:++fa:#icon class name#++

graph TDB["fa:fa-twitter for peace"]B-->C[fa:fa-ban forbidden]B-->D(fa:fa-spinner);B-->E(A fa:fa-camerra-retro perhaps?);

渲染图如下:

graph TDB["fa:fa-twitter for peace"]B-->C[fa:fa-ban forbidden]B-->D(fa:fa-spinner);B-->E(A fa:fa-camera-retro perhaps?);

这里写图片描述

以上reference:
1.mermaid docs


第二部分—图表(graph)


定义连接线的样式
graph LRid1(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;

渲染结果:

这里写图片描述

graph LRid1(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;

备注:这些样式参考CSS样式。

样式类

为了方便样式的使用,可以定义类来使用样式
类的定义示例:

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

对节点使用样式类:

class nodeId className;

同时对多个节点使用相同的样式类:

class nodeId1,nodeId2 className;

可以在CSS中提前定义样式类,应用在图表的定义中。

graph LRA-->B[AAABBB];B-->D;class A cssClass;

默认样式类:\
当没有指定样式的时候,默认采用。

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

示例:

graph LRclassDef default fill:#f90,stroke:#555,stroke-width:4px;id1(Start)-->id2(Stop)

结果:

graph LR
classDef default fill:#f90,stroke:#555,stroke-width:4px;
id1(Start)-->id2(Stop)

这里写图片描述

序列图(sequence diagram)1

序列图

示例:

sequenceDiagramAlice->>John: Hello John, how are you ?John-->>Alice: Great!Alice--->>John: Huang,you are better .John-->>Alice: yeah, Just not bad.
sequenceDiagramAlice->>John: Hello John, how are you ?John-->>Alice: Great!Alice->>John: Hung,you are better .John-->>Alice: yeah, Just not bad.

这里写图片描述
观察上面的图,如果想让John出现在前面,如何控制,mermaid通过设定参与者(participants)的顺序控制二者的顺序。上面的图可以做如下修改:

sequenceDiagram\
  participant John\
  participant Alice\
  Alice->>John:Hello John,how are you?\
  John–>>Alice:Great!

sequenceDiagramparticipant Johnparticipant AliceAlice-xJohn:Hello John,how are you?John-->>Alice:Great!

这里写图片描述
消息的语法:
  实线或者虚线的使用:
[Actor][Arrow][Actor]:Message text\
Arrow的六种样式:

  • ->
  • –>
  • ->>
  • –>>
  • -x
  • –x

示例:

sequenceDiagramAlice->John: Hello John, how are you ?John-->Alice:Great!Alice->>John: dont borther me !John-->>Alice:Great!Alice-xJohn: wait!John--xAlice: Ok!

这里写图片描述

便签

给序列图增加便签:\
具体规则:\
[right of | left of | over][Actor]:Text\
示例:

sequenceDiagramparticipant JohnNote left of John: Text in note

结果:

这里写图片描述

跨越两个Actor的便签:

sequenceDiagramAlice->John:Hello John, how are you?Note over Alice,John:A typical interaction
sequenceDiagram
Alice->>John:Hello John, how are you?
Note over Alice,John:A typical interaction

这里写图片描述

循环Loops

在序列图中,也可以使用循环,具体规则如下:

loop Loop text
... statements...
end

示例:

sequenceDiagramAlice->>John: Hello!loop Reply every minuteJohn->>Alice:Great!end

渲染结果:

这里写图片描述

选择ALT

在序列图中选择的表达。规则如下:

alt Describing text
...statements...
else
...statements...
end

或者使用opt(推荐在没有else的情况下使用)

opt Describing text
...statements...
end

示例:

sequenceDiagramAlice->>Bob: Hello Bob, how are you?alt is sickBob->>Alice:not so good :(else is wellBob->>Alice:Feeling fresh like a daisy:)endopt Extra responseBob->>Alice:Thanks for askingend

渲染结果如下:

这里写图片描述


甘特图(gantt)2

甘特图是一类条形图,由Karol Adamiechi在1896年提出, 而在1910年Henry Gantt也独立的提出了此种图形表示。通常用在对项目终端元素和总结元素的开始及完成时间进行的描述。

示例:

gantt
dateFormat YYYY-MM-DDsection S1
T1: 2014-01-01, 9dsection S2
T2: 2014-01-11, 9dsection S3
T3: 2014-01-02, 9d
gantt
dateFormat YYYY-MM-DD
section S1
T1: 2014-01-01, 9d
section S2
T2: 2014-01-11, 9d
section S3
T3: 2014-01-02, 9d

这里写图片描述

先来看一个大的例子:

    ganttdateFormat  YYYY-MM-DDtitle Adding GANTT diagram functionality to mermaidsection A sectionCompleted task            :done,    des1, 2014-01-06,2014-01-08Active task               :active,  des2, 2014-01-09, 3dFuture task               :         des3, after des2, 5dFuture task2               :         des4, after des3, 5dsection Critical tasksCompleted task in the critical line :crit, done, 2014-01-06,24hImplement parser and jison          :crit, done, after des1, 2dCreate tests for parser             :crit, active, 3dFuture task in critical line        :crit, 5dCreate tests for renderer           :2dAdd to mermaid                      :1dsection DocumentationDescribe gantt syntax               :active, a1, after des1, 3dAdd gantt diagram to demo page      :after a1  , 20hAdd another diagram to demo page    :doc1, after a1  , 48hsection Last sectionDescribe gantt syntax               :after doc1, 3dAdd gantt diagram to demo page      : 20hAdd another diagram to demo page    : 48h

获得的图渲染后如下:
这里写图片描述

header 1header 2
title标题
dateFormat日期格式
section模块
Completed已经完成
Active当前正在进行
Future后续待处理
crit关键阶段
日期缺失默认从上一项完成后

关于日期的格式可以参考:
- string-format
- Time-Formatting

Demo

graph TBsq[Square shape] --> ci((Circle shape))subgraph A subgraphdi{Diamond with  line break} -.-> ro(Rounded)di==>ro2(Rounded square shape)ende --> od3>Really long text with linebreak<br>in an Odd shape]cyr[Cyrillic]-->cyr2((Circle shape Начало));classDef green fill:#9f6,stroke:#333,stroke-width:2px;classDef orange fill:#f96,stroke:#333,stroke-width:4px;class sq,e greenclass di orange

这里写图片描述

reference

mermaid docs


本文原创首发于公众号:老王和他的IT界朋友们

微信扫描关注微信号:(原创投稿有惊喜!!!)


  1. 序列图的样式的定制需要在可以渲染CSS的地方才可使用,具体可以查阅参考。 ↩
  2. 甘特图的样式的定制需要在可以渲染CSS的地方才可使用,具体可以查阅参考。 ↩

转载于:https://www.cnblogs.com/wuyida/p/6301240.html

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/429962.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

华为三层交换机路由配置案例_华为三层交换机配置实例

1华为三层交换机配置实例一例服务器1双网卡&#xff0c;内网IP:&#xff0c;其它计算机通过其代理上网PORT1属于VLAN1PORT2属于VLAN2PORT3属于VLAN3VLAN1的机器可以正常上网配置VLAN2的计算机的网关为&#xff1a;配置VLAN3的计算机的网关为&#xff1a;即可实现VLAN间互联如果…

大学只待成追忆,只是工作已半年,2016再见

时光匆匆&#xff0c;真的不知不觉&#xff0c;已经毕业半年。这一年发生了好多事&#xff0c;回望简直难以相信。 再见广州&#xff0c;你好厦门 广深工作好找&#xff0c;但心就是想离开&#xff0c;当时想的是&#xff0c;找一个地方&#xff0c;让一切重新开始。来到厦门…

centos7挂载nas存储_CentOS7搭建NAS文件共享存储

概述&#xff1a;NFS是一种基于TCP/IP传输的网络文件系统协议&#xff0c;最初由SUN公司开发。通过NFS协议&#xff0c;客户机可以像访问本地目录一样访问远程服务器中的共享资源。NFS得到了如NAS等网络存储的设备极好支持。也是LVS共享存储的首选。环境&#xff1a;CentOS 7.8…

【移动端html5】 android video播放进度精确控制

android上视频播放存在的问题 在PC上播放html5视频&#xff0c;设置video.currentTime5,视频将跳到5s的位置&#xff0c;并且显示出第5s的画面。在安卓下&#xff0c;却存在下面两个问题&#xff1a; 在安卓上&#xff0c;为了省电&#xff0c;在暂停的时候&#xff0c;改变视…

柯理化

在JS中柯里化就是把一个需要传入多个参数的函数变成多个嵌套的只要传入一个参数的函数 在普通函数中的柯理化&#xff1a; var addfunction(x,y){ return xy; } 柯里化&#xff1a; var addCurringfunction(x){ return function(y){ return xy; } } addCurring(1)(2);//3 如果是…

Java NIO 教程

NIO 概述 NIO有三个核心组件&#xff1a; 通道&#xff08;Channels&#xff09;缓冲器&#xff08;Buffers&#xff09;选择器&#xff08;Selectors&#xff09; 实际上&#xff0c;NIO的组件和类远不止这三个&#xff0c;但这个三个组件是核心。至于其它组件&#xff0c;…

threejs相机和渲染器

渲染器 渲染器其实代表的是canvas标签。 渲染器的类型 WebGLRender 使用WebGL来渲染图形&#xff0c;速度较快&#xff0c;但是有些机器不支持WebGL。 CanvasRender 使用canvas2d来渲染图形&#xff0c;在较老的版本上&#xff0c;主要是用来渲染2D图形。现在这个渲染器在…

类的 三大特性 封装,继承,多态 overload与override的区别

OOP三大特性&#xff1a;封装&#xff0c;继承&#xff0c;多态 封装的目的&#xff1a;为了让类更安全封装的做法&#xff1a;1.类里面的成员变量做为private2.使用成员方法来间接访问成员变量3.在该方法里面加限制条件 php类里面不允许出现同名方法 继承 概念&#xff1a;子类…

三级菜单 python_python三级菜单

menu {北京:{海淀:{五道口:{soho:{},网易:{},google:{}},中关村:{爱奇艺:{},汽车之家:{},youku:{},},上地:{百度:{},},},昌平:{沙河:{老男孩:{},北航:{},},天通苑:{},回龙观:{},},朝阳:{},东城:{},},上海:{闵行:{"人民广场":{炸鸡店:{}}},闸北:{火车战:{携程:{}}},浦…

threejs概览

threejs术语和概念 threejs的API很长&#xff0c;有很多概念和术语&#xff0c;理解了这些概念和术语&#xff0c;才能更好的使用threejs。这些概念和术语都藏在API右侧的大纲中&#xff0c;下图简单整理了一下这些概念&#xff1a; 这些概念又分为四个大类&#xff08;见上图…

C#生成新浪微博短网址 示例源码

using System;using System.Collections.Generic;using System.Linq;using System.Text;using DotNetSample.Models;using System.Web.Script.Serialization;namespace DotNetSample.Utils{public class ShortUrlHelper{/// <summary>/// 获取新浪短域名/// </summary…

leetcode数组汇总_[LeetCode] 300. 最长上升子序列

题目链接&#xff1a; https://leetcode-cn.com/problems/longest-increasing-subsequence难度&#xff1a;中等通过率&#xff1a;43.0%题目描述:给定一个无序的整数数组&#xff0c;找到其中最长上升子序列的长度。示例: 输入: [10,9,2,5,3,7,101,18] 输出: 4 解释:…

threejs创建平面几何形状

创建平面几何形状 平面几何形状有三种&#xff1a;点&#xff0c;线&#xff0c;面三种&#xff0c;下面说说用threejs创建这几种形状的方法。 创建点 创建点可以使用Points类。 function createPoints(){//创建一个Geometry&#xff0c;并添加点let geometry new THREE.G…

新建vue3项目(未完待续)

vite 官网 https://cn.vitejs.dev/ 使用 vite 创建项目 npm create vitelatest 进入目录后 执行 npm install 运行程序 npm run dev vscode 不要同时安装 vetur 和 volar 关于安装eslint 官网 &#xff1a;https://eslint.org 安装ESLINT npm install eslint …

wcf 返回图片_wcf http 返回图片

做项目时候用wcf 返回图片,从官网上找了找一次只能返回一张图片&#xff0c;但是一直查不到返回多个图片的方法&#xff0c;ios 可以异步加载看速度也可以&#xff0c;先记录一下等以后用解决了再发[ServiceContract]public interface IImageServer{[OperationContract, WebGet…

threejs精灵(Sprite)

Sprite精灵 Sprite叫精灵&#xff0c;计算机图形学中&#xff0c;精灵指包含于场景中的二维图像或动画&#xff08;wiki&#xff09;。在threejs中&#xff0c;这样说明Sprtite&#xff08;doc&#xff09; : A sprite is a plane that always faces towards the camera , ge…

Ubuntu更改鼠标灵敏度

需要命令:xinput 清自行用 man xinput 查询 xinput 帮助文档 1、插入鼠标&#xff0c;打开终端&#xff0c;输入命令&#xff1a;xinput 查询当前已挂在设备 2、拔出鼠标&#xff0c;打开终端&#xff0c;再输入命令&#xff1a;xinput 查询当前已挂在设备&#xff0c;发现缺少…

echarts 生成 迁徙图_echarts3 迁徙图 迁入迁出(示例代码)

geoCoordMap {‘上海‘: [121.4648,31.2891],‘佛山‘: [112.8955,23.1097],‘保定‘: [115.0488,39.0948],‘兰州‘: [103.5901,36.3043],‘包头‘: [110.3467,41.4899],‘北京‘: [116.4551,40.2539],‘天津‘: [117.4219,39.4189],‘常州‘: [119.4543,31.5582],‘广州‘: […

threejs骨架形状

骨骼动画 骨骼是什么&#xff1f;骨骼就是一个可以控制其它形状的对象。在threejs中&#xff0c;骨骼&#xff08;Bone&#xff09;就是一个空的Object3D对象&#xff0c;当然&#xff0c;也可以是任何Object3D对象的子类。 创建骨架 创建骨架总体来说就四步&#xff1a; 创…

.net 知识积累

日历模式&#xff1a; 可以使用按钮事件进行触发 &#xff1b; 设置默认按钮&#xff1a; this.Form.DefaultButton"ID属性" &#xff1b; 注意此功能只能应用于.net控键中&#xff0c;必须位于 ruant "Server"; DefaultButton 必须是 IButtonControl 类…