-
Notifications
You must be signed in to change notification settings - Fork 39
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
如何用mermaid绘制时序图 #269
Labels
Comments
最简demo这个demo包含了,参与者,带箭头实线,带箭头虚线,备注,循环,可以覆盖常见场景。
```mermaid 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 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!
|
排序语法:participant 通过participant进行排序,由上至下,先出现的位于更左侧。 ```mermaid sequenceDiagram participant John participant Alice Alice->>John: Hello John, how are you? John-->>Alice: Great! ``` sequenceDiagram
participant John
participant Alice
Alice->>John: Hello John, how are you?
John-->>Alice: Great!
别名/短命名participant可以通过as设置alias,从而提升绘图效率 ```mermaid sequenceDiagram participant A as Alice participant J as John A->>J: Hello John, how are you? J->>A: Great! ``` sequenceDiagram
participant A as Alice
participant J as John
A->>J: Hello John, how are you?
J->>A: Great!
|
线段语法: ->, -->, ->>, -->>, -x, --x ```mermaid sequenceDiagram participant A as Alice participant B as Bob A->>B: 有箭头实线 A-->>B: 有箭头实线 A->B: 无箭头实线 A-->B: 无箭头虚线 A-x B: 有箭头实线,加上叉号 A--x B: 有箭头虚线,加上叉号 ``` sequenceDiagram
participant A as Alice
participant B as Bob
A->>B: 有箭头实线
A-->>B: 有箭头实线
A->B: 无箭头实线
A-->B: 无箭头虚线
A-x B: 有箭头实线,加上叉号
A--x B: 有箭头虚线,加上叉号
|
活动期语法:activate deactivate 活动期是垂直方向上的一个矩形,代表一个活动周期。 ```mermaid sequenceDiagram Alice->>John: Hello John, how are you? activate John John-->>Alice: Great! deactivate John ``` sequenceDiagram
Alice->>John: Hello John, how are you?
activate John
John-->>Alice: Great!
deactivate John
简写可以通过+/-来简写 ```mermaid sequenceDiagram Alice->>+John: Hello John, how are you? John-->>-Alice: Great! ``` sequenceDiagram
Alice->>+John: Hello John, how are you?
John-->>-Alice: Great!
|
备注语法:Note [ right of | left of | over ] [Actor] 用于在链路间增加一些备注说明,可以左侧,可以右侧,也可以横跨。 ```mermaid sequenceDiagram participant John Note right of John: Text in note ``` sequenceDiagram
participant John
Note right of John: Text in note
```mermaid sequenceDiagram participant John Note left of John: Text in note ``` sequenceDiagram
participant John
Note left of John: Text in note
```mermaid sequenceDiagram participant John Note over of John: Text in note ``` sequenceDiagram
participant John
Note over John: Text in note
|
循环语法:loop end 可用于表示轮询,定时任务等等。 ```mermaid sequenceDiagram Alice->John: Hello John, how are you? loop Every minute John-->Alice: Great! end ``` sequenceDiagram
Alice->John: Hello John, how are you?
loop Every minute
John-->Alice: Great!
end
|
注释语法:%% ```mermaid sequenceDiagram %% 我是一个注释,你看不到我 Alice->>John: Hello John, how are you? John-->>Alice: Great! %% 我是另一个注释,你也看不到我 ``` sequenceDiagram
%% 我是一个注释,你看不到我
Alice->>John: Hello John, how are you?
John-->>Alice: Great!
%% 我是另一个注释,你也看不到我
|
甘特图模拟js加载
mermaid在线编辑器:https://mermaid.live/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
为什么我选择用mermaid绘图
有尝试过一些绘图软件,例如draw.io,processon等等,这些绘图软件虽然强大,但都有一个通病:需要手动拖拽元素、连接线条、调整繁琐。对于绘制一些简单的时序图或者流程图而言,mermaid是一个非常好的选择。
优点如下:
The text was updated successfully, but these errors were encountered: