状态图

  • 基于PlantUML
  • 状态图
PlantUML制图-概述

状态图

基础

  • [*] 表示开始/结束

state-1.png

1
2
3
4
5
6
7
8
9
10
@startuml state-1
hide empty description
[*] --> 状态1
状态1 --> [*]
状态1 : this is a string
状态1 : this is another string

状态1 -> 状态2
状态2 --> [*]
@enduml

分组状态

  • state XXX { } 指定分组状态

state-2.png

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
@startuml state-2
hide empty description
[*] --> 未指派

state 未指派 {
[*] --> 未写入
未写入 --> 已写入 : 接口调用
已写入 --> 未写入 : 响应
}

state 已写入 {
[*] --> 未处理
未处理 --> 处理成功
处理成功 --> [*]
未处理 --> 处理失败
处理失败 --> [*]
state 处理失败 {
[*] --> 未接通
[*] --> 已接通未同意
未接通 --> [*]
已接通未同意 --> [*]
}
}
未指派 --> [*]
已写入 -> [*]
@enduml

并发状态

  • -- 虚线分割线

state-3.png

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
@startuml state-3
hide empty description
[*] --> Active

state Active {
[*] -> NumLockOff
NumLockOff --> NumLockOn : EvNumLockPressed
NumLockOn --> NumLockOff : EvNumLockPressed
--
[*] -> CapsLockOff
CapsLockOff --> CapsLockOn : EvCapsLockPressed
CapsLockOn --> CapsLockOff : EvCapsLockPressed
--
[*] -> ScrollLockOff
ScrollLockOff --> ScrollLockOn : EvCapsLockPressed
ScrollLockOn --> ScrollLockOff : EvCapsLockPressed
}
@enduml

箭头方向

  • up
  • down
  • left
  • right

state-4.png

1
2
3
4
5
6
7
8
@startuml state-4
hide empty description
[*] -up-> First : 向上
First -right-> Second : 向右
Second -down-> Third : 向下
Third -left-> Last : 向左
Last -down-> [*] : 结束
@enduml

注释

  • 省略(与其他的图一致)

state-5.png

1
2
3
4
5
6
7
8
9
10
11
12
13
14
@startuml state-5
hide empty description
[*] --> Active
Active --> Inactive

note left of Active : 旁侧注释

note right of Inactive



end note
note "无箭头注释" as N1
@enduml

自定义样式

  • skinparam 可以指定样式

state-6.png

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
@startuml state-6
skinparam backgroundColor LightYellow
skinparam state {
StartColor MediumBlue
EndColor Red
BackgroundColor Peru
BackgroundColor<<Warning>> Olive
BorderColor Gray
FontName Impact
}

[*] --> NotShooting

state "Not Shooting State" as NotShooting {
state "Idle mode" as Idle <<Warning>>
state "Configuring mode" as Configuring
[*] --> Idle
Idle --> Configuring : EvConfig
Configuring --> Idle : EvConfig
}

NotShooting --> [*]
@enduml