Vous devez utiliser [*] pour le début et la fin du diagramme d'état. Utilisez --> pour les flèches.
@startuml
[*] --> State1
State1 --> [*]
State1 : this is a string
State1 : this is another string
State1 -> State2
State2 --> [*]
@enduml
Autre rendu
Il est possible d'utiliser la directive hide empty description pour afficher l'état de façon plus compact.
@startuml
hide empty description
[*] --> State1
State1 --> [*]
State1 : this is a string
State1 : this is another string
State1 -> State2
State2 --> [*]
@enduml
État composite
Un état peut également être composite. Vous devez alors le définir avec le mot-clé state et des accolades.
Le stéréotype <<choice>> peut être utilisé pour signifier des états conditionnels.
@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
Exemple avec tous les stéréotypes [choice, fork, join, end]
@startuml
state choice1 <<choice>>
state fork1 <<fork>>
state join2 <<join>>
state end3 <<end>>
[*] --> choice1 : de ""start""\nà ""choice""
choice1 --> fork1 : de ""choice""\nà ""fork""
choice1 --> join2 : de ""choice""\nà ""join""
choice1 --> end3 : de ""choice""\nà ""end""
fork1 ---> State1 : de ""fork""\nà ""state""
fork1 --> State2 : de ""fork""\nà ""state""
State2 --> join2 : de ""state""\nà ""join""
State1 --> [*] : de ""state""\nà ""end""
join2 --> [*] : de ""join""\nà ""end""
@enduml
Vous pouvez ajouter de petits cercles [point] avec les stéréotypes <<entryPoint>> et <<exitPoint>> :
@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
Petits carrés [inputPin, outputPin]
Vous pouvez ajouter de petits carrés [pin] avec les stéréotypes <<inputPin>> et <<outputPin>> :
@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
Vous pouvez ajouter de multiples petits carrés [expansion] avec les stéréotypes <<expansionInput>> et <<expansionOutput>> :
@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
Vous pouvez utiliser -> pour les flèches horizontales. Il est aussi possible de forcer la direction de la flèche avec la syntaxe suivante:
-down->(flèche par défaut)
-right-> or ->
-left->
-up->
@startuml
[*] -up-> First
First -right-> Second
Second --> Third
Third -left-> Last
@enduml
Vous pouvez aussi utiliser une notation abrégée, avec soit le premier caractère de la direction (par exemple -d- à la place de -down-) ou bien les deux premiers caractères (-do-).
Veuillez noter qu'il ne faut pas abuser de cette fonction : Graphviz donne généralement de bons résultats sans peaufinage.
Changer la couleur ou le style des flèches
Vous pouvez modifier la couleur et/ou le style des flèches.
Vous pouvez définir des notes avec les mots clés suivant: note left of, note right of, note top of, note bottom of Vous pouvez aussi définir des notes sur plusieurs lignes.
@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
Vous pouvez aussi avoir des notes flottantes.
@startuml
state foo
note "This is a floating note" as N1
@enduml
Note sur un lien
Vous pouvez ajouter une note sur un lien entre états avec le mot clé note on link.
@startuml
[*] -> State1
State1 --> State2
note on link
this is a state-transition note
end note
@enduml
Plus de notes
Vous pouvez mettre des notes sur les états de composite
@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
Changer les couleurs localement [Inline color]
@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
@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
Change state color and style (inline style)
You can change the color or style of individual state using the following notation:
#color ##[style]color
With background color first (#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
@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