markdown 由简入繁,上手跟我做(八)时序图
例 1
```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
例 2
```mermaid
sequenceDiagram
Alice->>John: Hello John, how are you ?
John-->>Alice: Great!
Alice->>John: Hung,you are better .
John-->>Alice: yeah, Just not bad.
```
sequenceDiagram
Alice->>John: Hello John, how are you ?
John-->>Alice: Great!
Alice->>John: Hung,you are better .
John-->>Alice: yeah, Just not bad.
例 3
```mermaid
sequenceDiagram
participant John
participant Alice
Alice-xJohn:Hello John,how are you?
John-->>Alice:Great!
```
sequenceDiagram
participant John
participant Alice
Alice-xJohn:Hello John,how are you?
John-->>Alice:Great!
例 4
消息的语法:
实线或者虚线的使用:
[Actor][Arrow][Actor]:Message text\
Arrow 的六种样式:
- ->
- –>
- ->>
- –>>
- -x
- –x
```mermaid
sequenceDiagram
Alice->John: Hello John, how are you ?
John-->Alice:Great!
Alice->>John: dont borther me !
John-->>Alice:Great!
Alice-xJohn: wait!
John--xAlice: Ok!
```
sequenceDiagram
Alice->John: Hello John, how are you ?
John-->Alice:Great!
Alice->>John: dont borther me !
John-->>Alice:Great!
Alice-xJohn: wait!
John--xAlice: Ok!
例 5
便签
给序列图增加便签:\
具体规则:\[right of | left of | over][Actor]:Text
\
```mermaid
sequenceDiagram
participant John
Note left of John: Text in note
```
sequenceDiagram
participant John
Note left of John: Text in note
跨越两个 Actor 的便签
```mermaid
sequenceDiagram
Alice->>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
```mermaid
sequenceDiagram
Alice->>John: Hello!
loop Reply every minute
John->>Alice:Great!
end
```
sequenceDiagram
Alice->>John: Hello!
loop Reply every minute
John->>Alice:Great!
end
选择 ALT
在序列图中选择的表达。规则如下:
alt Describing text
...statements...
else
...statements...
end
或者使用 opt(推荐在没有 else 的情况下使用)
opt Describing text
...statements...
end
```mermaid
sequenceDiagram
Alice->>Bob: Hello Bob, how are you?
alt is sick
Bob->>Alice:not so good :(
else is well
Bob->>Alice:Feeling fresh like a daisy:)
end
opt Extra response
Bob->>Alice:Thanks for asking
end
```
sequenceDiagram
Alice->>Bob: Hello Bob, how are you?
alt is sick
Bob->>Alice:not so good :(
else is well
Bob->>Alice:Feeling fresh like a daisy:)
end
opt Extra response
Bob->>Alice:Thanks for asking
end
上一篇 markdown 由简入繁,上手跟我做(七)mermaid 画流程图
markdown 教程(目录)
下一篇 markdown 由简入繁,上手跟我做(九)甘特图