2024-03-23 11:39:02 +05:30
|
|
|
<!doctype html>
|
2022-11-21 16:59:55 -08:00
|
|
|
<html lang="en" xmlns="http://www.w3.org/1999/html">
|
2022-09-05 00:48:36 +05:30
|
|
|
<head>
|
|
|
|
<meta charset="utf-8" />
|
|
|
|
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
|
2022-09-26 18:16:36 -07:00
|
|
|
<title>States Mermaid Quick Test Page</title>
|
2022-09-05 00:48:36 +05:30
|
|
|
<link rel="icon" type="image/png" href="data:image/png;base64,iVBORw0KGgo=" />
|
|
|
|
<style>
|
|
|
|
div.mermaid {
|
|
|
|
/* font-family: 'trebuchet ms', verdana, arial; */
|
|
|
|
font-family: 'Courier New', Courier, monospace !important;
|
|
|
|
}
|
|
|
|
</style>
|
|
|
|
</head>
|
|
|
|
|
|
|
|
<body>
|
2022-10-02 13:51:25 -07:00
|
|
|
<h1>State diagram demos</h1>
|
2022-10-10 18:25:33 -07:00
|
|
|
<h2>Very simple showing change from State1 to State2</h2>
|
2022-09-05 00:48:36 +05:30
|
|
|
<pre class="mermaid">
|
2022-11-27 18:25:37 +00:00
|
|
|
---
|
|
|
|
title: Very simple diagram
|
|
|
|
---
|
|
|
|
stateDiagram
|
|
|
|
accTitle: This is the accessible title
|
2022-09-26 18:16:36 -07:00
|
|
|
accDescr:This is an accessible description
|
|
|
|
State1 --> State2
|
2022-09-05 00:48:36 +05:30
|
|
|
</pre>
|
2022-04-08 18:43:00 +00:00
|
|
|
|
2022-09-26 18:16:36 -07:00
|
|
|
<hr />
|
|
|
|
|
2022-10-10 18:25:33 -07:00
|
|
|
<h2>This has classDef statements to apply style classes to specific states</h2>
|
|
|
|
<h4>Here are the <code>classDef</code> statements:</h4>
|
|
|
|
<p>
|
|
|
|
<code>
|
|
|
|
classDef notMoving fill:white<br />
|
2022-11-21 16:59:55 -08:00
|
|
|
classDef movement font-style:italic<br />
|
|
|
|
classDef badBadEvent
|
|
|
|
fill:#f00,color:white,font-weight:bold,stroke-width:2px,stroke:yellow<br />
|
2022-10-10 18:25:33 -07:00
|
|
|
</code>
|
|
|
|
</p>
|
|
|
|
<h4>And these are how they are applied:</h4>
|
|
|
|
<p>
|
|
|
|
<code>
|
|
|
|
class Still notMoving<br />
|
|
|
|
class Moving, Crash movement<br />
|
|
|
|
class Crash badBadEvent<br />
|
|
|
|
</code>
|
|
|
|
</p>
|
2022-09-05 00:48:36 +05:30
|
|
|
<pre class="mermaid">
|
2022-11-27 18:25:37 +00:00
|
|
|
---
|
|
|
|
title: Very simple diagram
|
|
|
|
---
|
|
|
|
stateDiagram
|
2022-11-21 16:59:55 -08:00
|
|
|
direction TB
|
|
|
|
|
2022-11-27 18:25:37 +00:00
|
|
|
accTitle: This is the accessible title
|
2022-09-26 18:16:36 -07:00
|
|
|
accDescr: This is an accessible description
|
2022-10-10 18:25:33 -07:00
|
|
|
|
|
|
|
classDef notMoving fill:white
|
2022-11-21 16:59:55 -08:00
|
|
|
classDef movement font-style:italic
|
|
|
|
classDef badBadEvent fill:#f00,color:white,font-weight:bold,stroke-width:2px,stroke:yellow
|
2022-10-10 18:25:33 -07:00
|
|
|
|
2022-11-21 16:59:55 -08:00
|
|
|
[*]--> Still
|
2022-09-26 18:16:36 -07:00
|
|
|
Still --> [*]
|
|
|
|
Still --> Moving
|
|
|
|
Moving --> Still
|
|
|
|
Moving --> Crash
|
|
|
|
Crash --> [*]
|
2022-10-10 18:25:33 -07:00
|
|
|
|
|
|
|
class Still notMoving
|
|
|
|
class Moving, Crash movement
|
|
|
|
class Crash badBadEvent
|
2022-11-21 16:59:55 -08:00
|
|
|
class end badBadEvent
|
2022-09-26 18:16:36 -07:00
|
|
|
</pre>
|
|
|
|
|
|
|
|
<hr />
|
|
|
|
|
2022-11-21 16:59:55 -08:00
|
|
|
<h2>Here is a diagram that uses the ::: operator to apply styles to states</h2>
|
|
|
|
<h4>Here are the <code>classDef</code> statements:</h4>
|
|
|
|
<p>
|
|
|
|
<code>
|
|
|
|
classDef notMoving fill:white<br />
|
|
|
|
classDef movement font-style:italic<br />
|
|
|
|
classDef badBadEvent
|
|
|
|
fill:#f00,color:white,font-weight:bold,stroke-width:2px,stroke:yellow<br />
|
|
|
|
</code>
|
|
|
|
</p>
|
|
|
|
<h4>And these are how they are applied:</h4>
|
|
|
|
<p>
|
|
|
|
<code>
|
|
|
|
[*] --> Still:::notMoving<br />
|
|
|
|
...<br />
|
|
|
|
Still --> Moving:::movement<br />
|
|
|
|
...<br />
|
|
|
|
Moving --> Crash:::movement<br />
|
|
|
|
Crash:::badBadEvent --> [*]<br />
|
|
|
|
</code>
|
|
|
|
</p>
|
|
|
|
<p>
|
|
|
|
Note that both the starting state and the end state have styles applied:<br />
|
|
|
|
The start state has the <i>start</i> classDef style<br />and the end state has the
|
|
|
|
<i>stop</i> classDef style applied.
|
|
|
|
</p>
|
|
|
|
<pre class="mermaid">
|
|
|
|
stateDiagram
|
|
|
|
direction TB
|
|
|
|
|
|
|
|
accTitle: This is the accessible title
|
|
|
|
accDescr: This is an accessible description
|
|
|
|
|
|
|
|
classDef notMoving fill:white
|
|
|
|
classDef movement font-style:italic
|
|
|
|
classDef badBadEvent fill:#f00,color:white,font-weight:bold,stroke-width:2px,stroke:yellow
|
|
|
|
|
|
|
|
[*] --> Still:::notMoving
|
|
|
|
Still --> [*]
|
|
|
|
Still --> Moving:::movement
|
|
|
|
Moving --> Still
|
|
|
|
Moving --> Crash:::movement
|
|
|
|
Crash:::badBadEvent --> [*]
|
|
|
|
</pre>
|
|
|
|
<hr />
|
|
|
|
|
2022-09-26 18:16:36 -07:00
|
|
|
<pre class="mermaid">
|
2022-10-11 08:34:30 -07:00
|
|
|
stateDiagram-v2
|
2022-09-26 18:16:36 -07:00
|
|
|
accTitle: very very simple state
|
2022-11-17 15:49:37 -08:00
|
|
|
accDescr: This is a state diagram showing one state
|
|
|
|
State1
|
2022-09-26 18:16:36 -07:00
|
|
|
</pre>
|
2022-10-11 08:34:30 -07:00
|
|
|
<hr />
|
2022-09-26 18:16:36 -07:00
|
|
|
|
2022-11-21 16:59:55 -08:00
|
|
|
<h2>States with spaces in them</h2>
|
|
|
|
<pre class="mermaid">
|
|
|
|
stateDiagram
|
|
|
|
classDef yourState font-style:italic,font-weight:bold,fill:white
|
|
|
|
|
|
|
|
yswsii: Your state with spaces in it
|
|
|
|
[*] --> yswsii:::yourState
|
|
|
|
[*] --> SomeOtherState
|
|
|
|
SomeOtherState --> YetAnotherState
|
|
|
|
yswsii --> YetAnotherState
|
|
|
|
YetAnotherState --> [*]
|
|
|
|
</pre>
|
|
|
|
<hr />
|
|
|
|
|
2022-10-11 08:34:30 -07:00
|
|
|
<h2>You can label the relationships</h2>
|
|
|
|
<pre class="mermaid">
|
|
|
|
stateDiagram-v2
|
|
|
|
[*] --> State1
|
|
|
|
State1 --> State2 : Transition 1
|
|
|
|
State1 --> State3 : Transition 2
|
|
|
|
State1 --> State4 : Transition 3
|
|
|
|
State1 --> [*]
|
|
|
|
</pre>
|
2022-09-26 18:16:36 -07:00
|
|
|
<hr />
|
2022-10-11 08:34:30 -07:00
|
|
|
|
2022-10-10 18:25:33 -07:00
|
|
|
<h2>This shows Composite states</h2>
|
2022-09-26 18:16:36 -07:00
|
|
|
<pre class="mermaid">
|
2022-10-10 18:25:33 -07:00
|
|
|
stateDiagram-v2
|
2022-09-26 18:16:36 -07:00
|
|
|
[*] --> First
|
2022-10-10 18:25:33 -07:00
|
|
|
First --> Second
|
|
|
|
First --> Third
|
|
|
|
|
2022-12-09 16:01:13 -08:00
|
|
|
state "the first composite" as First {
|
2022-10-10 18:25:33 -07:00
|
|
|
[*] --> 1st
|
2022-12-09 16:01:13 -08:00
|
|
|
state innerFirst {
|
|
|
|
state "1 in innerFirst" as 1st1st
|
|
|
|
1st2nd: 2 in innerFirst
|
|
|
|
[*] --> 1st1st
|
|
|
|
1st1st --> 1st2nd
|
|
|
|
%% 1st2nd --> 1st
|
|
|
|
}
|
|
|
|
1st --> innerFirst
|
|
|
|
innerFirst --> 2nd
|
2022-10-10 18:25:33 -07:00
|
|
|
}
|
|
|
|
state Second {
|
|
|
|
2nd --> [*]
|
2022-09-26 18:16:36 -07:00
|
|
|
}
|
2022-10-10 18:25:33 -07:00
|
|
|
state Third {
|
|
|
|
[*] --> 3rd
|
|
|
|
3rd --> [*]
|
|
|
|
}
|
2022-10-11 08:34:30 -07:00
|
|
|
</pre>
|
|
|
|
<hr />
|
2022-10-10 18:25:33 -07:00
|
|
|
|
2023-10-07 22:16:11 -03:00
|
|
|
<h2>Composite states can link to themselves</h2>
|
2022-10-11 08:34:30 -07:00
|
|
|
<pre class="mermaid">
|
|
|
|
stateDiagram-v2
|
|
|
|
state Active {
|
|
|
|
Idle
|
|
|
|
}
|
|
|
|
Inactive --> Idle: ACT
|
|
|
|
Active --> Active: LOG
|
2022-09-26 18:16:36 -07:00
|
|
|
</pre>
|
2022-10-11 08:34:30 -07:00
|
|
|
<hr />
|
|
|
|
|
|
|
|
<h2>transition labels can span multiple lines using "br" tags or \n</h2>
|
2022-09-26 18:16:36 -07:00
|
|
|
<pre class="mermaid">
|
2022-10-11 08:34:30 -07:00
|
|
|
stateDiagram-v2
|
|
|
|
[*] --> S1
|
2022-11-21 16:59:55 -08:00
|
|
|
S1 --> S2: This long line uses a br tag<br />to create multiple<br />lines.
|
2023-10-07 22:16:11 -03:00
|
|
|
S1 --> S3: This transition description uses \na newline character\nto create multiple\nlines.
|
2022-10-11 08:34:30 -07:00
|
|
|
|
2022-09-26 18:16:36 -07:00
|
|
|
</pre>
|
2022-10-11 08:34:30 -07:00
|
|
|
<hr />
|
|
|
|
|
|
|
|
<h2>You can add Notes</h2>
|
2022-09-26 18:16:36 -07:00
|
|
|
<pre class="mermaid">
|
2022-10-11 08:34:30 -07:00
|
|
|
stateDiagram-v2
|
|
|
|
direction LR
|
|
|
|
State1: A state with a note
|
|
|
|
note right of State1
|
2022-11-21 16:59:55 -08:00
|
|
|
Important information!<br />You can write notes.<br />And\nthey\ncan\nbe\nmulti-\nline.
|
2022-10-11 08:34:30 -07:00
|
|
|
end note
|
|
|
|
State1 --> State2
|
|
|
|
note left of State2 : Notes can be to the left of a state\n(like this one).
|
|
|
|
note right of State2 : Notes can be to the right of a state\n(like this one).
|
2022-09-05 00:48:36 +05:30
|
|
|
</pre>
|
2022-10-11 08:34:30 -07:00
|
|
|
<hr />
|
2022-09-05 00:48:36 +05:30
|
|
|
|
2023-02-19 14:03:11 +05:30
|
|
|
<script type="module">
|
|
|
|
import mermaid from './mermaid.esm.mjs';
|
2022-09-05 00:48:36 +05:30
|
|
|
mermaid.initialize({
|
2022-10-11 08:34:30 -07:00
|
|
|
theme: 'default',
|
2022-09-05 00:48:36 +05:30
|
|
|
// themeCSS: '.node rect { fill: red; }',
|
|
|
|
logLevel: 3,
|
|
|
|
securityLevel: 'loose',
|
|
|
|
flowchart: { curve: 'basis' },
|
|
|
|
gantt: { axisFormat: '%m/%d/%Y' },
|
|
|
|
sequence: { actorMargin: 50 },
|
|
|
|
// sequenceDiagram: { actorMargin: 300 } // deprecated
|
|
|
|
});
|
|
|
|
</script>
|
|
|
|
</body>
|
2022-04-07 21:35:13 +00:00
|
|
|
</html>
|