简单状态 mermaid stateDiagram-v2
direction LR
s1 --> s2
1 2 3
别名 mermaid stateDiagram-v2
direction LR
state "this is state s1" as s1
s2: this is state s2
s1 --> s2: 连接描述
1 2 3 4 5
开始和结束 mermaid stateDiagram-v2
direction LR
%% [*]在左边表示开始右边表示结束
[*] --> [*]
1 2 3 4
复合状态 mermaid stateDiagram-v2
[*] --> First
state First {
[*] --> Second
state Second {
[*] --> second
second --> Third
state Third {
[*] --> third
third --> [*]
}
}
}
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
选择 mermaid stateDiagram-v2
%% 关键语法
state if_state <<choice>>
[*] --> IsPositive
IsPositive --> if_state
if_state --> False: if n < 0
if_state --> True : if n >= 0
False --> [*]
True --> [*]
1 2 3 4 5 6 7 8 9
fork/join状态 mermaid stateDiagram-v2
state fork_state <<fork>>
%% fork语法
[*] --> fork_state
fork_state --> State2
fork_state --> State3
%% join语法
state join_state <<join>>
State2 --> join_state
State3 --> join_state
join_state --> State4
State4 --> [*]
1 2 3 4 5 6 7 8 9 10 11 12
并发状态 mermaid stateDiagram-v2
[*] --> Active
state Active {
[*] --> NumLockOff
NumLockOff -->
NumLockOn : EvNumLockPressed
NumLockOn -->
NumLockOff : EvNumLockPressed
--
[*] --> CapsLockOff
CapsLockOff -->
CapsLockOn : EvCapsLockPressed
CapsLockOn -->
CapsLockOff : EvCapsLockPressed
}
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
备注 mermaid stateDiagram-v2
State1: The state with a note
%% 多行备注
note right of State1
Important information!
You can write break line
notes.
end note
State1 --> State2
%% 单行备注
note left of State2 : note left
1 2 3 4 5 6 7 8 9 10 11