From d72851bf51a4ef5c23242d1d1eae7f5e9fa62eb8 Mon Sep 17 00:00:00 2001 From: nimec01 <24428341+nimec01@users.noreply.github.com> Date: Sat, 2 Nov 2024 15:55:51 +0100 Subject: [PATCH] add history node --- .cspell/mermaid-terms.txt | 1 + .../rendering/stateDiagram-v2.spec.js | 70 +++++++++++++++++++ demos/state.html | 31 ++++++++ docs/syntax/flowchart.md | 2 + docs/syntax/stateDiagram.md | 62 ++++++++++++++++ packages/mermaid/scripts/docs.spec.ts | 2 + .../diagrams/state/parser/stateDiagram.jison | 14 ++++ packages/mermaid/src/diagrams/state/styles.js | 5 ++ .../mermaid/src/docs/syntax/stateDiagram.md | 33 +++++++++ .../rendering-elements/shapes.ts | 17 +++++ .../rendering-elements/shapes/history.ts | 61 ++++++++++++++++ 11 files changed, 298 insertions(+) create mode 100644 packages/mermaid/src/rendering-util/rendering-elements/shapes/history.ts diff --git a/.cspell/mermaid-terms.txt b/.cspell/mermaid-terms.txt index cb6db41dec..2d7d48d326 100644 --- a/.cspell/mermaid-terms.txt +++ b/.cspell/mermaid-terms.txt @@ -6,6 +6,7 @@ braintree catmull compositTitleSize curv +deephistory doublecircle elems gantt diff --git a/cypress/integration/rendering/stateDiagram-v2.spec.js b/cypress/integration/rendering/stateDiagram-v2.spec.js index 606a1a3f57..810e9533c7 100644 --- a/cypress/integration/rendering/stateDiagram-v2.spec.js +++ b/cypress/integration/rendering/stateDiagram-v2.spec.js @@ -330,6 +330,76 @@ 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 it should be possible to use a (deep) history node shorthand', () => { + imgSnapshotTest( + ` + stateDiagram-v2 + state "A" as A { + state "B" as B + state "C" as C + state A_History [[H]] + + 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 [[H*]] + + 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 aaa8e0aa99..c6d012458d 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 [[H]] + + 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 [[H*]] + + E --> I + I --> E + } + + G --> A_History + A --> D_History ++