Multilingual Wiki Documentation

You are currently using syntax.
In an attempt to improve PlantUML documentation...
Please do not use this website for your own diagrams.
You can click here and use the online server here for your own documentation.

Wiki Toc    View page history    Add new chapter    Reorder page    Raw


Diagramme d'état

State Diagram

Les diagrammes d'état fournissent une représentation visuelle des différents états dans lesquels un système ou un objet peut se trouver, ainsi que des transitions entre ces états. Ils sont essentiels pour modéliser le comportement dynamique des systèmes, en saisissant la manière dont ils réagissent à différents événements au fil du temps. Les diagrammes d'état décrivent le cycle de vie du système, ce qui facilite la compréhension, la conception et l'optimisation de son comportement.

Utilisation de PlantUML pour créer des diagrammes d'état offre plusieurs avantages :
  • Langage basé sur le texte: Définir et visualiser rapidement les états et les transitions sans les inconvénients du dessin manuel.
  • Efficacité et cohérence: Assurez une création de diagramme rationalisée et un contrôle de version facile.
  • Polyvalence: S'intègre à diverses plates-formes de documentation et prend en charge plusieurs formats de sortie.
  • Open-Source & Community Support: Soutenu par une communauté solide qui contribue continuellement à ses améliorations et offre des ressources inestimables.

State diagrams provide a visual representation of the various states a system or an object can be in, as well as the transitions between those states. They are essential in modeling the dynamic behavior of systems, capturing how they respond to different events over time. State diagrams depict the system's life cycle, making it easier to understand, design, and optimize its behavior.

Using PlantUML to create state diagrams offers several advantages:
  • Text-Based Language: Quickly define and visualize the states and transitions without the hassle of manual drawing.
  • Efficiency and Consistency: Ensure streamlined diagram creation and easy version control.
  • Versatility: Integrate with various documentation platforms and support multiple output formats.
  • Open-Source & Community Support: Backed by a strong community that continuously contributes to its enhancements and offers invaluable resources.

Exemple simple

Simple State

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

You can use [*] for the starting point and ending point of the state diagram.

Use --> for arrows.

@startuml

[*] --> State1
State1 --> [*]
State1 : this is a string
State1 : this is another string

State1 -> State2
State2 --> [*]

@enduml

Autre rendu

Change state rendering

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

You can use hide empty description to render state as simple box.

@startuml
hide empty description
[*] --> State1
State1 --> [*]
State1 : this is a string
State1 : this is another string

State1 -> State2
State2 --> [*]
@enduml

État composite

Composite state

Un état peut également être composite. Vous devez alors le définir avec le mot-clé state et des accolades.

Sous-état interne

@startuml
scale 350 width
[*] --> NotShooting

state NotShooting {
  [*] --> Idle
  Idle --> Configuring : EvConfig
  Configuring --> Idle : EvConfig
}

state Configuring {
  [*] --> NewValueSelection
  NewValueSelection --> NewValuePreview : EvNewValue
  NewValuePreview --> NewValueSelection : EvNewValueRejected
  NewValuePreview --> NewValueSelection : EvNewValueSaved

  state NewValuePreview {
     State1 -> State2
  }

}
@enduml

Lien entre sous-états

@startuml
state A {
  state X {
  }
  state Y {
  }
}
 
state B {
  state Z {
  }
}

X --> Z
Z --> Y
@enduml

[Ref. QA-3300]

WARNING
 This translation need to be updated. 
WARNING

A state can also be composite. You have to define it using the state keywords and brackets.

Internal sub-state

@startuml
scale 350 width
[*] --> NotShooting

state NotShooting {
  [*] --> Idle
  Idle --> Configuring : EvConfig
  Configuring --> Idle : EvConfig
}

state Configuring {
  [*] --> NewValueSelection
  NewValueSelection --> NewValuePreview : EvNewValue
  NewValuePreview --> NewValueSelection : EvNewValueRejected
  NewValuePreview --> NewValueSelection : EvNewValueSaved

  state NewValuePreview {
     State1 -> State2
  }

}
@enduml

