状态图

状态图 提供了一个系统或对象可能处于的各种状态的视觉表示,以及状态之间的转换。它们在模拟系统的动态行为方面至关重要,捕获它们如何随着时间的推移响应不同的事件。状态图描述了系统的生命周期,使其行为更易于理解、设计和优化。

使用 PlantUML 创建状态图提供了几个优势:

普通状态

使用([*])绘制状态图的起点或终点。

使用-->添加箭头。

简化状态

你可以使用隐藏空描述,即 hide empty description 关键字,渲染一个简单的状态。

复杂状态

一个状态也可能是嵌套的,必须使用关键字state和花括号来定义复杂状态。

内部子状态

子状态间的连接

[Ref. QA-3300]

WARNING
 This translation need to be updated. 
WARNING

长状态名

也可以使用关键字state来给状态描述较长的状态名,并定义其指代名。

历史状态 [[H], [H*]]

在嵌套状态中,你可以用 [H] 来表示历史状态, [H*] 表示深层历史状态.

分支状态 [fork, join]

你可以使用版型 <<fork>><<join>> 来表示状态的分叉及合并。

并发状态 [--, ||]

-- or ||作为分隔符来合成并发状态。

水平分隔 --

竖直分隔 ||

*[Ref. [QA-3086](https://forum.plantuml.net/3086/state-diagram-concurrent-state-horizontal-line)]*
WARNING
 This translation need to be updated. 
WARNING

选择结点 [choice]

版型 <<choice>>可以用来表示一个选择结点,表示状态条件。

一个使用版型的完整样例 [start, choice, fork, join, end]

[参考QA-404,QA-1159GH-887]

[Ref. QA-19174]
WARNING
 This translation need to be updated. 
WARNING

入口和出口 [entryPoint, exitPoint]

你可以用以下版型给合成状态添加入口结点<<entryPoint>>出口结点 <<exitPoint>>

WARNING
 This translation need to be updated. 
WARNING

引脚 [inputPin, outputPin]

你可以用以下版型添加引脚结点<<inputPin>><<outputPin>>

[Ref.QA-4309]

WARNING
 This translation need to be updated. 
WARNING

扩展 [expansionInput, expansionOutput]

你可以用以下版型添加扩展结点<<expansionInput>><<expansionOutput>>

[Ref.QA-4309]

WARNING
 This translation need to be updated. 
WARNING

箭头方向

使用->定义水平箭头,也可以使用下列格式强制设置箭头方向:

可以用首字母缩写或者开始的两个字母定义方向(如, -d--down--do-是完全等价的)。

请不要滥用这些功能,Graphviz不喜欢这样。

更改箭头线条的颜色和风格

你可以更改线条的颜色及风格.

[Ref. Incubation: Change line color in state diagrams]

*[Ref. [QA-93](https://forum.plantuml.net/93/how-use-different-color-for-arrows-in-state-diagram)]*
WARNING
 This translation need to be updated. 
WARNING

Change head or tail of arrow line

注释

可以用 note left of, note right of, note top of, note bottom of 关键字来定义注释。

还可以定义多行注释。

以及浮动注释。

WARNING
 This translation need to be updated. 
WARNING

在箭头上添加注释

你可以在连接箭头上使用 note on link 关键字来添加注释.

给复杂状态添加注释

可以给嵌套的状态添加注释。

颜色

[参考QA-1812]

显示参数

skinparam改变字体和颜色。

可以在如下场景中使用:

还可以为状态的构造类型指定特殊的字体和颜色。

状态图所有显示参数测试

Changing style

You can change style.

[Ref. GH-880]

Change state color and style (inline style)

You can change the color or style of individual state using the following notation:

With background color first (#color), then line style and line color (##[style]color ).

[Ref. QA-1487]

FIXME
🚩 text:color seems not to be taken into account
FIXME

[Adapted from QA-3770]

别名

有了State,你可以使用alias ,比如。

或。

[Ref. QA-1748, QA-14560]

Display JSON Data on State diagram

Simple example

[Ref. QA-17275]

For another example, see on JSON page.

State description

You can add description to a state or to a composite state.

[Ref. QA-16719]

Style for Nested State Body

[Ref. QA-16774]