In an attempt to improve PlantUML documentation...
Wiki Toc View page history Add new chapter Reorder page Raw
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
State Diagram
Simple State[*] for the starting point and ending point of
the state diagram.
Use --> for arrows.
Change state renderinghide empty description to render state as simple box.
Composite statestate
keywords and brackets.
Internal sub-state
Sub-state to sub-state
[Ref. QA-3300]
Long namestate keyword to use long description
for states.
History [[H], [H*]][H] for the history and [H*] for the deep history of a substate.
Fork [fork, join]<<fork>> and <<join>> stereotypes.
Concurrent state [--, ||]--
or || symbol as separator.
Horizontal separator
|
<<choice>>
can be used to use conditional state.
@startuml
state "Req(Id)" as ReqId <<sdlreceive>>
state "Minor(Id)" as MinorId
state "Major(Id)" as MajorId
state c <<choice>>
Idle --> ReqId
ReqId --> c
c --> MinorId : [Id <= 10]
c --> MajorId : [Id > 10]
@enduml
@startuml
state start1 <<start>>
state choice1 <<choice>>
state fork1 <<fork>>
state join2 <<join>>
state end3 <<end>>
[*] --> choice1 : from start\nto choice
start1 --> choice1 : from start stereo\nto choice
choice1 --> fork1 : from choice\nto fork
choice1 --> join2 : from choice\nto join
choice1 --> end3 : from choice\nto end stereo
fork1 ---> State1 : from fork\nto state
fork1 --> State2 : from fork\nto state
State2 --> join2 : from state\nto join
State1 --> [*] : from state\nto end
join2 --> [*] : from join\nto end
@enduml
[Ref. QA-404, QA-1159 and GH-887]
@startuml
state A {
state s1 as "Start 1" <<start>>
state s2 as "H 2" <<history>>
state s3 as "H 3" <<history*>>
}
@enduml
[Ref. QA-16824]
@startuml
state start1 <<start>>
state choice1 <<choice>>
state fork1 <<fork>>
state join2 <<join>>
state end3 <<end>>
state sdlreceive <<sdlreceive>>
state history <<history>>
state history2 <<history*>>
@enduml
[Ref. QA-19174]
<<entryPoint>>
and <<exitPoint>>
stereotypes:
@startuml
state Somp {
state entry1 <<entryPoint>>
state entry2 <<entryPoint>>
state sin
entry1 --> sin
entry2 -> sin
sin -> sin2
sin2 --> exitA <<exitPoint>>
}
[*] --> entry1
exitA --> Foo
Foo1 -> entry2
@enduml
<<inputPin>>
and <<outputPin>>
stereotypes:
@startuml
state Somp {
state entry1 <<inputPin>>
state entry2 <<inputPin>>
state sin
entry1 --> sin
entry2 -> sin
sin -> sin2
sin2 --> exitA <<outputPin>>
}
[*] --> entry1
exitA --> Foo
Foo1 -> entry2
@enduml
[Ref. QA-4309]
<<expansionInput>>
and <<expansionOutput>>
stereotypes:
@startuml
state Somp {
state entry1 <<expansionInput>>
state entry2 <<expansionInput>>
state sin
entry1 --> sin
entry2 -> sin
sin -> sin2
sin2 --> exitA <<expansionOutput>>
}
[*] --> entry1
exitA --> Foo
Foo1 -> entry2
@enduml
[Ref. QA-4309]
->
for horizontal arrows. It is possible to
force arrow's direction using the following syntax:
-down->
or -->
-right->
or ->
(default arrow)-left->
-up->
@startuml
[*] -up-> First
First -right-> Second
Second --> Third
Third -left-> Last
@enduml
You can shorten the arrow definition by using only the first character of the direction (for example, -d-
instead of
-down-
)
or the two first characters (-do-
).
@startuml
State S1
State S2
S1 -[#DD00AA]-> S2
S1 -left[#yellow]-> S3
S1 -up[#red,dashed]-> S4
S1 -right[dotted,#blue]-> S5
X1 -[dashed]-> X2
Z1 -[dotted]-> Z2
Y1 -[#blue,bold]-> Y2
@enduml
[Ref. Incubation: Change line color in state diagrams]
note left of
, note right of
, note top of
, note bottom of
keywords.
You can also define notes on several lines.
@startuml
[*] --> Active
Active --> Inactive
note left of Active : this is a short\nnote
note right of Inactive
A note can also
be defined on
several lines
end note
@enduml
You can also have floating notes.
@startuml
state foo
note "This is a floating note" as N1
@enduml
note on link
keyword.
@startuml
[*] -> State1
State1 --> State2
note on link
this is a state-transition note
end note
@enduml
@startuml
[*] --> NotShooting
state "Not Shooting State" as NotShooting {
state "Idle mode" as Idle
state "Configuring mode" as Configuring
[*] --> Idle
Idle --> Configuring : EvConfig
Configuring --> Idle : EvConfig
}
note right of NotShooting : This is a note on a composite state
@enduml
@startuml
state CurrentSite #pink {
state HardwareSetup #lightblue {
state Site #brown
Site -[hidden]-> Controller
Controller -[hidden]-> Devices
}
state PresentationSetup{
Groups -[hidden]-> PlansAndGraphics
}
state Trends #FFFF77
state Schedule #magenta
state AlarmSupression
}
@enduml
[Ref. QA-1812]
@startuml
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
@startuml
skinparam State {
AttributeFontColor blue
AttributeFontName serif
AttributeFontSize 9
AttributeFontStyle italic
BackgroundColor palegreen
BorderColor violet
EndColor gold
FontColor red
FontName Sanserif
FontSize 15
FontStyle bold
StartColor silver
}
state A : a a a\na
state B : b b b\nb
[*] -> A : start
A -> B : a2b
B -> [*] : end
@enduml
@startuml
<style>
stateDiagram {
BackgroundColor Peru
'LineColor Gray
FontName Impact
FontColor Red
arrow {
FontSize 13
LineColor Blue
}
}
</style>
[*] --> 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
@startuml
<style>
diamond {
BackgroundColor #palegreen
LineColor #green
LineThickness 2.5
}
</style>
state state1
state state2
state choice1 <<choice>>
state end3 <<end>>
state1 --> choice1 : 1
choice1 --> state2 : 2
choice1 --> end3 : 3
@enduml
[Ref. GH-880]
#color ##[style]color
#color
), then line style and line color (##[style]color
).
@startuml
state FooGradient #red-green ##00FFFF
state FooDashed #red|green ##[dashed]blue {
}
state FooDotted ##[dotted]blue {
}
state FooBold ##[bold] {
}
state Foo1 ##[dotted]green {
state inner1 ##[dotted]yellow
}
state out ##[dotted]gold
state Foo2 ##[bold]green {
state inner2 ##[dotted]yellow
}
inner1 -> inner2
out -> inner2
@enduml
[Ref. QA-1487]
#color;line:color;line.[bold|dashed|dotted];text:color
text:color
seems not to be taken into account
@startuml
@startuml
state FooGradient #red-green;line:00FFFF
state FooDashed #red|green;line.dashed;line:blue {
}
state FooDotted #line.dotted;line:blue {
}
state FooBold #line.bold {
}
state Foo1 #line.dotted;line:green {
state inner1 #line.dotted;line:yellow
}
state out #line.dotted;line:gold
state Foo2 #line.bold;line:green {
state inner2 #line.dotted;line:yellow
}
inner1 -> inner2
out -> inner2
@enduml
@enduml
@startuml
state s1 : s1 description
state s2 #pink;line:red;line.bold;text:red : s2 description
state s3 #palegreen;line:green;line.dashed;text:green : s3 description
state s4 #aliceblue;line:blue;line.dotted;text:blue : s4 description
@enduml
[Adapted from QA-3770]
alias
, like:
@startuml
state alias1
state "alias2"
state "long name" as alias3
state alias4 as "long name"
alias1 : ""state alias1""
alias2 : ""state "alias2"""
alias3 : ""state "long name" as alias3""
alias4 : ""state alias4 as "long name"""
alias1 -> alias2
alias2 -> alias3
alias3 -> alias4
@enduml
or:
@startuml
state alias1 : ""state alias1""
state "alias2" : ""state "alias2"""
state "long name" as alias3 : ""state "long name" as alias3""
state alias4 as "long name" : ""state alias4 as "long name"""
alias1 -> alias2
alias2 -> alias3
alias3 -> alias4
@enduml
[Ref. QA-1748, QA-14560]
@startuml
state "A" as stateA
state "C" as stateC {
state B
}
json jsonJ {
"fruit":"Apple",
"size":"Large",
"color": ["Red", "Green"]
}
@enduml
[Ref. QA-17275] For another example, see on JSON page.
@startuml
hide empty description
state s0
state "This is the State 1" as s1 {
s1: State description
state s2
state s3: long descr.
state s4
s4: long descr.
}
[*] -> s0
s0 --> s2
s2 -> s3
s3 -> s4
@enduml
[Ref. QA-16719]
@startuml
<style>
.foo {
state,stateBody {
BackGroundColor lightblue;
}
}
</style>
state MainState <<foo>> {
state SubA
}
@enduml
[Ref. QA-16774]