From f63708c003fca4f59af81e39ef39d04238cabfab Mon Sep 17 00:00:00 2001 From: nimec01 <24428341+nimec01@users.noreply.github.com> Date: Wed, 7 Aug 2024 21:54:46 +0200 Subject: [PATCH] feat: add history nodes to state diagram --- .cspell/mermaid-terms.txt | 1 + .../rendering/stateDiagram-v2.spec.js | 35 +++++++++++ demos/state.html | 31 ++++++++++ docs/syntax/stateDiagram.md | 62 +++++++++++++++++++ packages/mermaid/src/dagre-wrapper/nodes.js | 43 +++++++++++++ .../diagrams/state/parser/stateDiagram.jison | 10 +++ packages/mermaid/src/diagrams/state/styles.js | 6 ++ .../mermaid/src/docs/syntax/stateDiagram.md | 33 ++++++++++ 8 files changed, 221 insertions(+) diff --git a/.cspell/mermaid-terms.txt b/.cspell/mermaid-terms.txt index 3fa5eff2699..b64714e94e8 100644 --- a/.cspell/mermaid-terms.txt +++ b/.cspell/mermaid-terms.txt @@ -4,6 +4,7 @@ bmatrix braintree catmull compositTitleSize +deephistory doublecircle elems gantt diff --git a/cypress/integration/rendering/stateDiagram-v2.spec.js b/cypress/integration/rendering/stateDiagram-v2.spec.js index cb40aa8dc0d..83d857a53bf 100644 --- a/cypress/integration/rendering/stateDiagram-v2.spec.js +++ b/cypress/integration/rendering/stateDiagram-v2.spec.js @@ -330,6 +330,41 @@ describe('State diagram', () => { } ); }); + it('v2 it should be possible to use a (deep) history node', () => { + imgSnapshotTest( + ` + stateDiagram-v2 + state "A" as A { + state "B" as B + state "C" as C + state A_History [[history]] + + B --> C + C --> B + } + state "D" as D { + state "E" as E { + state "F" as F + state "G" as G + + F --> G + G --> F + } + state "I" as I + state D_History [[deephistory]] + + E --> I + I --> E + } + + G --> A_History + A --> D_History + `, + { + logLevel: 0, + } + ); + }); it('v2 A compound state should be able to link to itself', () => { imgSnapshotTest( ` diff --git a/demos/state.html b/demos/state.html index aaa8e0aa990..9cdcbf720f2 100644 --- a/demos/state.html +++ b/demos/state.html @@ -218,6 +218,37 @@
+ stateDiagram-v2 + state "A" as A { + state "B" as B + state "C" as C + state A_History [[history]] + + B --> C + C --> B + } + state "D" as D { + state "E" as E { + state "F" as F + state "G" as G + + F --> G + G --> F + } + state "I" as I + state D_History [[deephistory]] + + E --> I + I --> E + } + + G --> A_History + A --> D_History ++