Sub-state to sub-state

@startuml
state A {
  state X {
  }
  state Y {
  }
}
 
state B {
  state Z {
  }
}

X --> Z
Z --> Y
@enduml

[Ref. QA-3300]

@startuml
state A.X
state A.Y
 
state B.Z

X --> Z
Z --> Y
@enduml

Nom long

Long name

Vous pouvez aussi utiliser le mot-clé state pour donner un nom avec des espaces à un état.

@startuml
scale 600 width

[*] -> State1
State1 --> State2 : Succeeded
State1 --> [*] : Aborted
State2 --> State3 : Succeeded
State2 --> [*] : Aborted
state State3 {
  state "Accumulate Enough Data\nLong State Name" as long1
  long1 : Just a test
  [*] --> long1
  long1 --> long1 : New Data
  long1 --> ProcessData : Enough Data
}
State3 --> State3 : Failed
State3 --> [*] : Succeeded / Save Result
State3 --> [*] : Aborted

@enduml

You can also use the state keyword to use long description for states.

@startuml
scale 600 width

[*] -> State1
State1 --> State2 : Succeeded
State1 --> [*] : Aborted
State2 --> State3 : Succeeded
State2 --> [*] : Aborted
state State3 {
  state "Accumulate Enough Data\nLong State Name" as long1
  long1 : Just a test
  [*] --> long1
  long1 --> long1 : New Data
  long1 --> ProcessData : Enough Data
}
State3 --> State3 : Failed
State3 --> [*] : Succeeded / Save Result
State3 --> [*] : Aborted

@enduml

Historique de sous-état [[H], [H*]]

History [[H], [H*]]

Vous pouvez utiliser [H] pour l'historique et [H*] pour l'historique profond d'un sous-état.

@startuml
[*] -> State1
State1 --> State2 : Succeeded
State1 --> [*] : Aborted
State2 --> State3 : Succeeded
State2 --> [*] : Aborted
state State3 {
  state "Accumulate Enough Data" as long1
  long1 : Just a test
  [*] --> long1
  long1 --> long1 : New Data
  long1 --> ProcessData : Enough Data
  State2 --> [H]: Resume
}
State3 --> State2 : Pause
State2 --> State3[H*]: DeepResume
State3 --> State3 : Failed
State3 --> [*] : Succeeded / Save Result
State3 --> [*] : Aborted
@enduml

You can use [H] for the history and [H*] for the deep history of a substate.

@startuml
[*] -> State1
State1 --> State2 : Succeeded
State1 --> [*] : Aborted
State2 --> State3 : Succeeded
State2 --> [*] : Aborted
state State3 {
  state "Accumulate Enough Data" as long1
  long1 : Just a test
  [*] --> long1
  long1 --> long1 : New Data
  long1 --> ProcessData : Enough Data
  State2 --> [H]: Resume
}
State3 --> State2 : Pause
State2 --> State3[H*]: DeepResume
State3 --> State3 : Failed
State3 --> [*] : Succeeded / Save Result
State3 --> [*] : Aborted
@enduml

États parallèles [fork, join]

Fork [fork, join]

Il est possible d'afficher des états parallèles grâce aux stéréotypes <<fork>> et <<join>>.

@startuml

state fork_state <<fork>>
[*] --> fork_state
fork_state --> State2
fork_state --> State3

state join_state <<join>>
State2 --> join_state
State3 --> join_state
join_state --> State4
State4 --> [*]

@enduml

You can also fork and join using the <<fork>> and <<join>> stereotypes.

@startuml

state fork_state <<fork>>
[*] --> fork_state
fork_state --> State2
fork_state --> State3

state join_state <<join>>
State2 --> join_state
State3 --> join_state
join_state --> State4
State4 --> [*]

@enduml

États concurrents [--, ||]

Concurrent state [--, ||]

Vous pouvez définir un état concurrent dans un état composé en utilisant le symbole -- ou || comme séparateur.

