diff --git a/.changeset/tricky-dots-visit.md b/.changeset/tricky-dots-visit.md new file mode 100644 index 0000000000..9fdfcc724e --- /dev/null +++ b/.changeset/tricky-dots-visit.md @@ -0,0 +1,5 @@ +--- +'mermaid': minor +--- + +feat: add history nodes to state diagrams 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 ++