diff --git a/docs/stateDiagram.md b/docs/stateDiagram.md index d3c625a85..239680a09 100755 --- a/docs/stateDiagram.md +++ b/docs/stateDiagram.md @@ -2,10 +2,9 @@ > "A state diagram is a type of diagram used in computer science and related fields to describe the behavior of systems. State diagrams require that the system described is composed of a finite number of states; sometimes, this is indeed the case, while at other times this is a reasonable abstraction." Wikipedia -Mermaid can render state diagrams. The syntax tries to be compliant with the syntax used in plantUml as this will make it easier for users to -share diagrams between mermaid and plantUml. +Mermaid can render state diagrams. The syntax tries to be compliant with the syntax used in plantUml as this will make it easier for users to share diagrams between mermaid and plantUml. -``` +```markdown stateDiagram [*] --> Still Still --> [*] @@ -15,6 +14,7 @@ stateDiagram Moving --> Crash Crash --> [*] ``` + ```mermaid stateDiagram [*] --> Still @@ -25,53 +25,58 @@ stateDiagram Moving --> Crash Crash --> [*] ``` + In state diagrams systems are described in terms of its states and how the systems state can change to another state via a transitions. The example diagram above shows three states **Still**, **Moving** and **Crash**. You start in the state of Still. From Still you can change the state to Moving. In Moving you can change the state either back to Still or to Crash. There is no transition from Still to Crash. ## States A state can be declares in multiple ways. The simplest way is to define a state id as a description. -``` +```markdown stateDiagram s1 ``` + ```mermaid stateDiagram s1 ``` Another way is by using the state keyword with a description as per below: -``` + +```markdown stateDiagram - state "This ia state decription" as s2 + state "This is a state description" as s2 ``` + ```mermaid stateDiagram - state "This ia state decription" as s2 + state "This is a state description" as s2 ``` Another way to define a state with a description is to define the state id followed by a colon and the description: -``` + +```markdown stateDiagram - s2 : This ia state decription -``` -```mermaid -stateDiagram - s2 : This ia state decription + s2 : This is a state description ``` +```mermaid +stateDiagram + s2 : This is a state description +``` ## Transitions -Transitions are path/edges when one state passes into another. This is represented using text arrow, "-->". +Transitions are path/edges when one state passes into another. This is represented using text arrow, "\-\-\>". -When you define a transition between two states and the states are not already defined the undefined states are defined with the id -from the transition. You can later add descriptions to states defined this way. +When you define a transition between two states and the states are not already defined the undefined states are defined with the id from the transition. You can later add descriptions to states defined this way. -``` +```markdown stateDiagram s1 --> s2 ``` + ```mermaid stateDiagram s1 --> s2 @@ -79,39 +84,40 @@ stateDiagram It is possible to add text to a transition. To describe what it represents. -``` +```markdown stateDiagram s1 --> s2: A transition ``` + ```mermaid stateDiagram s1 --> s2: A transition ``` -## Start and end +## Start and End -There are two special states indicating the start and stop of the diagram. These are written with the [*] syntax and the direction of the transition to it defines it either as a start or a stop state. +There are two special states indicating the start and stop of the diagram. These are written with the [\*] syntax and the direction of the transition to it defines it either as a start or a stop state. -``` +```markdown stateDiagram [*] --> s1 s1 --> [*] ``` + ```mermaid stateDiagram [*] --> s1 s1 --> [*] ``` - -## Composit states +## Composite states In a real world use of state diagrams you often end up with diagrams that are multi-dimensional as one state can -have several internal states. These are called composit states in this terminology. +have several internal states. These are called composite states in this terminology. -In order to define a composit state you need to use the state keyword followed by and id and the body of the composit state between {}. See the example below: +In order to define a composite state you need to use the state keyword followed by and id and the body of the composite state between \{\}. See the example below: -``` +```markdown stateDiagram [*] --> First state First { @@ -119,6 +125,7 @@ stateDiagram second --> [*] } ``` + ```mermaid stateDiagram [*] --> First @@ -130,7 +137,7 @@ stateDiagram You can do this in several layers: -``` +```markdown stateDiagram [*] --> First @@ -148,6 +155,7 @@ stateDiagram } } ``` + ```mermaid stateDiagram [*] --> First @@ -166,9 +174,9 @@ stateDiagram } ``` -You can also define transitions also between composit states: +You can also define transitions also between composite states: -``` +```markdown stateDiagram [*] --> First First --> Second @@ -187,6 +195,7 @@ stateDiagram thi --> [*] } ``` + ```mermaid stateDiagram [*] --> First @@ -207,13 +216,13 @@ stateDiagram } ``` -*You can not define transitions between internal states belonging to different composit states* +*You can not define transitions between internal states belonging to different composite states* ## Forks It is possible to specify a fork in the diagram using <<fork>> <<join>>. -``` +```markdown stateDiagram state fork_state <> [*] --> fork_state @@ -226,6 +235,7 @@ It is possible to specify a fork in the diagram using <<fork>> <& join_state --> State4 State4 --> [*] ``` + ```mermaid stateDiagram state fork_state <> @@ -247,7 +257,7 @@ Sometimes nothing says it better then a Post-it note. That is also the case in s Here you can choose to put the note to the *right of* or to the *left of* a node. -``` +```markdown stateDiagram State1: The state with a note note right of State1 @@ -257,6 +267,7 @@ Here you can choose to put the note to the *right of* or to the *left of* a node State1 --> State2 note left of State2 : This is the note to the left. ``` + ```mermaid stateDiagram State1: The state with a note @@ -272,7 +283,8 @@ Here you can choose to put the note to the *right of* or to the *left of* a node ## Concurrency As in plantUml you can specify concurrency using the -- symbol. -``` + +```markdown stateDiagram [*] --> Active @@ -291,7 +303,6 @@ As in plantUml you can specify concurrency using the -- symbol. } ``` - ```mermaid stateDiagram [*] --> Active