Séparateur horizontal --

@startuml
[*] --> 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

Séparateur vertical ||

@startuml
[*] --> 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

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

You can define concurrent state into a composite state using either -- or || symbol as separator.

Horizontal separator --

@startuml
[*] --> Active

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

@enduml

Vertical separator ||

@startuml
[*] --> Active

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

@enduml

[Ref. QA-3086]

Conditionnel [choice]

Conditional [choice]

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

The stereotype <<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

Exemple avec tous les stéréotypes [choice, fork, join, end]

Stereotypes full example [start, choice, fork, join, end, history, history*]

@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

[Réf. QA-404 et QA-1159]

[Ref. QA-404, QA-1159 and GH-887]

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

Start, choice, fork, join, end

@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]

History, history*

@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]

Minimal example with all stereotypes

@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]

Petits cercles [entryPoint, exitPoint]

Point [entryPoint, exitPoint]

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

WARNING
 This translation need to be updated. 
WARNING

You can add point with <<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

Petits carrés [inputPin, outputPin]

Pin [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

[Réf. QA-4309]

WARNING
 This translation need to be updated. 
WARNING

You can add pin with <<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]

Multiples petits carrés [expansionInput, expansionOutput]

Expansion [expansionInput, expansionOutput]

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

[Réf. QA-4309]

WARNING
 This translation need to be updated. 
WARNING

You can add expansion with <<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]

Direction des flèches

Arrow direction

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.

You can use -> 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-).

Please note that you should not abuse this functionality : Graphviz gives usually good results without tweaking.

Changer la couleur ou le style des flèches

Change line color and style

Vous pouvez modifier la couleur et/ou le style des flèches.

@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

[Réf. Incubation: Change line color in state diagrams]

You can change line color and/or line style.

@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

Note

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

You can also define notes using 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 sur un lien

Note on link

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

You can put notes on state-transition or link, with note on link keyword.

@startuml
[*] -> State1
State1 --> State2
note on link 
  this is a state-transition note 
end note
@enduml

Plus de notes

More in 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

You can put notes on composite states.

@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]

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

[Réf. QA-1812]

@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]

Skinparam

Skinparam

Utilisez la commande skinparam pour changer la couleur et la mise en forme du texte du schéma.

Vous pouvez utiliser cette commande :

Vous pouvez définir une couleur spécifique et une police d'écriture pour les états stéréotypés.

@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

Test de tous les skinparam spécifiques aux diagrammes d'état:

@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

You can use the skinparam command to change colors and fonts for the drawing.

You can use this command : You can define specific color and fonts for stereotyped states.

@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

Test of all specific skinparam to State Diagrams

@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

Changement de style

Changing style

Vous pouvez changer de style

@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

*[Ref. [GH-880](https://github.com/plantuml/plantuml/issues/880#issuecomment-1022278138)]*
WARNING
 This translation need to be updated. 
WARNING

You can change style.

@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]

Modifier la couleur et le style d'un état (style en ligne)

Change state color and style (inline style)

Vous pouvez modifier la couleur ou le style d'un état individuel en utilisant la notation suivante

  • #color ##[style]color

Avec la couleur de fond d'abord (#color), puis le style de ligne et la couleur de ligne (##[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

[Réf. QA-1487]

  • #color;line:color;line.[bold|dashed|dotted];text:color

FIXME
🚩 text:color semble ne pas être pris en compte
FIXME

@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

[Adapté de QA-3770]

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

[Ref. QA-1487]

  • #color;line:color;line.[bold|dashed|dotted];text:color

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

@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

With State you can use 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]

Display JSON Data on State diagram

Simple example

@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.

State description

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

@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]

Style for Nested State Body

@startuml
<style>
.foo {
  state,stateBody {
    BackGroundColor lightblue;
  }
}
</style>

state MainState <<foo>> {
  state SubA
}
@enduml

[Ref. QA-16774]


Please report any bugs to plantuml@gmail.com or here.
This website is still in beta testing.