Mermaid图教程

编程入门 行业动态 更新时间:2024-10-20 06:34:26

Mermaid图<a href=https://www.elefans.com/category/jswz/34/1771193.html style=教程"/>

Mermaid图教程

Mermaid图教程

参考了:

图表方向

graph 图表方向
图表方向含义
TB/TD从上到下
BT从下到上
RL从右到左
LR从左到右

节点图形

格式形状
id[text]矩形
id(text)圆角矩形
id((text))圆形
id>text]右向旗帜状
id{text}菱形

连接线

格式效果
A-->B实线,箭头,无文字
A---B实线,无箭头,无文字
A--文字---BA---|文字|B实线,无箭头,文字
A--文字-->BA-->|文字|B实线,箭头,文字
A-.->B虚线,箭头,无文字
A-.文字.->B虚线,箭头,文字
A==>B大箭头,无文字
A==文字==>B大箭头,文字

特殊语法

引号

文字里用引号避免一些特殊字符的错误。比如矩形节点里有 () 时就无法渲染,所以加上引号。

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

实体字符

可以使用 HTML 中的实体字符。

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

子图

graph TBc1-->a2subgraph onea1-->a2endsubgraph twob1-->b2endsubgraph threec1-->c2end

样式

linkStyle 后面的数字表示第几根线,从 0 开始。可以指定颜色和粗细。

graph TD;A-->B;A-->C;B-->D;C-->D;linkStyle 0 stroke:#0ff,stroke-width:2px;linkStyle 3 stroke:#ff3,stroke-width:4px;

可以设置节点背景,边框颜色,粗细,实线还是虚线

graph LRid1(Start)-->id2(Stop)style id1 fill:#f9f,stroke:#333,stroke-width:4pxstyle id2 fill:#ccf,stroke:#f66,stroke-width:2px,stroke-dasharray: 5, 5

图标

可以使用 Font Awesome 图标。语法 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-camera-retro perhaps?);

时序图

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!

参与者

如果不显示声明,参与者将根据第一次出现的顺序排列,如:

sequenceDiagramAlice->>John: Hello John, how are you?John-->>Alice: Great!

第一条语句出现了两个参与者角色,而在这条语句中,Alice 在 John 之前,所以图中也是这个顺序。如果不想根据第一次出现的顺序来排,可以主动声明以定义顺序:

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

别名

可以给角色写一个简短的别名以方便书写。

sequenceDiagramparticipant A as Aliceparticipant J as JohnA->>J: Hello John, how are you?J->>A: Great!

消息

消息连线有六种样式。

一个-是实线,两个-是虚线。

sequenceDiagramA->B: 无箭头实线A-->B: 无箭头虚线(点线)A->>B: 有箭头实线A-->>B: 有箭头实线A-x B: 有箭头实线,加上叉A--x B: 有箭头虚线,加上叉

更多推荐

Mermaid图教程

本文发布于:2024-02-26 10:14:44,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1702142.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:教程   Mermaid

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!