Mermaid语法2-流程图方向、节点以及连接

本文介绍了如何使用Graph语法自上而下创建流程图,包括声明方向、定义节点样式及连接方式,提供了详细的Graph流程图绘制教程。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Graph

graph:绘制流程图
TD声明流程图的方向,声明了图是自上而下的(TD或TB)

graph TD
    Start --> Stop %%注释,由A到B,自上而下排
    %% graph ,声明绘制流程图,TD:top to down
    %% 第二行起建议缩进
    %% 首行不可注释
    %% --> 两个-,两边建议空格
A
B

类似,如下声明自左向右 (LR)

graph LR
    Start --> Stop
A
B

流程图方向

所有的方向:

TB - top to bottom
TD - top-down/ same as top to bottom
BT - bottom to top
RL - right to left
LR - left to right

节点

节点id是流程图的基本单元,除了end,其他字符都可以作为节点id,默认显示内容为节点id:

graph LR
	E %% E为节点id,不能是"end",但可以是“End”、“END”
E
  • 带内容的节点id
    可以给节点id内容,后续可以引用之前定义的节点内容
graph LR
id1[This is the textin the box] --> id1 
%% 节点id与内容之间没有空格
%% 可以引用之前定义的节点id
This is the textin the box

节点形状

节点可以有不同的形状,使用不同的符号,则产生不同box形状

graph TB
id1[矩形] -->
id2(圆角) -->
id3[[subroute process]] -->
id4[(圆柱形)] -->
id5([椭圆]) -->
id6((圆形)) -->
id7>不对称形状] -->
id8{菱形} -->
id9{{六边形}} -->
id10[/This is the text in the box/]  -->
id11[\This is the text in the box\]  -->
 A[/Christmas\] -->
 B[\Go shopping/]
矩形
圆角
subroute process
圆柱形
椭圆
圆形
不对称形状
菱形
六边形
This is the text in the box
This is the text in the box
Christmas
Go shopping

节点之间的连接

Nodes can be connected with links/edges. It is possible to have different types of links or attach a text string to a link.

graph LR
	A --> B  %% 箭头连接
A
B
graph LR
	C --- D %%直线连接 
C
D
graph LR
	A-- text link ---B %% 文本连接
text link
A
B
graph LR
	A-- text link -->B %% 文本箭头连接
text link
A
B
graph LR
	A-.->B %% 虚线箭头
A
B

Dotted link with text

graph LR
   A-. text .-> B %% 虚线箭头
text
A
B

Thick link

graph LR
   A ==> B %% 粗箭头
A
B
graph LR
   A == text ==> B %% 粗箭头文本
text
A
B

参考

Mermaid github

评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值