diff --git a/.build/common.ts b/.build/common.ts index efd0e3a85..2497d443f 100644 --- a/.build/common.ts +++ b/.build/common.ts @@ -33,6 +33,11 @@ export const packageOptions = { packageName: 'mermaid-layout-elk', file: 'layouts.ts', }, + 'mermaid-layout-tidy-tree': { + name: 'mermaid-layout-tidy-tree', + packageName: 'mermaid-layout-tidy-tree', + file: 'index.ts', + }, examples: { name: 'mermaid-examples', packageName: 'examples', diff --git a/.changeset/clean-wolves-turn.md b/.changeset/clean-wolves-turn.md new file mode 100644 index 000000000..7a44c1c16 --- /dev/null +++ b/.changeset/clean-wolves-turn.md @@ -0,0 +1,5 @@ +--- +'mermaid': patch +--- + +fix: Render newlines as spaces in class diagrams diff --git a/.changeset/crazy-loops-matter.md b/.changeset/crazy-loops-matter.md new file mode 100644 index 000000000..e6377a9e5 --- /dev/null +++ b/.changeset/crazy-loops-matter.md @@ -0,0 +1,5 @@ +--- +'mermaid': patch +--- + +fix: Handle arrows correctly when auto number is enabled diff --git a/.changeset/gold-olives-rule.md b/.changeset/gold-olives-rule.md deleted file mode 100644 index 6fe343774..000000000 --- a/.changeset/gold-olives-rule.md +++ /dev/null @@ -1,5 +0,0 @@ ---- -'mermaid': minor ---- - -feat: Add `getRegisteredDiagramsMetadata` to `mermaid`, which returns all the registered diagram IDs in mermaid diff --git a/.changeset/hungry-baths-glow.md b/.changeset/hungry-baths-glow.md new file mode 100644 index 000000000..b3084bcab --- /dev/null +++ b/.changeset/hungry-baths-glow.md @@ -0,0 +1,5 @@ +--- +'mermaid': minor +--- + +feat: Added support for new participant types (`actor`, `boundary`, `control`, `entity`, `database`, `collections`, `queue`) in `sequenceDiagram`. diff --git a/.changeset/hungry-guests-drive.md b/.changeset/hungry-guests-drive.md new file mode 100644 index 000000000..1b0e0a07b --- /dev/null +++ b/.changeset/hungry-guests-drive.md @@ -0,0 +1,7 @@ +--- +'mermaid': minor +'@mermaid-js/layout-tidy-tree': minor +'@mermaid-js/layout-elk': minor +--- + +feat: Update mindmap rendering to support multiple layouts, improved edge intersections, and new shapes diff --git a/.changeset/platinum-olives-rule.md b/.changeset/platinum-olives-rule.md deleted file mode 100644 index af70d6538..000000000 --- a/.changeset/platinum-olives-rule.md +++ /dev/null @@ -1,5 +0,0 @@ ---- -'@mermaid-js/examples': minor ---- - -feat: Add examples for diagrams in the `@mermaid-js/examples` package diff --git a/.changeset/pretty-falcons-say.md b/.changeset/pretty-falcons-say.md deleted file mode 100644 index f1a0a95c3..000000000 --- a/.changeset/pretty-falcons-say.md +++ /dev/null @@ -1,5 +0,0 @@ ---- -'mermaid': patch ---- - -chore: Updated TreeMapDB to use class based approach diff --git a/.changeset/revert-marked-dependency.md b/.changeset/revert-marked-dependency.md new file mode 100644 index 000000000..aded58871 --- /dev/null +++ b/.changeset/revert-marked-dependency.md @@ -0,0 +1,9 @@ +--- +'mermaid': patch +--- + +chore: revert marked dependency from ^15.0.7 to ^16.0.0 + +- Reverted marked package version to ^16.0.0 for better compatibility +- This is a dependency update that maintains API compatibility +- All tests pass with the updated version diff --git a/.changeset/slimy-peaches-win.md b/.changeset/slimy-peaches-win.md deleted file mode 100644 index a0b902e29..000000000 --- a/.changeset/slimy-peaches-win.md +++ /dev/null @@ -1,7 +0,0 @@ ---- -'@mermaid-js/examples': patch -'mermaid': patch -'@mermaid-js/parser': patch ---- - -chore: Move packet diagram out of beta diff --git a/.changeset/tangy-ghosts-watch.md b/.changeset/tangy-ghosts-watch.md deleted file mode 100644 index 9d69de4d0..000000000 --- a/.changeset/tangy-ghosts-watch.md +++ /dev/null @@ -1,5 +0,0 @@ ---- -'mermaid': patch ---- - -fix: adjust sequence diagram title positioning to prevent overlap with top border in Safari diff --git a/.changeset/weak-files-stare.md b/.changeset/weak-files-stare.md deleted file mode 100644 index c1a8d8f3a..000000000 --- a/.changeset/weak-files-stare.md +++ /dev/null @@ -1,5 +0,0 @@ ---- -'mermaid': patch ---- - -chore: Update MindmapDB to use class based approach diff --git a/.changeset/wild-areas-lick.md b/.changeset/wild-areas-lick.md deleted file mode 100644 index 3653c9b3d..000000000 --- a/.changeset/wild-areas-lick.md +++ /dev/null @@ -1,7 +0,0 @@ ---- -'mermaid': patch ---- - -fix(timeline): fix loading `leftMargin` from config - -The `timeline.leftMargin` config value should now correctly control the size of the left margin, instead of being ignored. diff --git a/.cspell/contributors.txt b/.cspell/contributors.txt index 80f4df22a..a95f8654e 100644 --- a/.cspell/contributors.txt +++ b/.cspell/contributors.txt @@ -2,6 +2,7 @@ Ashish Jain cpettitt Dong Cai +fourcube knsv Knut Sveidqvist Nikolay Rozhkov diff --git a/.cspell/mermaid-terms.txt b/.cspell/mermaid-terms.txt index b0cfa0a1d..6900c15b0 100644 --- a/.cspell/mermaid-terms.txt +++ b/.cspell/mermaid-terms.txt @@ -5,6 +5,7 @@ bmatrix braintree catmull compositTitleSize +cose curv doublecircle elems diff --git a/.cspell/misc-terms.txt b/.cspell/misc-terms.txt index 1820e3c86..2906a02fa 100644 --- a/.cspell/misc-terms.txt +++ b/.cspell/misc-terms.txt @@ -1,4 +1,5 @@ BRANDES +Buzan circo handDrawn KOEPF diff --git a/.github/lychee.toml b/.github/lychee.toml index fbe7a71a2..06b3aa707 100644 --- a/.github/lychee.toml +++ b/.github/lychee.toml @@ -59,6 +59,7 @@ exclude = [ "https://huehive.co", "https://foswiki.org", "https://www.gnu.org", +"https://redmine.org", "https://mermaid-preview.com" ] diff --git a/.github/workflows/e2e-applitools.yml b/.github/workflows/e2e-applitools.yml index dd97b49e1..6aaa91eb8 100644 --- a/.github/workflows/e2e-applitools.yml +++ b/.github/workflows/e2e-applitools.yml @@ -23,9 +23,6 @@ env: jobs: e2e-applitools: runs-on: ubuntu-latest - container: - image: cypress/browsers:node-20.11.0-chrome-121.0.6167.85-1-ff-120.0-edge-121.0.2277.83-1 - options: --user 1001 steps: - if: ${{ ! env.USE_APPLI }} name: Warn if not using Applitools diff --git a/.github/workflows/e2e-timings.yml b/.github/workflows/e2e-timings.yml index 00e733c48..21dbda293 100644 --- a/.github/workflows/e2e-timings.yml +++ b/.github/workflows/e2e-timings.yml @@ -58,7 +58,7 @@ jobs: echo "EOF" >> $GITHUB_OUTPUT - name: Commit and create pull request - uses: peter-evans/create-pull-request@889dce9eaba7900ce30494f5e1ac7220b27e5c81 + uses: peter-evans/create-pull-request@18e469570b1cf0dfc11d60ec121099f8ff3e617a with: add-paths: | cypress/timings.json diff --git a/.github/workflows/validate-lockfile.yml b/.github/workflows/validate-lockfile.yml index 6eb0a63ca..59a6df96d 100644 --- a/.github/workflows/validate-lockfile.yml +++ b/.github/workflows/validate-lockfile.yml @@ -35,7 +35,7 @@ jobs: # 2) No unwanted vitepress paths if grep -qF 'packages/mermaid/src/vitepress' pnpm-lock.yaml; then - issues+=("• Disallowed path 'packages/mermaid/src/vitepress' present. Run `rm -rf packages/mermaid/src/vitepress && pnpm install` to regenerate.") + issues+=("• Disallowed path 'packages/mermaid/src/vitepress' present. Run \`rm -rf packages/mermaid/src/vitepress && pnpm install\` to regenerate.") fi # 3) Lockfile only changes when package.json changes diff --git a/.gitignore b/.gitignore index 7448f2a81..7eb55d5cb 100644 --- a/.gitignore +++ b/.gitignore @@ -4,6 +4,7 @@ node_modules/ coverage/ .idea/ .pnpm-store/ +.instructions/ dist v8-compile-cache-0 diff --git a/CHANGELOG.md b/CHANGELOG.md deleted file mode 100644 index 8a4c0a414..000000000 --- a/CHANGELOG.md +++ /dev/null @@ -1,1005 +0,0 @@ -# Changelog - -## [10.0.0](https://github.com/mermaid-js/mermaid/releases/tag/v10.0.0) - -### Mermaid is ESM only! - -We've dropped CJS support. So, you will have to update your import scripts as follows. - -```html - -``` - -You can keep using v9 by adding the `@9` in the CDN URL. - -```diff -- -+ -``` - -### mermaid.render is async and doesn't accept callbacks - -```js -// < v10 -mermaid.render('id', 'graph TD;\nA-->B', (svg, bindFunctions) => { - element.innerHTML = svg; - if (bindFunctions) { - bindFunctions(element); - } -}); - -// Shorter syntax -if (bindFunctions) { - bindFunctions(element); -} -// can be replaced with the `?.` shorthand -bindFunctions?.(element); - -// >= v10 with async/await -const { svg, bindFunctions } = await mermaid.render('id', 'graph TD;\nA-->B'); -element.innerHTML = svg; -bindFunctions?.(element); - -// >= v10 with promise.then -mermaid.render('id', 'graph TD;A-->B').then(({ svg, bindFunctions }) => { - element.innerHTML = svg; - bindFunctions?.(element); -}); -``` - -### mermaid.parse is async and ParseError is removed - -```js -// < v10 -mermaid.parse(text, parseError); - -//>= v10 -await mermaid.parse(text).catch(parseError); -// or -try { - await mermaid.parse(text); -} catch (err) { - parseError(err); -} -``` - -### Init deprecated and InitThrowsErrors removed - -The config passed to `init` was not being used earlier. -It will now be used. -The `init` function is deprecated and will be removed in the next major release. -init currently works as a wrapper to `initialize` and `run`. - -```js -// < v10 -mermaid.init(config, selector, cb); - -//>= v10 -mermaid.initialize(config); -mermaid.run({ - querySelector: selector, - postRenderCallback: cb, - suppressErrors: true, -}); -``` - -```js -// < v10 -mermaid.initThrowsErrors(config, selector, cb); - -//>= v10 -mermaid.initialize(config); -mermaid.run({ - querySelector: selector, - postRenderCallback: cb, - suppressErrors: false, -}); -``` - -// TODO: Populate changelog pre v10 - -- Config has a lot of changes -- globalReset resets to `defaultConfig` instead of current config. Use `reset` instead. - -## [Unreleased](https://github.com/knsv/mermaid/tree/HEAD) - -[Full Changelog](https://github.com/knsv/mermaid/compare/8.2.0...HEAD) - -**Closed issues:** - -- Cross-Site Scripting:DOM - Issue [\#847](https://github.com/knsv/mermaid/issues/847) - -## [8.2.0](https://github.com/knsv/mermaid/tree/8.2.0) (2019-07-17) - -[Full Changelog](https://github.com/knsv/mermaid/compare/8.1.0...8.2.0) - -**Closed issues:** - -- Create issue templates [\#871](https://github.com/knsv/mermaid/issues/871) -- cross site scripting in mermaid [\#869](https://github.com/knsv/mermaid/issues/869) -- Make Gantt chart date inclusive [\#868](https://github.com/knsv/mermaid/issues/868) -- CHANGELOG missing updates for all versions since 0.4.0 [\#865](https://github.com/knsv/mermaid/issues/865) -- please add tag for 8.0.0 release [\#863](https://github.com/knsv/mermaid/issues/863) -- classDiagram breaks on any edit [\#858](https://github.com/knsv/mermaid/issues/858) -- found 1 high severity vulnerability [\#839](https://github.com/knsv/mermaid/issues/839) -- Missing fontawesome icon support [\#830](https://github.com/knsv/mermaid/issues/830) -- Docs for integration with wiki.js? [\#829](https://github.com/knsv/mermaid/issues/829) -- Is this project still maintained? [\#826](https://github.com/knsv/mermaid/issues/826) -- typora [\#823](https://github.com/knsv/mermaid/issues/823) -- Maintain the order of the nodes in Flowchart [\#815](https://github.com/knsv/mermaid/issues/815) -- Overlap, Overflow and cut titles in flowchart [\#814](https://github.com/knsv/mermaid/issues/814) -- How load mermaidApi notejs electron [\#813](https://github.com/knsv/mermaid/issues/813) -- How to set the spacing between the text of the flowchart node and the border? [\#812](https://github.com/knsv/mermaid/issues/812) -- no triming participant name and the name following spaces is as another actor in sequence [\#809](https://github.com/knsv/mermaid/issues/809) -- uml Class as shape type [\#807](https://github.com/knsv/mermaid/issues/807) -- Force-directed graph Layout Style [\#806](https://github.com/knsv/mermaid/issues/806) -- how can I start a newLine in FlowChart [\#805](https://github.com/knsv/mermaid/issues/805) -- UOEProcessShow [\#801](https://github.com/knsv/mermaid/issues/801) -- Why the use of code blocks? [\#799](https://github.com/knsv/mermaid/issues/799) -- fixing class diagram [\#794](https://github.com/knsv/mermaid/issues/794) -- Autonumber support in sequence diagrams [\#782](https://github.com/knsv/mermaid/issues/782) -- MomentJS dependency [\#781](https://github.com/knsv/mermaid/issues/781) -- Feature : Can we color code the flow/arrows [\#766](https://github.com/knsv/mermaid/issues/766) -- Is there any way to convert flowchart.js code to mermaid code [\#726](https://github.com/knsv/mermaid/issues/726) -- Fixed width of nodes [\#653](https://github.com/knsv/mermaid/issues/653) -- Inline comment [\#650](https://github.com/knsv/mermaid/issues/650) -- alt attribute of img tag in HTML [\#619](https://github.com/knsv/mermaid/issues/619) -- Just wanted to say : THANKS ! [\#618](https://github.com/knsv/mermaid/issues/618) -- "animation" [\#446](https://github.com/knsv/mermaid/issues/446) - -**Merged pull requests:** - -- Trimming whitespace after participant id [\#882](https://github.com/knsv/mermaid/pull/882) ([IOrlandoni](https://github.com/IOrlandoni)) -- chore\(deps\): bump atob from 2.0.3 to 2.1.2 [\#881](https://github.com/knsv/mermaid/pull/881) ([dependabot[bot]](https://github.com/apps/dependabot)) -- chore\(deps\): bump fstream from 1.0.11 to 1.0.12 [\#880](https://github.com/knsv/mermaid/pull/880) ([dependabot[bot]](https://github.com/apps/dependabot)) -- chore\(deps\): bump js-yaml from 3.12.0 to 3.13.1 [\#879](https://github.com/knsv/mermaid/pull/879) ([dependabot[bot]](https://github.com/apps/dependabot)) -- I847 cross site scripting [\#878](https://github.com/knsv/mermaid/pull/878) ([knsv](https://github.com/knsv)) -- Bump lodash.mergewith from 4.6.1 to 4.6.2 [\#877](https://github.com/knsv/mermaid/pull/877) ([dependabot[bot]](https://github.com/apps/dependabot)) -- Adding docs into core repo again [\#876](https://github.com/knsv/mermaid/pull/876) ([knsv](https://github.com/knsv)) -- Bump lodash from 4.17.11 to 4.17.13 [\#875](https://github.com/knsv/mermaid/pull/875) ([dependabot[bot]](https://github.com/apps/dependabot)) -- feat\(stale.yml\): update issue label and bot comment [\#874](https://github.com/knsv/mermaid/pull/874) ([ThePenguin1140](https://github.com/ThePenguin1140)) -- Feature/allow inclusive enddates [\#872](https://github.com/knsv/mermaid/pull/872) ([ThePenguin1140](https://github.com/ThePenguin1140)) -- Adding trapezoid and inverse trapezoid vertex options. [\#741](https://github.com/knsv/mermaid/pull/741) ([adamwulf](https://github.com/adamwulf)) - -## [8.1.0](https://github.com/knsv/mermaid/tree/8.1.0) (2019-06-25) - -[Full Changelog](https://github.com/knsv/mermaid/compare/7.0.5...8.1.0) - -**Closed issues:** - -- Gantt and sequence diagram do not render [\#853](https://github.com/knsv/mermaid/issues/853) -- margins around flowchart are not balanced [\#852](https://github.com/knsv/mermaid/issues/852) -- Smaller bundles [\#843](https://github.com/knsv/mermaid/issues/843) -- unicode in labels [\#776](https://github.com/knsv/mermaid/issues/776) -- Hard-changing drawing of arrows per edge type [\#775](https://github.com/knsv/mermaid/issues/775) -- SequenceDiagram wrong [\#773](https://github.com/knsv/mermaid/issues/773) -- Render mermaid on github pages with simple code [\#772](https://github.com/knsv/mermaid/issues/772) -- FlowChart - large space between text and the image [\#754](https://github.com/knsv/mermaid/issues/754) -- Class Diagram Issues when using Mermaid in Stackedit [\#748](https://github.com/knsv/mermaid/issues/748) -- Multi-platform CI [\#744](https://github.com/knsv/mermaid/issues/744) -- gantt: sections can't have a colon [\#742](https://github.com/knsv/mermaid/issues/742) -- Yarn build does not add mermaid.min.css to dist [\#732](https://github.com/knsv/mermaid/issues/732) -- Is there a grammar / keyword / more than just the basic examples? [\#718](https://github.com/knsv/mermaid/issues/718) -- Click event and react component [\#717](https://github.com/knsv/mermaid/issues/717) -- Long text going outside the box [\#706](https://github.com/knsv/mermaid/issues/706) -- How to migrate from yUML to mermaid? [\#704](https://github.com/knsv/mermaid/issues/704) -- Issue on Dynamic Creation in PHP [\#690](https://github.com/knsv/mermaid/issues/690) -- `click "\#target"` and `click "http://url"` should create regular links [\#689](https://github.com/knsv/mermaid/issues/689) -- Support Chinese punctuation [\#687](https://github.com/knsv/mermaid/issues/687) -- \[Question\] Proper way to install on Mac? [\#681](https://github.com/knsv/mermaid/issues/681) -- Has Mermaid a graphical interface to make diagrams? [\#668](https://github.com/knsv/mermaid/issues/668) -- mermaid installation on debian [\#649](https://github.com/knsv/mermaid/issues/649) -- "Cannot activate" in sequenceDiagram [\#647](https://github.com/knsv/mermaid/issues/647) -- Link \("click" statement\) in flowchart does not work in exported SVG [\#646](https://github.com/knsv/mermaid/issues/646) -- How to pass styling [\#639](https://github.com/knsv/mermaid/issues/639) -- The live editor can't show seq diagram with notes for 8.0.0-alpha.3 [\#638](https://github.com/knsv/mermaid/issues/638) -- import mermaid.css with ES6 + NPM [\#634](https://github.com/knsv/mermaid/issues/634) -- Actor line cuts through other elements [\#633](https://github.com/knsv/mermaid/issues/633) -- Graph TD line out of the picture \(left side\) [\#630](https://github.com/knsv/mermaid/issues/630) -- Flowchart labels appear "cutoff" [\#628](https://github.com/knsv/mermaid/issues/628) -- Uncaught TypeError: \_.constant is not a function \(mermaid.js\) [\#626](https://github.com/knsv/mermaid/issues/626) -- Missing tags and releases for newer versions [\#623](https://github.com/knsv/mermaid/issues/623) -- Mermaid and Leo / Leo Vue [\#622](https://github.com/knsv/mermaid/issues/622) -- mermaidAPI gantt Vue.js [\#621](https://github.com/knsv/mermaid/issues/621) -- Gantt sections are not separated by colors - Fix: set numberSectionStyles to 4 instead of 3 [\#620](https://github.com/knsv/mermaid/issues/620) -- how to get mermaidAPI? [\#617](https://github.com/knsv/mermaid/issues/617) -- Error in startOnLoad documentation? [\#616](https://github.com/knsv/mermaid/issues/616) -- Example export to SVG generates error [\#614](https://github.com/knsv/mermaid/issues/614) -- The new online editor does not support previously generated links [\#613](https://github.com/knsv/mermaid/issues/613) -- Grammar / Syntax documentation for flowcharts [\#607](https://github.com/knsv/mermaid/issues/607) -- Mermaid does not work with d3.js [\#606](https://github.com/knsv/mermaid/issues/606) -- Why does this code's flowchart lines get cut-off on screen? [\#604](https://github.com/knsv/mermaid/issues/604) -- click keyword does not fire my callback \(on the demo Website too\) [\#603](https://github.com/knsv/mermaid/issues/603) -- Online Editor fails to show exported SVG [\#601](https://github.com/knsv/mermaid/issues/601) -- Just saying thanks! [\#597](https://github.com/knsv/mermaid/issues/597) -- stylesheet crashed with other library like abcjs [\#596](https://github.com/knsv/mermaid/issues/596) -- Missing connection [\#594](https://github.com/knsv/mermaid/issues/594) -- How to use mermaid on node.js restful api? [\#593](https://github.com/knsv/mermaid/issues/593) -- Remove status code [\#589](https://github.com/knsv/mermaid/issues/589) -- Golang based editor [\#588](https://github.com/knsv/mermaid/issues/588) -- sequenceDiagram -\> notetext css font is hardcoded [\#587](https://github.com/knsv/mermaid/issues/587) -- Multiple graph in the live editor [\#586](https://github.com/knsv/mermaid/issues/586) -- All \ elements in page are colored black [\#584](https://github.com/knsv/mermaid/issues/584) -- Styling: classes aren't applied to elements. [\#582](https://github.com/knsv/mermaid/issues/582) -- Rounded connections [\#580](https://github.com/knsv/mermaid/issues/580) -- Arrows are not being shown correctly in the dark theme [\#578](https://github.com/knsv/mermaid/issues/578) -- The documentation for CLI seems outdated. [\#572](https://github.com/knsv/mermaid/issues/572) -- No effect of click event:can not open link [\#571](https://github.com/knsv/mermaid/issues/571) -- Text colors are not correct in VSCODE [\#570](https://github.com/knsv/mermaid/issues/570) -- Nodes aren't aligned properly \(just need an explanation\) [\#568](https://github.com/knsv/mermaid/issues/568) -- setting margin around figure in R [\#567](https://github.com/knsv/mermaid/issues/567) -- Arrows should Come out in upward and Downward direction from decision Node [\#566](https://github.com/knsv/mermaid/issues/566) -- TypeError: Cannot read property 'select' of undefined [\#563](https://github.com/knsv/mermaid/issues/563) -- A little bug [\#557](https://github.com/knsv/mermaid/issues/557) -- Japanese text appears garbled [\#554](https://github.com/knsv/mermaid/issues/554) -- classdiagram not works in mermaid live_editor [\#553](https://github.com/knsv/mermaid/issues/553) -- font awesome in link text? [\#546](https://github.com/knsv/mermaid/issues/546) -- q: heard of the cosmogol standard? [\#545](https://github.com/knsv/mermaid/issues/545) -- Arrow heads missing \(cli, 7.0.3\) [\#544](https://github.com/knsv/mermaid/issues/544) -- No Edge Boxes if useHtmlLabels=false [\#541](https://github.com/knsv/mermaid/issues/541) -- how to change mermaid text color or line text block color? [\#534](https://github.com/knsv/mermaid/issues/534) -- FlowChart visualization broken when downloading from live editor [\#533](https://github.com/knsv/mermaid/issues/533) -- Can't get flowchart to render paths at the top of the diagram; I even tried the online editor and that shows the same issue. Thoughts? [\#532](https://github.com/knsv/mermaid/issues/532) -- live editor make browser\(safari on macOS&iOS\) not longer respond [\#531](https://github.com/knsv/mermaid/issues/531) -- css classes need a prefix/namespace [\#527](https://github.com/knsv/mermaid/issues/527) -- input activate/deactivate cause safari unresponding [\#521](https://github.com/knsv/mermaid/issues/521) -- Cannot Render the Mermaid Graph to PDF ? [\#520](https://github.com/knsv/mermaid/issues/520) -- clicking links works from inset in subgraph but not from nodes [\#516](https://github.com/knsv/mermaid/issues/516) -- Strange syntax error - when importing mermaid.js [\#515](https://github.com/knsv/mermaid/issues/515) -- gantt x-axis display [\#510](https://github.com/knsv/mermaid/issues/510) -- phantomjs renamed to phantomjs-prebuilt [\#508](https://github.com/knsv/mermaid/issues/508) -- issue when using sphinxcontrib-mermaid extension for sphinx [\#507](https://github.com/knsv/mermaid/issues/507) -- layout of docs page looks broken [\#504](https://github.com/knsv/mermaid/issues/504) -- Problem showing graph with php on localhost [\#502](https://github.com/knsv/mermaid/issues/502) -- logLevel's option doesnt work at 7.0.0 [\#501](https://github.com/knsv/mermaid/issues/501) -- How do I get the log for a render or parse attempt? [\#500](https://github.com/knsv/mermaid/issues/500) -- Mermaid neutral style to built in latest release [\#499](https://github.com/knsv/mermaid/issues/499) -- Any plans for adding a typescript definition file? [\#495](https://github.com/knsv/mermaid/issues/495) -- Gantt diagrams too narrow [\#493](https://github.com/knsv/mermaid/issues/493) -- Flowchart edge labels placement [\#490](https://github.com/knsv/mermaid/issues/490) -- Very different styles when rendering as png vs. svg [\#489](https://github.com/knsv/mermaid/issues/489) -- New editor that supports mermaid: Caret [\#488](https://github.com/knsv/mermaid/issues/488) -- Gant PNG margin [\#486](https://github.com/knsv/mermaid/issues/486) -- ReferenceError: window is not defined [\#485](https://github.com/knsv/mermaid/issues/485) -- Menu and layout bugs in docs [\#484](https://github.com/knsv/mermaid/issues/484) -- Mermaid resets some of the page CSS styles [\#482](https://github.com/knsv/mermaid/issues/482) -- Arrows rendering incorrectly in online editor [\#480](https://github.com/knsv/mermaid/issues/480) -- CSS stroke-dasharray ignored by browsers but not other viewers [\#474](https://github.com/knsv/mermaid/issues/474) -- mermaid - Browser Support issue [\#472](https://github.com/knsv/mermaid/issues/472) -- Totally love mermaid I might pop! [\#471](https://github.com/knsv/mermaid/issues/471) -- Sequence Diagram: Missing x on async arrows \(png\) [\#469](https://github.com/knsv/mermaid/issues/469) -- live editor: the svg file rendered from graph is not supported by browsers [\#468](https://github.com/knsv/mermaid/issues/468) -- Not found css [\#462](https://github.com/knsv/mermaid/issues/462) -- Phantomjs Dependency [\#461](https://github.com/knsv/mermaid/issues/461) -- Mermaid cli not working for subgraphs [\#459](https://github.com/knsv/mermaid/issues/459) -- Support for notes across multiple participants? [\#458](https://github.com/knsv/mermaid/issues/458) -- Related to Issue \#329: Phantomjs issues. [\#455](https://github.com/knsv/mermaid/issues/455) -- Add a click style [\#426](https://github.com/knsv/mermaid/issues/426) -- Add Parallel block \(par\) to sequence diagrams [\#425](https://github.com/knsv/mermaid/issues/425) -- updating shapes after the flow chart rendering complete [\#424](https://github.com/knsv/mermaid/issues/424) -- can't catch parse error Maximum call stack size exceeded on safari [\#421](https://github.com/knsv/mermaid/issues/421) -- Arrows endings are missing [\#419](https://github.com/knsv/mermaid/issues/419) -- shouldn't mermaid become more like Markdown ? [\#417](https://github.com/knsv/mermaid/issues/417) -- Live editor show rendered diagram if syntax invalid [\#415](https://github.com/knsv/mermaid/issues/415) -- Live editor sticky sidebar [\#414](https://github.com/knsv/mermaid/issues/414) -- Linkstyle stroke does not work [\#410](https://github.com/knsv/mermaid/issues/410) -- flowchart id's with dots in them .. break links [\#408](https://github.com/knsv/mermaid/issues/408) -- Flowchart: Link text beginning with lowercase 'o' causes flowchart to break [\#407](https://github.com/knsv/mermaid/issues/407) -- Some chinese character will case Safari no responding. [\#405](https://github.com/knsv/mermaid/issues/405) -- Cannot center-justify text in nodes? [\#397](https://github.com/knsv/mermaid/issues/397) -- Edge labels should have white background in live editor [\#396](https://github.com/knsv/mermaid/issues/396) -- Live editor does not support activate/deactivate [\#394](https://github.com/knsv/mermaid/issues/394) -- Styling subgraph? [\#391](https://github.com/knsv/mermaid/issues/391) -- Update live editor to version 6.0.0 [\#387](https://github.com/knsv/mermaid/issues/387) -- sequence diagram config issue [\#385](https://github.com/knsv/mermaid/issues/385) -- How to add newline in the text [\#384](https://github.com/knsv/mermaid/issues/384) -- PhantomJS crashes on a large graph [\#380](https://github.com/knsv/mermaid/issues/380) -- Finnish support for class diagrams using plantuml syntax [\#377](https://github.com/knsv/mermaid/issues/377) -- mermaidAPI.render generated different svg code from mermaid.int\(\) [\#374](https://github.com/knsv/mermaid/issues/374) -- Put your own action on the chart [\#372](https://github.com/knsv/mermaid/issues/372) -- when declaring participants the elements are generated twice [\#370](https://github.com/knsv/mermaid/issues/370) -- Example Flowchart is cut in display \(Chrome\). [\#368](https://github.com/knsv/mermaid/issues/368) -- Add shebang support to diagrams [\#365](https://github.com/knsv/mermaid/issues/365) -- Silencing CLI output [\#352](https://github.com/knsv/mermaid/issues/352) -- SequenceDiagram: 3+ Alternative Paths [\#348](https://github.com/knsv/mermaid/issues/348) -- Smaller height of actor boxes [\#342](https://github.com/knsv/mermaid/issues/342) -- Question: lib/phantomscript.js - foreignObjects in SVG - related to \#58 [\#340](https://github.com/knsv/mermaid/issues/340) -- npm test fails on osx being blocked at Can not load "PhantomJS", it is not registered! [\#337](https://github.com/knsv/mermaid/issues/337) -- Tabs & subgraphs cause rendering error [\#336](https://github.com/knsv/mermaid/issues/336) -- Display question: right angles [\#335](https://github.com/knsv/mermaid/issues/335) -- No Arrows rendered v0.5.8 [\#330](https://github.com/knsv/mermaid/issues/330) -- mermaid -v filename.mmd gives You must specify at least one source file. [\#328](https://github.com/knsv/mermaid/issues/328) -- You had errors in your syntax. Use --help for further information. [\#327](https://github.com/knsv/mermaid/issues/327) -- Allow alternate arrow syntax that doesn't close html comments [\#322](https://github.com/knsv/mermaid/issues/322) -- Comment in subgraph [\#319](https://github.com/knsv/mermaid/issues/319) -- Update graph [\#311](https://github.com/knsv/mermaid/issues/311) -- css conflicts with boostrap's css [\#308](https://github.com/knsv/mermaid/issues/308) -- Can not get click event to fire. [\#306](https://github.com/knsv/mermaid/issues/306) -- Fix phantomjs2 compatibility [\#304](https://github.com/knsv/mermaid/issues/304) -- Flowcharts do not work in native IE11 [\#303](https://github.com/knsv/mermaid/issues/303) -- Integration with remark.js - tutorial added [\#302](https://github.com/knsv/mermaid/issues/302) -- Theme for dark background [\#301](https://github.com/knsv/mermaid/issues/301) -- Sequence diagram Loops: changing boxMargin spoils the "loop" notation [\#299](https://github.com/knsv/mermaid/issues/299) -- src/mermaid.js generates bad code [\#297](https://github.com/knsv/mermaid/issues/297) -- Fresh fork: jasmine tests fail [\#294](https://github.com/knsv/mermaid/issues/294) -- CSS clash [\#292](https://github.com/knsv/mermaid/issues/292) -- Mermaid does not work in Chrome 48 [\#281](https://github.com/knsv/mermaid/issues/281) -- node click is not effective [\#272](https://github.com/knsv/mermaid/issues/272) -- circle and ellipse cannot change color by classDef [\#271](https://github.com/knsv/mermaid/issues/271) -- \[Feature request\] gantt diagram axis format [\#269](https://github.com/knsv/mermaid/issues/269) -- Not Able to See Labels even htmlLabels:false added [\#268](https://github.com/knsv/mermaid/issues/268) -- npm run watch doesn’t work due missing dependencies [\#266](https://github.com/knsv/mermaid/issues/266) -- label out of node [\#262](https://github.com/knsv/mermaid/issues/262) -- IE11 Support issue [\#261](https://github.com/knsv/mermaid/issues/261) -- mermaid without browser [\#260](https://github.com/knsv/mermaid/issues/260) -- Insufficient capacity of gantt diagrams [\#226](https://github.com/knsv/mermaid/issues/226) -- some WARN about installion [\#222](https://github.com/knsv/mermaid/issues/222) -- Live editor offline access [\#217](https://github.com/knsv/mermaid/issues/217) -- suggest: code highlight mode config for editors [\#212](https://github.com/knsv/mermaid/issues/212) -- Uncaught RangeError: Maximum call stack size exceeded [\#189](https://github.com/knsv/mermaid/issues/189) -- Implement render function for server side rendering using phantomjs [\#169](https://github.com/knsv/mermaid/issues/169) -- Styling label texts [\#50](https://github.com/knsv/mermaid/issues/50) -- Graphviz DOT syntax [\#5](https://github.com/knsv/mermaid/issues/5) - -**Merged pull requests:** - -- Remove console.log in classDB. [\#861](https://github.com/knsv/mermaid/pull/861) ([Arthaey](https://github.com/Arthaey)) -- Bump sshpk from 1.13.1 to 1.16.1 [\#851](https://github.com/knsv/mermaid/pull/851) ([dependabot[bot]](https://github.com/apps/dependabot)) -- Significantly smaller bundles [\#850](https://github.com/knsv/mermaid/pull/850) ([fabiospampinato](https://github.com/fabiospampinato)) -- Support styling of subgraphs [\#845](https://github.com/knsv/mermaid/pull/845) ([Qix-](https://github.com/Qix-)) -- fix dark theme loop labels not visible [\#837](https://github.com/knsv/mermaid/pull/837) ([jnnnnn](https://github.com/jnnnnn)) -- fix draw function can only call once [\#832](https://github.com/knsv/mermaid/pull/832) ([vaniship](https://github.com/vaniship)) -- Fix dotted lines not appearing in flowcharts when HTML labels disabled [\#828](https://github.com/knsv/mermaid/pull/828) ([stanhu](https://github.com/stanhu)) -- Fix issue with XML line breaks inside vertex labels [\#824](https://github.com/knsv/mermaid/pull/824) ([jsyang](https://github.com/jsyang)) -- fixed diagrams [\#810](https://github.com/knsv/mermaid/pull/810) ([0xflotus](https://github.com/0xflotus)) -- Clickable gantt tasks [\#804](https://github.com/knsv/mermaid/pull/804) ([abzicht](https://github.com/abzicht)) -- linkStyle now supports list of indexes with a few tests [\#798](https://github.com/knsv/mermaid/pull/798) ([ivan-danilov](https://github.com/ivan-danilov)) -- fix class diagram mermaid [\#795](https://github.com/knsv/mermaid/pull/795) ([DanShai](https://github.com/DanShai)) -- Added exclude weekdays to definition [\#792](https://github.com/knsv/mermaid/pull/792) ([jopapo](https://github.com/jopapo)) -- SVG link rendering [\#791](https://github.com/knsv/mermaid/pull/791) ([flying-sheep](https://github.com/flying-sheep)) -- Gantt milestones [\#788](https://github.com/knsv/mermaid/pull/788) ([gijswijs](https://github.com/gijswijs)) -- Remove duplicate code [\#768](https://github.com/knsv/mermaid/pull/768) ([znxkznxk1030](https://github.com/znxkznxk1030)) -- Render nodes as real links [\#765](https://github.com/knsv/mermaid/pull/765) ([flying-sheep](https://github.com/flying-sheep)) -- Support Multi-line Actor Descriptions [\#764](https://github.com/knsv/mermaid/pull/764) ([watsoncj](https://github.com/watsoncj)) -- Fix issue with marker-end. [\#757](https://github.com/knsv/mermaid/pull/757) ([gjlubbertsen](https://github.com/gjlubbertsen)) -- Make Class Diagrams usable in Stackedit and Live Editor [\#749](https://github.com/knsv/mermaid/pull/749) ([monsterkrampe](https://github.com/monsterkrampe)) -- Sequence numbers [\#722](https://github.com/knsv/mermaid/pull/722) ([paulbland](https://github.com/paulbland)) -- Add option for right angles [\#721](https://github.com/knsv/mermaid/pull/721) ([paulbland](https://github.com/paulbland)) -- Add nested activation classes [\#720](https://github.com/knsv/mermaid/pull/720) ([paulbland](https://github.com/paulbland)) -- wip: class diagram cardinality display [\#705](https://github.com/knsv/mermaid/pull/705) ([Vrixyz](https://github.com/Vrixyz)) -- add comments about CSS in config [\#688](https://github.com/knsv/mermaid/pull/688) ([imma90](https://github.com/imma90)) -- SequenceDiagram: Add support for multiple alt else statements [\#641](https://github.com/knsv/mermaid/pull/641) ([sechel](https://github.com/sechel)) -- fix \#426 - add class .clickable on nodes with click function or link [\#598](https://github.com/knsv/mermaid/pull/598) ([thomasleveil](https://github.com/thomasleveil)) -- Spec fix 1 [\#595](https://github.com/knsv/mermaid/pull/595) ([frankschmitt](https://github.com/frankschmitt)) - -## [7.0.5](https://github.com/knsv/mermaid/tree/7.0.5) (2017-09-01) - -[Full Changelog](https://github.com/knsv/mermaid/compare/7.0.3...7.0.5) - -**Closed issues:** - -- live editor latin error after update [\#560](https://github.com/knsv/mermaid/issues/560) -- Simple full example in online documentation is broken [\#558](https://github.com/knsv/mermaid/issues/558) -- Graph No Arrow Head v7.0.3 [\#543](https://github.com/knsv/mermaid/issues/543) -- Conflict while using mermaid along with core-js [\#512](https://github.com/knsv/mermaid/issues/512) -- Export to pdf on website [\#496](https://github.com/knsv/mermaid/issues/496) -- New downstream project: Mermaid Preview for VSCode [\#442](https://github.com/knsv/mermaid/issues/442) -- Can't Zoom the flowchart ? [\#399](https://github.com/knsv/mermaid/issues/399) -- line labels are not rendered correctly in live editor [\#366](https://github.com/knsv/mermaid/issues/366) -- mermaid-loader [\#361](https://github.com/knsv/mermaid/issues/361) -- Are there any documentation or examples for classDiagram and gitGraph? [\#359](https://github.com/knsv/mermaid/issues/359) -- \# character broken in 0.5.8 [\#347](https://github.com/knsv/mermaid/issues/347) -- Documentation issue: CSS example is not visible [\#345](https://github.com/knsv/mermaid/issues/345) -- Include documentation for command line usage [\#326](https://github.com/knsv/mermaid/issues/326) -- Fresh fork: can't build dist [\#296](https://github.com/knsv/mermaid/issues/296) -- Invalid value for \ attribute viewBox="0 0 -Infinity -Infinity" [\#291](https://github.com/knsv/mermaid/issues/291) -- Webpack require fails [\#277](https://github.com/knsv/mermaid/issues/277) -- New documentation - need improved logo [\#216](https://github.com/knsv/mermaid/issues/216) - -## [7.0.3](https://github.com/knsv/mermaid/tree/7.0.3) (2017-06-04) - -[Full Changelog](https://github.com/knsv/mermaid/compare/7.0.2...7.0.3) - -**Closed issues:** - -- the documentation website is down [\#539](https://github.com/knsv/mermaid/issues/539) -- Good example of interactivity with mermaidAPI [\#514](https://github.com/knsv/mermaid/issues/514) - -## [7.0.2](https://github.com/knsv/mermaid/tree/7.0.2) (2017-06-01) - -[Full Changelog](https://github.com/knsv/mermaid/compare/7.0.0...7.0.2) - -**Closed issues:** - -- CDN is not working [\#511](https://github.com/knsv/mermaid/issues/511) -- A sampe sequenceDiagram crashes mermaid-cli [\#492](https://github.com/knsv/mermaid/issues/492) -- Mermaid doesn't delete nodes when called multiple times [\#491](https://github.com/knsv/mermaid/issues/491) -- API crashes on 2nd render\(\) call [\#478](https://github.com/knsv/mermaid/issues/478) -- sequenceDiagram: dotted line for alt and empty bracket should be hidden [\#456](https://github.com/knsv/mermaid/issues/456) -- SVG output \(almost\) not correct [\#434](https://github.com/knsv/mermaid/issues/434) -- How to set axisFormatter of gantt in mermaid CLI? [\#428](https://github.com/knsv/mermaid/issues/428) -- customizing link style with any color sets `fill` property to `black` instead of `none` [\#416](https://github.com/knsv/mermaid/issues/416) -- New line at the end of SVG file [\#400](https://github.com/knsv/mermaid/issues/400) -- CLI doesn't work [\#389](https://github.com/knsv/mermaid/issues/389) -- Can't render subgraphs with htmlLabels: false [\#367](https://github.com/knsv/mermaid/issues/367) -- Color arrowhead [\#362](https://github.com/knsv/mermaid/issues/362) -- CLI: Invisible text, lines in SVG output [\#341](https://github.com/knsv/mermaid/issues/341) - -**Merged pull requests:** - -- Update Travis config [\#538](https://github.com/knsv/mermaid/pull/538) ([tylerlong](https://github.com/tylerlong)) -- Fix spelling of 'you' in sequenceDiagram docs [\#537](https://github.com/knsv/mermaid/pull/537) ([ctruelson](https://github.com/ctruelson)) -- Improve CLI output [\#536](https://github.com/knsv/mermaid/pull/536) ([gibson042](https://github.com/gibson042)) -- Modernize mermaid [\#524](https://github.com/knsv/mermaid/pull/524) ([tylerlong](https://github.com/tylerlong)) -- Modernize mermaid [\#519](https://github.com/knsv/mermaid/pull/519) ([tylerlong](https://github.com/tylerlong)) -- Update CLI instructions [\#509](https://github.com/knsv/mermaid/pull/509) ([filipedeschamps](https://github.com/filipedeschamps)) -- Add style for classDiagram to dark/default theme [\#503](https://github.com/knsv/mermaid/pull/503) ([yudenzel](https://github.com/yudenzel)) -- Fix documentation for git graph. [\#498](https://github.com/knsv/mermaid/pull/498) ([gomlgs](https://github.com/gomlgs)) -- Fix links in documentations [\#497](https://github.com/knsv/mermaid/pull/497) ([saveman71](https://github.com/saveman71)) -- Update README.md with git graph sample [\#481](https://github.com/knsv/mermaid/pull/481) ([raghur](https://github.com/raghur)) -- Fix misspelling of “another” [\#479](https://github.com/knsv/mermaid/pull/479) ([stevenschobert](https://github.com/stevenschobert)) -- Fixed \#456 sequenceDiagram: dotted line for alt and empty bracket sho… [\#477](https://github.com/knsv/mermaid/pull/477) ([brookhong](https://github.com/brookhong)) -- Add viewbox attr to class diagram [\#473](https://github.com/knsv/mermaid/pull/473) ([gnkm](https://github.com/gnkm)) -- add par statement to sequenceDiagram [\#470](https://github.com/knsv/mermaid/pull/470) ([u-minor](https://github.com/u-minor)) - -## [7.0.0](https://github.com/knsv/mermaid/tree/7.0.0) (2017-01-29) - -[Full Changelog](https://github.com/knsv/mermaid/compare/6.0.0...7.0.0) - -**Closed issues:** - -- demos on io site not working [\#466](https://github.com/knsv/mermaid/issues/466) -- Can not be generated PNG pictures through CLI with Chinese [\#451](https://github.com/knsv/mermaid/issues/451) -- Round nodes cannot be styled with CSS classes [\#443](https://github.com/knsv/mermaid/issues/443) -- webpack gulp UglifyJsPlugin error. [\#440](https://github.com/knsv/mermaid/issues/440) -- String concatenation isn't working [\#432](https://github.com/knsv/mermaid/issues/432) -- text flow/wrap in actor box of sequence diagram [\#422](https://github.com/knsv/mermaid/issues/422) -- Online live editor still use old version [\#402](https://github.com/knsv/mermaid/issues/402) -- uncaught TypeError: t.getTransformToElement is not a function [\#401](https://github.com/knsv/mermaid/issues/401) -- Only works when using browserify'd code [\#373](https://github.com/knsv/mermaid/issues/373) -- document the use of shebang line in mmd files [\#364](https://github.com/knsv/mermaid/issues/364) -- Diagrams are small and unreadable in IE 11 - since 0.5.1 [\#356](https://github.com/knsv/mermaid/issues/356) -- \[Feature Request\] ER-Diagram Support [\#354](https://github.com/knsv/mermaid/issues/354) -- npm install -g mermaid does not install phantomjs [\#329](https://github.com/knsv/mermaid/issues/329) -- activation boxes [\#313](https://github.com/knsv/mermaid/issues/313) -- The need for mermaid.css should be mentioned explicitly in the intro docs... [\#273](https://github.com/knsv/mermaid/issues/273) - -**Merged pull requests:** - -- Update index.html [\#465](https://github.com/knsv/mermaid/pull/465) ([bmsleight](https://github.com/bmsleight)) -- Fix for \#416, customizing link style with any color sets `fill` property to `black` instead of `none` [\#452](https://github.com/knsv/mermaid/pull/452) ([joshuacolvin](https://github.com/joshuacolvin)) -- Allow .node\>circle to receive css styles [\#449](https://github.com/knsv/mermaid/pull/449) ([bfriedz](https://github.com/bfriedz)) -- Fix spelling [\#447](https://github.com/knsv/mermaid/pull/447) ([jawn](https://github.com/jawn)) -- added tests and fix cli css style selector lowercase problem [\#445](https://github.com/knsv/mermaid/pull/445) ([whyzdev](https://github.com/whyzdev)) -- Update d3.js [\#441](https://github.com/knsv/mermaid/pull/441) ([hetz](https://github.com/hetz)) -- adde tests to reproduce \#434 in flowchart [\#439](https://github.com/knsv/mermaid/pull/439) ([whyzdev](https://github.com/whyzdev)) -- Code Climate config [\#437](https://github.com/knsv/mermaid/pull/437) ([larkinscott](https://github.com/larkinscott)) -- fix gantt and sequence digram cli cfg [\#435](https://github.com/knsv/mermaid/pull/435) ([whyzdev](https://github.com/whyzdev)) -- fix gantt chart cli configuration broken [\#433](https://github.com/knsv/mermaid/pull/433) ([whyzdev](https://github.com/whyzdev)) -- fix gantt chart cli configuration parsing including functions [\#430](https://github.com/knsv/mermaid/pull/430) ([whyzdev](https://github.com/whyzdev)) -- Uses an empty text node instead of a string for svg group labels [\#429](https://github.com/knsv/mermaid/pull/429) ([daveaglick](https://github.com/daveaglick)) -- use tspan via d3.textwrap to place actor text in sequence diagram [\#427](https://github.com/knsv/mermaid/pull/427) ([whyzdev](https://github.com/whyzdev)) -- \#422 use foreignObject/div to place actor label in sequence diagram [\#423](https://github.com/knsv/mermaid/pull/423) ([whyzdev](https://github.com/whyzdev)) -- Clarify the need for a CSS stylesheet [\#413](https://github.com/knsv/mermaid/pull/413) ([sifb](https://github.com/sifb)) -- Added hads downstream project [\#412](https://github.com/knsv/mermaid/pull/412) ([sinedied](https://github.com/sinedied)) -- update usage and fix \#273 [\#406](https://github.com/knsv/mermaid/pull/406) ([jinntrance](https://github.com/jinntrance)) -- Add https://github.com/raghur/mermaid-filter to downstream projects docs page [\#404](https://github.com/knsv/mermaid/pull/404) ([raghur](https://github.com/raghur)) -- New neutral theme [\#395](https://github.com/knsv/mermaid/pull/395) ([sinedied](https://github.com/sinedied)) -- fix cli issues [\#390](https://github.com/knsv/mermaid/pull/390) ([ben-page](https://github.com/ben-page)) -- Add missing space for 'Labels out of bounds' section [\#386](https://github.com/knsv/mermaid/pull/386) ([The-Alchemist](https://github.com/The-Alchemist)) -- Fix typo: `pats` -\> `paths` [\#382](https://github.com/knsv/mermaid/pull/382) ([swhgoon](https://github.com/swhgoon)) -- Added class diagram example to README.md [\#379](https://github.com/knsv/mermaid/pull/379) ([HustLion](https://github.com/HustLion)) -- override normal flowchart arrowhead to allow css styling [\#376](https://github.com/knsv/mermaid/pull/376) ([dodoinblue](https://github.com/dodoinblue)) -- added sphinx extension [\#371](https://github.com/knsv/mermaid/pull/371) ([mgaitan](https://github.com/mgaitan)) -- Fix typo in the sequence diagram documentation [\#369](https://github.com/knsv/mermaid/pull/369) ([ggpasqualino](https://github.com/ggpasqualino)) - -## [6.0.0](https://github.com/knsv/mermaid/tree/6.0.0) (2016-05-29) - -[Full Changelog](https://github.com/knsv/mermaid/compare/0.5.8...6.0.0) - -**Closed issues:** - -- Docs css: code hard to read [\#324](https://github.com/knsv/mermaid/issues/324) -- About Markpad integration [\#323](https://github.com/knsv/mermaid/issues/323) -- How to link backwards in flowchat? [\#321](https://github.com/knsv/mermaid/issues/321) -- Help with editor [\#310](https://github.com/knsv/mermaid/issues/310) -- +1 [\#293](https://github.com/knsv/mermaid/issues/293) -- Basic chart does not render on Chome, but does in Firefox [\#290](https://github.com/knsv/mermaid/issues/290) -- Live editor is broken [\#285](https://github.com/knsv/mermaid/issues/285) -- "No such file or directory" trying to run mermaid 0.5.7 on OS X [\#284](https://github.com/knsv/mermaid/issues/284) -- participant name as "Long Long Name" [\#283](https://github.com/knsv/mermaid/issues/283) -- Windows - cli - could not find phantomjs at the specified path [\#236](https://github.com/knsv/mermaid/issues/236) - -**Merged pull requests:** - -- The option of gantt for the spaces for the section names. [\#353](https://github.com/knsv/mermaid/pull/353) ([zeroyonichihachi](https://github.com/zeroyonichihachi)) -- Gitgraph: Make reset work with parent ref carets [\#350](https://github.com/knsv/mermaid/pull/350) ([raghur](https://github.com/raghur)) -- Remove the text-shadows that make the text look blurry [\#349](https://github.com/knsv/mermaid/pull/349) ([AsaAyers](https://github.com/AsaAyers)) -- add line interpolation to linkStyle in flowchart [\#346](https://github.com/knsv/mermaid/pull/346) ([AlanHohn](https://github.com/AlanHohn)) -- Support git graph diagrams in mermaid [\#344](https://github.com/knsv/mermaid/pull/344) ([raghur](https://github.com/raghur)) -- Build and test execution changes [\#338](https://github.com/knsv/mermaid/pull/338) ([ssbarnea](https://github.com/ssbarnea)) -- Reformatting of css files [\#331](https://github.com/knsv/mermaid/pull/331) ([Jmuccigr](https://github.com/Jmuccigr)) -- \(WIP\) Sequence Diagram Title Support [\#320](https://github.com/knsv/mermaid/pull/320) ([bronsoja](https://github.com/bronsoja)) -- activations doc + few fixes [\#318](https://github.com/knsv/mermaid/pull/318) ([ciekawy](https://github.com/ciekawy)) -- Dark theme for better contrast on darker backgrounds [\#317](https://github.com/knsv/mermaid/pull/317) ([crodriguez1a](https://github.com/crodriguez1a)) -- Activations [\#316](https://github.com/knsv/mermaid/pull/316) ([ciekawy](https://github.com/ciekawy)) -- Support leading comments for sequenceDiagrams [\#312](https://github.com/knsv/mermaid/pull/312) ([ashsearle](https://github.com/ashsearle)) -- Show a little lenience for white-space around names [\#309](https://github.com/knsv/mermaid/pull/309) ([ashsearle](https://github.com/ashsearle)) -- Update list of downstream projects [\#307](https://github.com/knsv/mermaid/pull/307) ([maxArturo](https://github.com/maxArturo)) -- Issue 299: Sequence diagram Loops: changing boxMargin spoils the "loop" notation [\#300](https://github.com/knsv/mermaid/pull/300) ([LarryKlugerDS](https://github.com/LarryKlugerDS)) -- Issue 297 - src/mermaid.js generates bad code [\#298](https://github.com/knsv/mermaid/pull/298) ([LarryKlugerDS](https://github.com/LarryKlugerDS)) -- Updated instructions for running tests [\#295](https://github.com/knsv/mermaid/pull/295) ([LarryKlugerDS](https://github.com/LarryKlugerDS)) -- Add Markdown Plus to Downstream projects [\#288](https://github.com/knsv/mermaid/pull/288) ([tylerlong](https://github.com/tylerlong)) -- Quote phantomPath so that it doesn't fail on window [\#286](https://github.com/knsv/mermaid/pull/286) ([raghur](https://github.com/raghur)) - -## [0.5.8](https://github.com/knsv/mermaid/tree/0.5.8) (2016-01-27) - -[Full Changelog](https://github.com/knsv/mermaid/compare/0.5.7...0.5.8) - -## [0.5.7](https://github.com/knsv/mermaid/tree/0.5.7) (2016-01-25) - -[Full Changelog](https://github.com/knsv/mermaid/compare/0.5.6...0.5.7) - -**Closed issues:** - -- Mermaid + LightPaper = ❤️ [\#280](https://github.com/knsv/mermaid/issues/280) -- Bower Integration [\#278](https://github.com/knsv/mermaid/issues/278) -- Mermaid breaks when variables end in 'v' [\#276](https://github.com/knsv/mermaid/issues/276) -- sequence diagrams don't support participant aliasing [\#263](https://github.com/knsv/mermaid/issues/263) -- One diagram that fails to render stops further execution on the page [\#259](https://github.com/knsv/mermaid/issues/259) -- Where to find line layout algorithm? [\#258](https://github.com/knsv/mermaid/issues/258) -- Compatibility with node.js [\#257](https://github.com/knsv/mermaid/issues/257) -- Label resizing with dynamically loaded fonts [\#255](https://github.com/knsv/mermaid/issues/255) -- SVG arrowheads are broken in the CLI [\#249](https://github.com/knsv/mermaid/issues/249) -- Cannot read property 'replace' of undefined [\#239](https://github.com/knsv/mermaid/issues/239) - -**Merged pull requests:** - -- gh-50 Allow styling of edge labels in css [\#267](https://github.com/knsv/mermaid/pull/267) ([Anoia](https://github.com/Anoia)) -- Allow sequenceDiagram participant aliasing [\#265](https://github.com/knsv/mermaid/pull/265) ([gibson042](https://github.com/gibson042)) - -## [0.5.6](https://github.com/knsv/mermaid/tree/0.5.6) (2015-11-22) - -[Full Changelog](https://github.com/knsv/mermaid/compare/0.5.5...0.5.6) - -**Closed issues:** - -- title doesn't work in sequenceDiagram [\#248](https://github.com/knsv/mermaid/issues/248) -- hypen-minus should be valid in sequence diagram alt/else/etc. descriptions [\#247](https://github.com/knsv/mermaid/issues/247) -- Broken in firefox? [\#245](https://github.com/knsv/mermaid/issues/245) -- When there is a Chinese symbol in the flowchart, it will crash。 [\#238](https://github.com/knsv/mermaid/issues/238) -- Non-alpha characters included in ALPHA token \(flow graph jison\) [\#232](https://github.com/knsv/mermaid/issues/232) -- subgraph not rendering with change to sample [\#231](https://github.com/knsv/mermaid/issues/231) -- sequence diagram requires a new line at the end? [\#229](https://github.com/knsv/mermaid/issues/229) -- Live Editor: Permalink address not being parsed [\#202](https://github.com/knsv/mermaid/issues/202) -- Add download SVG link to the live editor [\#144](https://github.com/knsv/mermaid/issues/144) - -**Merged pull requests:** - -- Make sequenceDiagram terminal newline optional [\#253](https://github.com/knsv/mermaid/pull/253) ([gibson042](https://github.com/gibson042)) -- Support sequenceDiagram "over" notes [\#252](https://github.com/knsv/mermaid/pull/252) ([gibson042](https://github.com/gibson042)) -- Properly handle "rest of line" statements [\#251](https://github.com/knsv/mermaid/pull/251) ([gibson042](https://github.com/gibson042)) -- CLI: Propagate exit code from lib \(i.e., phantomjs\) [\#250](https://github.com/knsv/mermaid/pull/250) ([gibson042](https://github.com/gibson042)) -- flowRender.js - Fix FontAwesome icon insert [\#244](https://github.com/knsv/mermaid/pull/244) ([ma-zal](https://github.com/ma-zal)) -- updated sequence diagram link in live editor [\#242](https://github.com/knsv/mermaid/pull/242) ([r-a-v-a-s](https://github.com/r-a-v-a-s)) -- updated links in README.md [\#240](https://github.com/knsv/mermaid/pull/240) ([r-a-v-a-s](https://github.com/r-a-v-a-s)) -- Ellipse syntax [\#237](https://github.com/knsv/mermaid/pull/237) ([spect88](https://github.com/spect88)) -- Allow keywords as suffixes of node ids [\#235](https://github.com/knsv/mermaid/pull/235) ([spect88](https://github.com/spect88)) -- Highlighted the editor in the nav [\#234](https://github.com/knsv/mermaid/pull/234) ([knsv](https://github.com/knsv)) -- Live editor tweaks [\#233](https://github.com/knsv/mermaid/pull/233) ([spect88](https://github.com/spect88)) -- Add a Gitter chat badge to README.md [\#230](https://github.com/knsv/mermaid/pull/230) ([gitter-badger](https://github.com/gitter-badger)) - -## [0.5.5](https://github.com/knsv/mermaid/tree/0.5.5) (2015-10-21) - -[Full Changelog](https://github.com/knsv/mermaid/compare/0.5.4...0.5.5) - -**Closed issues:** - -- sequence diagram, arrowhead instead of crosshead [\#227](https://github.com/knsv/mermaid/issues/227) - -**Merged pull requests:** - -- Fix a typo: crosshead --\> arrowhead [\#228](https://github.com/knsv/mermaid/pull/228) ([tylerlong](https://github.com/tylerlong)) - -## [0.5.4](https://github.com/knsv/mermaid/tree/0.5.4) (2015-10-19) - -[Full Changelog](https://github.com/knsv/mermaid/compare/0.5.3...0.5.4) - -**Closed issues:** - -- Weird bug in live editor when using words with substring `end` [\#184](https://github.com/knsv/mermaid/issues/184) -- Custom icons [\#15](https://github.com/knsv/mermaid/issues/15) -- Marker-end arrow cannot be shown for URL with query parameter [\#225](https://github.com/knsv/mermaid/issues/225) -- Please update bower's D3 version [\#221](https://github.com/knsv/mermaid/issues/221) -- Set log level from mermaid configuration [\#220](https://github.com/knsv/mermaid/issues/220) -- Width fixed to 400px [\#204](https://github.com/knsv/mermaid/issues/204) -- render to png from the cli does not display the marker-end arrow heads [\#181](https://github.com/knsv/mermaid/issues/181) -- Links in sequence diagrams [\#159](https://github.com/knsv/mermaid/issues/159) -- comment characters `%%` cause parse error [\#141](https://github.com/knsv/mermaid/issues/141) -- Add a reversed asymmetric shape [\#124](https://github.com/knsv/mermaid/issues/124) -- Add syntax for double headed arrows [\#123](https://github.com/knsv/mermaid/issues/123) -- Support for font-awesome [\#49](https://github.com/knsv/mermaid/issues/49) - -**Merged pull requests:** - -- Allow `end` as a substring of vertex id [\#224](https://github.com/knsv/mermaid/pull/224) ([spect88](https://github.com/spect88)) -- Remove duplicate npm dependencies: d3 and he [\#223](https://github.com/knsv/mermaid/pull/223) ([spect88](https://github.com/spect88)) - -## [0.5.3](https://github.com/knsv/mermaid/tree/0.5.3) (2015-10-04) - -[Full Changelog](https://github.com/knsv/mermaid/compare/0.5.2...0.5.3) - -## [0.5.2](https://github.com/knsv/mermaid/tree/0.5.2) (2015-10-04) - -[Full Changelog](https://github.com/knsv/mermaid/compare/0.5.1...0.5.2) - -**Closed issues:** - -- Installing “atom-mermaid@0.1.3” failed [\#218](https://github.com/knsv/mermaid/issues/218) -- Render mermaid code on websites? [\#215](https://github.com/knsv/mermaid/issues/215) -- Brackets in a node with text? [\#213](https://github.com/knsv/mermaid/issues/213) -- node feature request [\#211](https://github.com/knsv/mermaid/issues/211) -- Please add prefix for styles [\#208](https://github.com/knsv/mermaid/issues/208) -- Bad handling of block arguments [\#207](https://github.com/knsv/mermaid/issues/207) -- please consider port to mac osx [\#203](https://github.com/knsv/mermaid/issues/203) -- allow phantomjs \>=1.9.x [\#201](https://github.com/knsv/mermaid/issues/201) -- syntax for venn diagrams? [\#200](https://github.com/knsv/mermaid/issues/200) -- Broken CLI Graphs? \(v0.5.1\) [\#196](https://github.com/knsv/mermaid/issues/196) -- Static site does not render under HTTPS [\#194](https://github.com/knsv/mermaid/issues/194) -- Error on simple graph [\#192](https://github.com/knsv/mermaid/issues/192) -- Escape "~" [\#191](https://github.com/knsv/mermaid/issues/191) -- Trying to add link using 'click' to flowchart [\#188](https://github.com/knsv/mermaid/issues/188) -- cli: no lines and arrowheads rendered / only dotted lines [\#187](https://github.com/knsv/mermaid/issues/187) -- text of mermaid div displayed on page [\#186](https://github.com/knsv/mermaid/issues/186) -- using mermaid with laravel [\#185](https://github.com/knsv/mermaid/issues/185) -- Atom editor package [\#183](https://github.com/knsv/mermaid/issues/183) -- Auto linewrap for notes in sequence diagrams [\#178](https://github.com/knsv/mermaid/issues/178) -- Execute code after initialize [\#176](https://github.com/knsv/mermaid/issues/176) -- Autoscaling for all diagram types [\#175](https://github.com/knsv/mermaid/issues/175) -- Problem with click event callback [\#174](https://github.com/knsv/mermaid/issues/174) -- How to escape characters? [\#170](https://github.com/knsv/mermaid/issues/170) -- it can not work [\#167](https://github.com/knsv/mermaid/issues/167) -- UML Class diagram [\#154](https://github.com/knsv/mermaid/issues/154) -- Broken subgraph using the CLI [\#153](https://github.com/knsv/mermaid/issues/153) -- Support PlantUML syntax [\#149](https://github.com/knsv/mermaid/issues/149) -- IE Support issue [\#142](https://github.com/knsv/mermaid/issues/142) -- Flowchart truncated [\#140](https://github.com/knsv/mermaid/issues/140) -- Double Quote as text is not working [\#219](https://github.com/knsv/mermaid/issues/219) -- classDef / class not working with htmlLabels? [\#210](https://github.com/knsv/mermaid/issues/210) -- Links in graph missing [\#209](https://github.com/knsv/mermaid/issues/209) -- Last word in comment boxes getting cut off by word wrap library : \( [\#195](https://github.com/knsv/mermaid/issues/195) -- Escaping characters in sequence diagram [\#193](https://github.com/knsv/mermaid/issues/193) -- SVG foreignObject rendering [\#180](https://github.com/knsv/mermaid/issues/180) -- IE9 issue [\#179](https://github.com/knsv/mermaid/issues/179) -- inoperable in an AMD/requirejs environment: IPython Notebook [\#127](https://github.com/knsv/mermaid/issues/127) -- \[Parser\] Hyphen in participant name bring TypeError [\#74](https://github.com/knsv/mermaid/issues/74) -- Support for hyperlink and tooltip [\#34](https://github.com/knsv/mermaid/issues/34) - -**Merged pull requests:** - -- Update flowchart.md [\#214](https://github.com/knsv/mermaid/pull/214) ([orschiro](https://github.com/orschiro)) -- Default style when using the CLI [\#205](https://github.com/knsv/mermaid/pull/205) ([gillesdemey](https://github.com/gillesdemey)) -- Gantt chart - add minutes and seconds durations [\#198](https://github.com/knsv/mermaid/pull/198) ([dbrans](https://github.com/dbrans)) -- Using QUnit for AMD testing [\#190](https://github.com/knsv/mermaid/pull/190) ([bollwyvl](https://github.com/bollwyvl)) -- Update phantomscript.js [\#182](https://github.com/knsv/mermaid/pull/182) ([phairow](https://github.com/phairow)) - -## [0.5.1](https://github.com/knsv/mermaid/tree/0.5.1) (2015-06-21) - -[Full Changelog](https://github.com/knsv/mermaid/compare/0.5.0...0.5.1) - -**Closed issues:** - -- Live editor is broken [\#173](https://github.com/knsv/mermaid/issues/173) -- 0.5.0 no longer respects custom date definitions in Gantt diagrams [\#171](https://github.com/knsv/mermaid/issues/171) -- Drop label character restrictions [\#162](https://github.com/knsv/mermaid/issues/162) -- can't nest subgraphs in flowchart [\#161](https://github.com/knsv/mermaid/issues/161) -- Unable to generate gantt diagram with mermaid CLI [\#158](https://github.com/knsv/mermaid/issues/158) -- Inline css by "mermaid" [\#157](https://github.com/knsv/mermaid/issues/157) -- Finite State Machine Diagram [\#152](https://github.com/knsv/mermaid/issues/152) -- How to center align gantt diagram [\#150](https://github.com/knsv/mermaid/issues/150) -- Security concern regarding class definition [\#148](https://github.com/knsv/mermaid/issues/148) -- File Extension [\#147](https://github.com/knsv/mermaid/issues/147) -- To SVG Export [\#146](https://github.com/knsv/mermaid/issues/146) -- `setTimeout` with clusters problematic with programmatic edits and no callback [\#133](https://github.com/knsv/mermaid/issues/133) -- Possibility to set the width of the generated flowchart [\#129](https://github.com/knsv/mermaid/issues/129) -- flowchart - styling of edges via css overrides specific styles set in the graph definition [\#128](https://github.com/knsv/mermaid/issues/128) -- module.exports.cloneCssStyles\(\) in combination with Angularjs breaks display in Chrome and IE [\#126](https://github.com/knsv/mermaid/issues/126) -- Gantt - suitable xAxis for longer project [\#125](https://github.com/knsv/mermaid/issues/125) -- Mix horizontal and vertical graph [\#68](https://github.com/knsv/mermaid/issues/68) -- How to get started with this project ? [\#64](https://github.com/knsv/mermaid/issues/64) -- Special characters break parsing [\#54](https://github.com/knsv/mermaid/issues/54) -- Responsive graph layout for mobile viewers [\#51](https://github.com/knsv/mermaid/issues/51) -- Styling connector lines [\#31](https://github.com/knsv/mermaid/issues/31) - -**Merged pull requests:** - -- Remove moot `version` property from bower.json [\#172](https://github.com/knsv/mermaid/pull/172) ([kkirsche](https://github.com/kkirsche)) - -## [0.5.0](https://github.com/knsv/mermaid/tree/0.5.0) (2015-06-07) - -[Full Changelog](https://github.com/knsv/mermaid/compare/0.4.0...0.5.0) - -**Closed issues:** - -- it can not work where graph TD contains chinese character [\#166](https://github.com/knsv/mermaid/issues/166) -- Broken Examples [\#163](https://github.com/knsv/mermaid/issues/163) -- uglifyjs wanrings which means we can improve the code [\#156](https://github.com/knsv/mermaid/issues/156) -- New\(er\) features unavailable in downloadable js files? [\#151](https://github.com/knsv/mermaid/issues/151) -- Add gh-gapes link to description [\#143](https://github.com/knsv/mermaid/issues/143) -- Some examples not displayed on Firefox 36.0.1 [\#138](https://github.com/knsv/mermaid/issues/138) -- tags ending in a "v" don't render [\#132](https://github.com/knsv/mermaid/issues/132) -- Links in flowchart [\#131](https://github.com/knsv/mermaid/issues/131) -- Using the library for iOS development [\#130](https://github.com/knsv/mermaid/issues/130) -- Add a css file, mermaid.css, with default styling [\#122](https://github.com/knsv/mermaid/issues/122) -- Add capability for gantt diagrams [\#118](https://github.com/knsv/mermaid/issues/118) -- lower case v causes error in the parser [\#108](https://github.com/knsv/mermaid/issues/108) -- Label's css conflict with boostrap's .label [\#67](https://github.com/knsv/mermaid/issues/67) -- TypeError: Cannot read property 'layout' of undefined [\#37](https://github.com/knsv/mermaid/issues/37) -- software architecture diagram [\#36](https://github.com/knsv/mermaid/issues/36) -- Support for bar charts and pie diagrams [\#22](https://github.com/knsv/mermaid/issues/22) - -**Merged pull requests:** - -- Dev 0.5.0 [\#168](https://github.com/knsv/mermaid/pull/168) ([knsv](https://github.com/knsv)) -- Fix spacing [\#164](https://github.com/knsv/mermaid/pull/164) ([rhcarvalho](https://github.com/rhcarvalho)) -- Fixing typo: "Think" -\> "Thick" [\#160](https://github.com/knsv/mermaid/pull/160) ([it0a](https://github.com/it0a)) -- IE, local html, cssRules access is denied [\#155](https://github.com/knsv/mermaid/pull/155) ([tylerlong](https://github.com/tylerlong)) -- Add automatically generated change log file. [\#139](https://github.com/knsv/mermaid/pull/139) ([skywinder](https://github.com/skywinder)) -- Adding init argument to the global API [\#137](https://github.com/knsv/mermaid/pull/137) ([bollwyvl](https://github.com/bollwyvl)) -- Add description of manual calling of init [\#136](https://github.com/knsv/mermaid/pull/136) ([bollwyvl](https://github.com/bollwyvl)) -- Allow other forms of node selection for init\(\) [\#135](https://github.com/knsv/mermaid/pull/135) ([bollwyvl](https://github.com/bollwyvl)) -- Use a library-level variable for assigning ids [\#134](https://github.com/knsv/mermaid/pull/134) ([bollwyvl](https://github.com/bollwyvl)) - -## [0.4.0](https://github.com/knsv/mermaid/tree/0.4.0) (2015-03-01) - -[Full Changelog](https://github.com/knsv/mermaid/compare/0.3.5...0.4.0) - -**Closed issues:** - -- subgraph background is black in rendered flowchart PNG via CLI [\#121](https://github.com/knsv/mermaid/issues/121) -- Integrate editor at https://github.com/naseer/mermaid-webapp [\#110](https://github.com/knsv/mermaid/issues/110) -- Internet Explorer Support [\#99](https://github.com/knsv/mermaid/issues/99) -- Asymmetric shapes not documented [\#82](https://github.com/knsv/mermaid/issues/82) -- NoModificationAllowedError [\#23](https://github.com/knsv/mermaid/issues/23) -- Improve arrows [\#3](https://github.com/knsv/mermaid/issues/3) - -## [0.3.5](https://github.com/knsv/mermaid/tree/0.3.5) (2015-02-15) - -[Full Changelog](https://github.com/knsv/mermaid/compare/0.3.4...0.3.5) - -## [0.3.4](https://github.com/knsv/mermaid/tree/0.3.4) (2015-02-15) - -[Full Changelog](https://github.com/knsv/mermaid/compare/0.3.3...0.3.4) - -**Closed issues:** - -- Subgraph syntax bug? [\#120](https://github.com/knsv/mermaid/issues/120) -- Live editor [\#115](https://github.com/knsv/mermaid/issues/115) -- Error in "Basic Syntax" wiki page [\#113](https://github.com/knsv/mermaid/issues/113) -- semicolons, anyone? [\#111](https://github.com/knsv/mermaid/issues/111) -- undefined `sequenceConfig` fails [\#109](https://github.com/knsv/mermaid/issues/109) -- Sequence Diagrams: Show Actors below as well [\#106](https://github.com/knsv/mermaid/issues/106) -- Allow overriding sequence diagram configuration \(SVG properties\) [\#103](https://github.com/knsv/mermaid/issues/103) -- Error when rendering A-- This is the text -- B [\#102](https://github.com/knsv/mermaid/issues/102) -- Clipping in documentation [\#97](https://github.com/knsv/mermaid/issues/97) -- isolate class styling to the svg container [\#92](https://github.com/knsv/mermaid/issues/92) -- Apply styling from css when using the CLI utility [\#85](https://github.com/knsv/mermaid/issues/85) -- Generated SVG works poorly outside web browsers [\#58](https://github.com/knsv/mermaid/issues/58) -- Make the new graph declaration more visual [\#40](https://github.com/knsv/mermaid/issues/40) -- Generating SVG text blob for use in Node [\#2](https://github.com/knsv/mermaid/issues/2) - -**Merged pull requests:** - -- Add live editor [\#119](https://github.com/knsv/mermaid/pull/119) ([naseer](https://github.com/naseer)) -- Adds CSS option to the CLI [\#116](https://github.com/knsv/mermaid/pull/116) ([fardog](https://github.com/fardog)) -- Update flowchart.md in response Issue \#113 [\#114](https://github.com/knsv/mermaid/pull/114) ([vijay40](https://github.com/vijay40)) -- Ignore all files except the license and dist/ folder when installing with Bower. [\#112](https://github.com/knsv/mermaid/pull/112) ([jasonbellamy](https://github.com/jasonbellamy)) - -## [0.3.3](https://github.com/knsv/mermaid/tree/0.3.3) (2015-01-25) - -[Full Changelog](https://github.com/knsv/mermaid/compare/0.3.2...0.3.3) - -**Closed issues:** - -- Missing arrows in sequence diagram [\#98](https://github.com/knsv/mermaid/issues/98) -- Error with \>9 linkStyles [\#95](https://github.com/knsv/mermaid/issues/95) -- Support for dotted links [\#26](https://github.com/knsv/mermaid/issues/26) - -**Merged pull requests:** - -- Require d3 directly to better support Node usage [\#107](https://github.com/knsv/mermaid/pull/107) ([markdalgleish](https://github.com/markdalgleish)) -- update doc with -c option [\#105](https://github.com/knsv/mermaid/pull/105) ([jjmr](https://github.com/jjmr)) -- Add new parameter to the console client to override the svg configuration in sequence diagrams [\#104](https://github.com/knsv/mermaid/pull/104) ([jjmr](https://github.com/jjmr)) -- Text based labels, new shape [\#101](https://github.com/knsv/mermaid/pull/101) ([bjowes](https://github.com/bjowes)) -- fix html tags in example usage [\#100](https://github.com/knsv/mermaid/pull/100) ([deiwin](https://github.com/deiwin)) - -## [0.3.2](https://github.com/knsv/mermaid/tree/0.3.2) (2015-01-11) - -[Full Changelog](https://github.com/knsv/mermaid/compare/0.3.1...0.3.2) - -**Closed issues:** - -- disable auto render [\#91](https://github.com/knsv/mermaid/issues/91) -- Tidy breaks mermaid \(linebreaks in \\) [\#87](https://github.com/knsv/mermaid/issues/87) -- Bug: \ being rendered as text in node [\#73](https://github.com/knsv/mermaid/issues/73) -- Graph edges appear to render outside of the canvas [\#70](https://github.com/knsv/mermaid/issues/70) -- Make link text look like it is on the line [\#53](https://github.com/knsv/mermaid/issues/53) - -**Merged pull requests:** - -- Merge pull request \#1 from knsv/master [\#96](https://github.com/knsv/mermaid/pull/96) ([gkchic](https://github.com/gkchic)) -- Removed duplicated section in flowchart docs [\#94](https://github.com/knsv/mermaid/pull/94) ([kaime](https://github.com/kaime)) -- Grammar changes to sequence page [\#93](https://github.com/knsv/mermaid/pull/93) ([gkchic](https://github.com/gkchic)) -- GitHub buttons [\#89](https://github.com/knsv/mermaid/pull/89) ([gkchic](https://github.com/gkchic)) -- Template change [\#88](https://github.com/knsv/mermaid/pull/88) ([gkchic](https://github.com/gkchic)) - -## [0.3.1](https://github.com/knsv/mermaid/tree/0.3.1) (2015-01-05) - -[Full Changelog](https://github.com/knsv/mermaid/compare/0.3.0...0.3.1) - -**Closed issues:** - -- Non ASCII chars in labels [\#84](https://github.com/knsv/mermaid/issues/84) -- 'undefined' titles of Quicklinks on the usage page [\#80](https://github.com/knsv/mermaid/issues/80) -- \[cli\] Enhancement proposal: not fail --version / --help if phantomjs isn't installed [\#71](https://github.com/knsv/mermaid/issues/71) -- Neural Networks [\#39](https://github.com/knsv/mermaid/issues/39) -- Support for sequence diagrams [\#16](https://github.com/knsv/mermaid/issues/16) -- Client utility for mermaid [\#6](https://github.com/knsv/mermaid/issues/6) - -**Merged pull requests:** - -- Flowchart doc: Text in the circle now in a circle [\#81](https://github.com/knsv/mermaid/pull/81) ([Grahack](https://github.com/Grahack)) -- Fix for issue \#73 [\#79](https://github.com/knsv/mermaid/pull/79) ([it0a](https://github.com/it0a)) -- Ink template [\#78](https://github.com/knsv/mermaid/pull/78) ([gkchic](https://github.com/gkchic)) -- Show help and version even if phantom isn't present. Fixes \#71 [\#75](https://github.com/knsv/mermaid/pull/75) ([fardog](https://github.com/fardog)) -- Add apostrophe & 'and' [\#72](https://github.com/knsv/mermaid/pull/72) ([sudodoki](https://github.com/sudodoki)) - -## [0.3.0](https://github.com/knsv/mermaid/tree/0.3.0) (2014-12-22) - -[Full Changelog](https://github.com/knsv/mermaid/compare/0.2.16...0.3.0) - -**Closed issues:** - -- Consider shipping a standalone executable [\#65](https://github.com/knsv/mermaid/issues/65) -- Trailing whitespace at the end of lines is not ignored [\#55](https://github.com/knsv/mermaid/issues/55) -- How do I do comments? [\#47](https://github.com/knsv/mermaid/issues/47) -- This characters failed the lexical parsing [\#46](https://github.com/knsv/mermaid/issues/46) -- tutorial for creating new type of graph/layout [\#44](https://github.com/knsv/mermaid/issues/44) -- Improve readability with new line as terminator and whitespace [\#38](https://github.com/knsv/mermaid/issues/38) -- Use classes instead of inline style for easy styling [\#24](https://github.com/knsv/mermaid/issues/24) - -**Merged pull requests:** - -- Adds Command Line Interface for generating PNGs from mermaid description files [\#69](https://github.com/knsv/mermaid/pull/69) ([fardog](https://github.com/fardog)) -- Allow special symbols for direction along with acronyms [\#66](https://github.com/knsv/mermaid/pull/66) ([vijay40](https://github.com/vijay40)) - -## [0.2.16](https://github.com/knsv/mermaid/tree/0.2.16) (2014-12-15) - -[Full Changelog](https://github.com/knsv/mermaid/compare/0.2.15...0.2.16) - -**Closed issues:** - -- Mermaid not rendering properly on Wordpress pages [\#59](https://github.com/knsv/mermaid/issues/59) -- Improve example page with live demo [\#52](https://github.com/knsv/mermaid/issues/52) -- Create image file via CLI? [\#48](https://github.com/knsv/mermaid/issues/48) -- Does not render upon AngularJS Updates [\#45](https://github.com/knsv/mermaid/issues/45) -- Download link in README.MD doesn't work. [\#42](https://github.com/knsv/mermaid/issues/42) -- linkStyle usage is not obvious [\#41](https://github.com/knsv/mermaid/issues/41) -- Move \*.spec.js in src/ to test/ [\#35](https://github.com/knsv/mermaid/issues/35) -- Lines routed outside visible area [\#19](https://github.com/knsv/mermaid/issues/19) - -**Merged pull requests:** - -- New grammar will allow statements ending without semicolon as disccused in Issue \#38 [\#63](https://github.com/knsv/mermaid/pull/63) ([vijay40](https://github.com/vijay40)) -- Class based styling [\#62](https://github.com/knsv/mermaid/pull/62) ([bjowes](https://github.com/bjowes)) -- Fix typos [\#60](https://github.com/knsv/mermaid/pull/60) ([sublimino](https://github.com/sublimino)) -- Included .DS_Store in gitignore [\#57](https://github.com/knsv/mermaid/pull/57) ([alvynmcq](https://github.com/alvynmcq)) -- Improves readablity discussed in issue \#38 [\#56](https://github.com/knsv/mermaid/pull/56) ([vijay40](https://github.com/vijay40)) -- Added a linting task for gulp [\#43](https://github.com/knsv/mermaid/pull/43) ([serv](https://github.com/serv)) - -## [0.2.15](https://github.com/knsv/mermaid/tree/0.2.15) (2014-12-05) - -[Full Changelog](https://github.com/knsv/mermaid/compare/0.2.14...0.2.15) - -**Closed issues:** - -- Question marks don't render properly with /dist/mermaid.full.min.js [\#30](https://github.com/knsv/mermaid/issues/30) -- Error with some characters [\#25](https://github.com/knsv/mermaid/issues/25) -- Provide parse function in browser without `require`? [\#21](https://github.com/knsv/mermaid/issues/21) -- Better label text support [\#18](https://github.com/knsv/mermaid/issues/18) -- Cap-cased words break parser [\#8](https://github.com/knsv/mermaid/issues/8) - -**Merged pull requests:** - -- Include bower_components/ to .gitignore [\#33](https://github.com/knsv/mermaid/pull/33) ([serv](https://github.com/serv)) -- Fixed reference to Git repo. [\#32](https://github.com/knsv/mermaid/pull/32) ([guyellis](https://github.com/guyellis)) - -## [0.2.14](https://github.com/knsv/mermaid/tree/0.2.14) (2014-12-03) - -[Full Changelog](https://github.com/knsv/mermaid/compare/0.2.13...0.2.14) - -## [0.2.13](https://github.com/knsv/mermaid/tree/0.2.13) (2014-12-03) - -[Full Changelog](https://github.com/knsv/mermaid/compare/0.2.10...0.2.13) - -**Closed issues:** - -- modified init to be applied more than once [\#29](https://github.com/knsv/mermaid/issues/29) -- Wanted to know build process for the project. [\#28](https://github.com/knsv/mermaid/issues/28) -- Container support [\#27](https://github.com/knsv/mermaid/issues/27) -- can not support Chinese description [\#20](https://github.com/knsv/mermaid/issues/20) -- Node Label text mistaken for Direction [\#17](https://github.com/knsv/mermaid/issues/17) -- Support unicode chars in labels [\#9](https://github.com/knsv/mermaid/issues/9) -- Publish to NPM [\#7](https://github.com/knsv/mermaid/issues/7) - -## [0.2.10](https://github.com/knsv/mermaid/tree/0.2.10) (2014-12-01) - -[Full Changelog](https://github.com/knsv/mermaid/compare/0.2.9...0.2.10) - -## [0.2.9](https://github.com/knsv/mermaid/tree/0.2.9) (2014-12-01) - -[Full Changelog](https://github.com/knsv/mermaid/compare/0.2.8...0.2.9) - -**Closed issues:** - -- Add link to jsbin playground to README [\#11](https://github.com/knsv/mermaid/issues/11) -- What are the requirements ? [\#10](https://github.com/knsv/mermaid/issues/10) - -**Merged pull requests:** - -- Allow unicode chars in labels [\#13](https://github.com/knsv/mermaid/pull/13) ([codebeige](https://github.com/codebeige)) - -## [0.2.8](https://github.com/knsv/mermaid/tree/0.2.8) (2014-12-01) - -[Full Changelog](https://github.com/knsv/mermaid/compare/0.2.7...0.2.8) - -## [0.2.7](https://github.com/knsv/mermaid/tree/0.2.7) (2014-12-01) - -[Full Changelog](https://github.com/knsv/mermaid/compare/0.2.6...0.2.7) - -**Closed issues:** - -- Provide parser as separate module [\#4](https://github.com/knsv/mermaid/issues/4) - -## [0.2.6](https://github.com/knsv/mermaid/tree/0.2.6) (2014-11-27) - -[Full Changelog](https://github.com/knsv/mermaid/compare/0.2.5...0.2.6) - -## [0.2.5](https://github.com/knsv/mermaid/tree/0.2.5) (2014-11-27) - -[Full Changelog](https://github.com/knsv/mermaid/compare/0.2.4...0.2.5) - -**Merged pull requests:** - -- Added new shapes! [\#1](https://github.com/knsv/mermaid/pull/1) ([bjowes](https://github.com/bjowes)) - -## [0.2.4](https://github.com/knsv/mermaid/tree/0.2.4) (2014-11-25) - -[Full Changelog](https://github.com/knsv/mermaid/compare/0.2.3...0.2.4) - -## [0.2.3](https://github.com/knsv/mermaid/tree/0.2.3) (2014-11-24) - -[Full Changelog](https://github.com/knsv/mermaid/compare/0.2.2...0.2.3) - -## [0.2.2](https://github.com/knsv/mermaid/tree/0.2.2) (2014-11-22) - -[Full Changelog](https://github.com/knsv/mermaid/compare/0.2.1...0.2.2) - -## [0.2.1](https://github.com/knsv/mermaid/tree/0.2.1) (2014-11-22) - -[Full Changelog](https://github.com/knsv/mermaid/compare/0.2.0...0.2.1) - -## [0.2.0](https://github.com/knsv/mermaid/tree/0.2.0) (2014-11-22) - -[Full Changelog](https://github.com/knsv/mermaid/compare/0.1.1...0.2.0) - -## [0.1.1](https://github.com/knsv/mermaid/tree/0.1.1) (2014-11-17) - -[Full Changelog](https://github.com/knsv/mermaid/compare/0.1.0...0.1.1) - -## [0.1.0](https://github.com/knsv/mermaid/tree/0.1.0) (2014-11-16) - -\* _This Change Log was automatically generated by [github_changelog_generator](https://github.com/skywinder/GitHub-Changelog-Generator)_ diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 120000 index 000000000..c68d3f76d --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1 @@ +./packages/mermaid/CHANGELOG.md \ No newline at end of file diff --git a/cypress/helpers/util.ts b/cypress/helpers/util.ts index 81b7036af..ab4bbef64 100644 --- a/cypress/helpers/util.ts +++ b/cypress/helpers/util.ts @@ -14,7 +14,7 @@ interface CodeObject { mermaid: CypressMermaidConfig; } -const utf8ToB64 = (str: string): string => { +export const utf8ToB64 = (str: string): string => { return Buffer.from(decodeURIComponent(encodeURIComponent(str))).toString('base64'); }; @@ -22,7 +22,7 @@ const batchId: string = 'mermaid-batch-' + (Cypress.env('useAppli') ? Date.now().toString() - : Cypress.env('CYPRESS_COMMIT') || Date.now().toString()); + : (Cypress.env('CYPRESS_COMMIT') ?? Date.now().toString())); export const mermaidUrl = ( graphStr: string | string[], @@ -61,9 +61,7 @@ export const imgSnapshotTest = ( sequence: { ...(_options.sequence ?? {}), actorFontFamily: 'courier', - noteFontFamily: _options.sequence?.noteFontFamily - ? _options.sequence.noteFontFamily - : 'courier', + noteFontFamily: _options.sequence?.noteFontFamily ?? 'courier', messageFontFamily: 'courier', }, }; diff --git a/cypress/integration/other/xss.spec.js b/cypress/integration/other/xss.spec.js index 1e51d2f23..35a493850 100644 --- a/cypress/integration/other/xss.spec.js +++ b/cypress/integration/other/xss.spec.js @@ -1,4 +1,4 @@ -import { mermaidUrl } from '../../helpers/util.ts'; +import { imgSnapshotTest, mermaidUrl, utf8ToB64 } from '../../helpers/util.ts'; describe('XSS', () => { it('should handle xss in tags', () => { const str = @@ -141,4 +141,37 @@ describe('XSS', () => { cy.wait(1000); cy.get('#the-malware').should('not.exist'); }); + + it('should sanitize icon labels in architecture diagrams', () => { + const str = JSON.stringify({ + code: `architecture-beta + group api(cloud)[API] + service db "" [Database] in api`, + }); + imgSnapshotTest(utf8ToB64(str), {}, true); + cy.wait(1000); + cy.get('#the-malware').should('not.exist'); + }); + + it('should sanitize katex blocks', () => { + const str = JSON.stringify({ + code: `sequenceDiagram + participant A as Alice$$\\text{Alice}$$ + A->>John: Hello John, how are you?`, + }); + imgSnapshotTest(utf8ToB64(str), {}, true); + cy.wait(1000); + cy.get('#the-malware').should('not.exist'); + }); + + it('should sanitize labels', () => { + const str = JSON.stringify({ + code: `erDiagram + "" ||--|| ENTITY2 : "" + `, + }); + imgSnapshotTest(utf8ToB64(str), {}, true); + cy.wait(1000); + cy.get('#the-malware').should('not.exist'); + }); }); diff --git a/cypress/integration/rendering/block.spec.js b/cypress/integration/rendering/block.spec.js index 589a30fde..27e23cd91 100644 --- a/cypress/integration/rendering/block.spec.js +++ b/cypress/integration/rendering/block.spec.js @@ -16,7 +16,7 @@ describe('Block diagram', () => { it('BL2: should handle columns statement in sub-blocks', () => { imgSnapshotTest( - `block-beta + `block id1["Hello"] block columns 3 @@ -32,7 +32,7 @@ describe('Block diagram', () => { it('BL3: should align block widths and handle columns statement in sub-blocks', () => { imgSnapshotTest( - `block-beta + `block block columns 1 id1 @@ -48,7 +48,7 @@ describe('Block diagram', () => { it('BL4: should align block widths and handle columns statements in deeper sub-blocks then 1 level', () => { imgSnapshotTest( - `block-beta + `block columns 1 block columns 1 @@ -68,7 +68,7 @@ describe('Block diagram', () => { it('BL5: should align block widths and handle columns statements in deeper sub-blocks then 1 level (alt)', () => { imgSnapshotTest( - `block-beta + `block columns 1 block id1 @@ -87,7 +87,7 @@ describe('Block diagram', () => { it('BL6: should handle block arrows and spece statements', () => { imgSnapshotTest( - `block-beta + `block columns 3 space:3 ida idb idc @@ -106,7 +106,7 @@ describe('Block diagram', () => { it('BL7: should handle different types of edges', () => { imgSnapshotTest( - `block-beta + `block columns 3 A space:5 A --o B @@ -119,7 +119,7 @@ describe('Block diagram', () => { it('BL8: should handle sub-blocks without columns statements', () => { imgSnapshotTest( - `block-beta + `block columns 2 C A B block @@ -133,7 +133,7 @@ describe('Block diagram', () => { it('BL9: should handle edges from blocks in sub blocks to other blocks', () => { imgSnapshotTest( - `block-beta + `block columns 3 B space block @@ -147,7 +147,7 @@ describe('Block diagram', () => { it('BL10: should handle edges from composite blocks', () => { imgSnapshotTest( - `block-beta + `block columns 3 B space block BL @@ -161,7 +161,7 @@ describe('Block diagram', () => { it('BL11: should handle edges to composite blocks', () => { imgSnapshotTest( - `block-beta + `block columns 3 B space block BL @@ -175,7 +175,7 @@ describe('Block diagram', () => { it('BL12: edges should handle labels', () => { imgSnapshotTest( - `block-beta + `block A space A -- "apa" --> E @@ -186,7 +186,7 @@ describe('Block diagram', () => { it('BL13: should handle block arrows in different directions', () => { imgSnapshotTest( - `block-beta + `block columns 3 space blockArrowId1<["down"]>(down) space blockArrowId2<["right"]>(right) blockArrowId3<["Sync"]>(x, y) blockArrowId4<["left"]>(left) @@ -199,7 +199,7 @@ describe('Block diagram', () => { it('BL14: should style statements and class statements', () => { imgSnapshotTest( - `block-beta + `block A B classDef blue fill:#66f,stroke:#333,stroke-width:2px; @@ -212,7 +212,7 @@ describe('Block diagram', () => { it('BL15: width alignment - D and E should share available space', () => { imgSnapshotTest( - `block-beta + `block block D E @@ -225,7 +225,7 @@ describe('Block diagram', () => { it('BL16: width alignment - C should be as wide as the composite block', () => { imgSnapshotTest( - `block-beta + `block block A("This is the text") B @@ -238,7 +238,7 @@ describe('Block diagram', () => { it('BL17: width alignment - blocks should be equal in width', () => { imgSnapshotTest( - `block-beta + `block A("This is the text") B C @@ -249,7 +249,7 @@ describe('Block diagram', () => { it('BL18: block types 1 - square, rounded and circle', () => { imgSnapshotTest( - `block-beta + `block A["square"] B("rounded") C(("circle")) @@ -260,7 +260,7 @@ describe('Block diagram', () => { it('BL19: block types 2 - odd, diamond and hexagon', () => { imgSnapshotTest( - `block-beta + `block A>"rect_left_inv_arrow"] B{"diamond"} C{{"hexagon"}} @@ -271,7 +271,7 @@ describe('Block diagram', () => { it('BL20: block types 3 - stadium', () => { imgSnapshotTest( - `block-beta + `block A(["stadium"]) `, {} @@ -280,7 +280,7 @@ describe('Block diagram', () => { it('BL21: block types 4 - lean right, lean left, trapezoid and inv trapezoid', () => { imgSnapshotTest( - `block-beta + `block A[/"lean right"/] B[\"lean left"\] C[/"trapezoid"\] @@ -292,7 +292,7 @@ describe('Block diagram', () => { it('BL22: block types 1 - square, rounded and circle', () => { imgSnapshotTest( - `block-beta + `block A["square"] B("rounded") C(("circle")) @@ -303,7 +303,7 @@ describe('Block diagram', () => { it('BL23: sizing - it should be possible to make a block wider', () => { imgSnapshotTest( - `block-beta + `block A("rounded"):2 B:2 C @@ -314,7 +314,7 @@ describe('Block diagram', () => { it('BL24: sizing - it should be possible to make a composite block wider', () => { imgSnapshotTest( - `block-beta + `block block:2 A end @@ -326,7 +326,7 @@ describe('Block diagram', () => { it('BL25: block in the middle with space on each side', () => { imgSnapshotTest( - `block-beta + `block columns 3 space middle["In the middle"] @@ -337,7 +337,7 @@ describe('Block diagram', () => { }); it('BL26: space and an edge', () => { imgSnapshotTest( - `block-beta + `block columns 5 A space B A --x B @@ -347,7 +347,7 @@ describe('Block diagram', () => { }); it('BL27: block sizes for regular blocks', () => { imgSnapshotTest( - `block-beta + `block columns 3 a["A wide one"] b:2 c:2 d `, @@ -356,7 +356,7 @@ describe('Block diagram', () => { }); it('BL28: composite block with a set width - f should use the available space', () => { imgSnapshotTest( - `block-beta + `block columns 3 a:3 block:e:3 @@ -370,7 +370,7 @@ describe('Block diagram', () => { it('BL29: composite block with a set width - f and g should split the available space', () => { imgSnapshotTest( - `block-beta + `block columns 3 a:3 block:e:3 @@ -384,4 +384,28 @@ describe('Block diagram', () => { {} ); }); + + it('BL30: block should overflow if too wide for columns', () => { + imgSnapshotTest( + `block-beta + columns 2 + fit:2 + overflow:3 + short:1 + also_overflow:2 +`, + {} + ); + }); + + it('BL31: edge without arrow syntax should render with no arrowheads', () => { + imgSnapshotTest( + `block-beta + a + b + a --- b +`, + {} + ); + }); }); diff --git a/cypress/integration/rendering/classDiagram.spec.js b/cypress/integration/rendering/classDiagram.spec.js index e7d201b5d..6cea402f8 100644 --- a/cypress/integration/rendering/classDiagram.spec.js +++ b/cypress/integration/rendering/classDiagram.spec.js @@ -495,4 +495,47 @@ describe('Class diagram', () => { cy.get('a').should('have.attr', 'target', '_blank').should('have.attr', 'rel', 'noopener'); }); }); + + describe('Include char sequence "graph" in text (#6795)', () => { + it('has a label with char sequence "graph"', () => { + imgSnapshotTest( + ` + classDiagram + class Person { + +String name + -Int id + #double age + +Text demographicProfile + } + `, + { flowchart: { defaultRenderer: 'elk' } } + ); + }); + }); + + it('should handle backticks for namespace and class names', () => { + imgSnapshotTest( + ` + classDiagram + namespace \`A::B\` { + class \`IPC::Sender\` + } + RenderProcessHost --|> \`IPC::Sender\` + `, + {} + ); + it('should handle an empty class body with empty braces', () => { + imgSnapshotTest( + ` classDiagram + class FooBase~T~ {} + class Bar { + +Zip + +Zap() + } + FooBase <|-- Ba + `, + { flowchart: { defaultRenderer: 'elk' } } + ); + }); + }); }); diff --git a/cypress/integration/rendering/erDiagram.spec.js b/cypress/integration/rendering/erDiagram.spec.js index cbfec8218..8f6193f96 100644 --- a/cypress/integration/rendering/erDiagram.spec.js +++ b/cypress/integration/rendering/erDiagram.spec.js @@ -354,4 +354,19 @@ ORDER ||--|{ LINE-ITEM : contains { logLevel: 1 } ); }); + + describe('Include char sequence "graph" in text (#6795)', () => { + it('has a label with char sequence "graph"', () => { + imgSnapshotTest( + ` + erDiagram + p[Photograph] { + varchar(12) jobId + date dateCreated + } + `, + { flowchart: { defaultRenderer: 'elk' } } + ); + }); + }); }); diff --git a/cypress/integration/rendering/flowchart-elk.spec.js b/cypress/integration/rendering/flowchart-elk.spec.js index 27af2c40c..312e1d5b4 100644 --- a/cypress/integration/rendering/flowchart-elk.spec.js +++ b/cypress/integration/rendering/flowchart-elk.spec.js @@ -1053,6 +1053,21 @@ flowchart LR }); }); }); + + it('6647-elk: should keep node order when using elk layout unless it would add crossings', () => { + imgSnapshotTest( + `--- +config: + layout: elk +--- + flowchart TB + a --> a1 & a2 & a3 & a4 + b --> b1 & b2 + b2 --> b3 + b1 --> b4 + ` + ); + }); }); describe('Title and arrow styling #4813', () => { diff --git a/cypress/integration/rendering/flowchart-v2.spec.js b/cypress/integration/rendering/flowchart-v2.spec.js index 97fc1ecbd..8c6cde57a 100644 --- a/cypress/integration/rendering/flowchart-v2.spec.js +++ b/cypress/integration/rendering/flowchart-v2.spec.js @@ -1113,4 +1113,77 @@ end ); }); }); + describe('Flowchart Node Shape Rendering', () => { + it('should render a stadium-shaped node', () => { + imgSnapshotTest( + `flowchart TB + A(["Start"]) --> n1["Untitled Node"] + A --> n2["Untitled Node"] + `, + {} + ); + }); + it('should render a diamond-shaped node using shape config', () => { + imgSnapshotTest( + `flowchart BT + n2["Untitled Node"] --> n1["Diamond"] + n1@{ shape: diam} + `, + {} + ); + }); + it('should render a rounded rectangle and a normal rectangle', () => { + imgSnapshotTest( + `flowchart BT + n2["Untitled Node"] --> n1["Rounded Rectangle"] + n3["Untitled Node"] --> n1 + n1@{ shape: rounded} + n3@{ shape: rect} + `, + {} + ); + }); + }); + + it('6617: Per Link Curve Styling using edge Ids', () => { + imgSnapshotTest( + `flowchart TD + A e1@-->B e5@--> E + E e7@--> D + B e3@-->D + A e2@-->C e4@-->D + C e6@--> F + F e8@--> D + e1@{ curve: natural } + e2@{ curve: stepAfter } + e3@{ curve: monotoneY } + e4@{ curve: bumpY } + e5@{ curve: linear } + e6@{ curve: catmullRom } + e7@{ curve: cardinal } + ` + ); + }); + + describe('when rendering unsuported markdown', () => { + const graph = `flowchart TB + mermaid{"What is\nyourmermaid version?"} --> v10["<11"] --"\`<**1**1\`"--> fine["No bug"] + mermaid --> v11[">= v11"] -- ">= v11" --> broken["Affected by https://github.com/mermaid-js/mermaid/issues/5824"] + subgraph subgraph1["\`How to fix **fix**\`"] + broken --> B["B"] + end + githost["Github, Gitlab, BitBucket, etc."] + githost2["\`Github, Gitlab, BitBucket, etc.\`"] + a["1."] + b["- x"] + `; + + it('should render raw strings', () => { + imgSnapshotTest(graph); + }); + + it('should render raw strings with htmlLabels: false', () => { + imgSnapshotTest(graph, { htmlLabels: false }); + }); + }); }); diff --git a/cypress/integration/rendering/gantt.spec.js b/cypress/integration/rendering/gantt.spec.js index 2cc67918c..32dbcb4d9 100644 --- a/cypress/integration/rendering/gantt.spec.js +++ b/cypress/integration/rendering/gantt.spec.js @@ -565,6 +565,18 @@ describe('Gantt diagram', () => { ); }); + it('should render only the day when using dateFormat D', () => { + imgSnapshotTest( + ` + gantt + title Test + dateFormat D + A :a, 1, 1d + `, + {} + ); + }); + // TODO: fix it // // This test is skipped deliberately @@ -647,6 +659,49 @@ describe('Gantt diagram', () => { ); }); + it('should render a gantt diagram excluding a specific date in YYYY-MM-DD HH:mm:ss format', () => { + imgSnapshotTest( + ` + gantt + dateFormat YYYY-MM-DD HH:mm:ss + excludes 2025-07-07 + section Section + A task :a1, 2025-07-04 20:30:30, 2025-07-08 10:30:30 + Another task:after a1, 20h + `, + {} + ); + }); + + it('should render a gantt diagram excluding saturday and sunday in YYYY-MM-DD HH:mm:ss format', () => { + imgSnapshotTest( + ` + gantt + dateFormat YYYY-MM-DD HH:mm:ss + excludes weekends + weekend saturday + section Section + A task :a1, 2025-07-04 20:30:30, 2025-07-08 10:30:30 + Another task:after a1, 20h + `, + {} + ); + }); + it('should render a gantt diagram excluding friday and saturday in YYYY-MM-DD HH:mm:ss format', () => { + imgSnapshotTest( + ` + gantt + dateFormat YYYY-MM-DD HH:mm:ss + excludes weekends + weekend friday + section Section + A task :a1, 2025-07-04 20:30:30, 2025-07-08 10:30:30 + Another task:after a1, 20h + `, + {} + ); + }); + it("should render when there's a semicolon in the title", () => { imgSnapshotTest( ` diff --git a/cypress/integration/rendering/mindmap-tidy-tree.spec.js b/cypress/integration/rendering/mindmap-tidy-tree.spec.js new file mode 100644 index 000000000..e111c281a --- /dev/null +++ b/cypress/integration/rendering/mindmap-tidy-tree.spec.js @@ -0,0 +1,79 @@ +import { imgSnapshotTest } from '../../helpers/util.ts'; + +describe('Mindmap Tidy Tree', () => { + it('1-tidy-tree: should render a simple mindmap without children', () => { + imgSnapshotTest( + ` --- + config: + layout: tidy-tree + --- + mindmap + root((mindmap)) + A + B + ` + ); + }); + it('2-tidy-tree: should render a simple mindmap', () => { + imgSnapshotTest( + ` --- + config: + layout: tidy-tree + --- + mindmap + root((mindmap is a long thing)) + A + B + C + D + ` + ); + }); + it('3-tidy-tree: should render a mindmap with different shapes', () => { + imgSnapshotTest( + ` --- + config: + layout: tidy-tree + --- + mindmap + root((mindmap)) + Origins + Long history + ::icon(fa fa-book) + Popularisation + British popular psychology author Tony Buzan + Research + On effectiveness<br/>and features + On Automatic creation + Uses + Creative techniques + Strategic planning + Argument mapping + Tools + id)I am a cloud( + id))I am a bang(( + Tools + ` + ); + }); + it('4-tidy-tree: should render a mindmap with children', () => { + imgSnapshotTest( + ` --- + config: + layout: tidy-tree + --- + mindmap + ((This is a mindmap)) + child1 + grandchild 1 + grandchild 2 + child2 + grandchild 3 + grandchild 4 + child3 + grandchild 5 + grandchild 6 + ` + ); + }); +}); diff --git a/cypress/integration/rendering/mindmap.spec.ts b/cypress/integration/rendering/mindmap.spec.ts index 731f861ee..e0409ed46 100644 --- a/cypress/integration/rendering/mindmap.spec.ts +++ b/cypress/integration/rendering/mindmap.spec.ts @@ -159,12 +159,10 @@ root }); it('square shape', () => { imgSnapshotTest( - ` -mindmap + `mindmap root[ The root - ] - `, + ]`, {}, undefined, shouldHaveRoot @@ -172,12 +170,10 @@ mindmap }); it('rounded rect shape', () => { imgSnapshotTest( - ` -mindmap + `mindmap root(( The root - )) - `, + ))`, {}, undefined, shouldHaveRoot @@ -185,12 +181,10 @@ mindmap }); it('circle shape', () => { imgSnapshotTest( - ` -mindmap + `mindmap root( The root - ) - `, + )`, {}, undefined, shouldHaveRoot @@ -198,10 +192,8 @@ mindmap }); it('default shape', () => { imgSnapshotTest( - ` -mindmap - The root - `, + `mindmap + The root`, {}, undefined, shouldHaveRoot @@ -209,12 +201,10 @@ mindmap }); it('adding children', () => { imgSnapshotTest( - ` -mindmap + `mindmap The root child1 - child2 - `, + child2`, {}, undefined, shouldHaveRoot @@ -222,13 +212,11 @@ mindmap }); it('adding grand children', () => { imgSnapshotTest( - ` -mindmap + `mindmap The root child1 child2 - child3 - `, + child3`, {}, undefined, shouldHaveRoot @@ -240,9 +228,22 @@ mindmap `mindmap id1[\`**Start** with a second line 😎\`] - id2[\`The dog in **the** hog... a *very long text* about it -Word!\`] -` + id2[\`The dog in **the** hog... a *very long text* about it Word!\`]` + ); + }); + }); + describe('Include char sequence "graph" in text (#6795)', () => { + it('has a label with char sequence "graph"', () => { + imgSnapshotTest( + ` mindmap + root + Photograph + Waterfall + Landscape + Geography + Mountains + Rocks`, + { flowchart: { defaultRenderer: 'elk' } } ); }); }); diff --git a/cypress/integration/rendering/pie.spec.ts b/cypress/integration/rendering/pie.spec.ts index 171a83057..8f6ef7de3 100644 --- a/cypress/integration/rendering/pie.spec.ts +++ b/cypress/integration/rendering/pie.spec.ts @@ -82,4 +82,13 @@ describe('pie chart', () => { ` ); }); + it('should render pie slices only for non-zero values but shows all legends', () => { + imgSnapshotTest( + ` pie title Pets adopted by volunteers + "Dogs" : 386 + "Cats" : 85 + "Rats" : 1 + ` + ); + }); }); diff --git a/cypress/integration/rendering/sankey.spec.ts b/cypress/integration/rendering/sankey.spec.ts index ad0d75f18..b9940d998 100644 --- a/cypress/integration/rendering/sankey.spec.ts +++ b/cypress/integration/rendering/sankey.spec.ts @@ -15,7 +15,7 @@ describe('Sankey Diagram', () => { describe('when given a linkColor', function () { this.beforeAll(() => { cy.wrap( - `sankey-beta + `sankey a,b,10 ` ).as('graph'); @@ -62,7 +62,7 @@ describe('Sankey Diagram', () => { this.beforeAll(() => { cy.wrap( ` - sankey-beta + sankey a,b,8 b,c,8 diff --git a/cypress/integration/rendering/sequencediagram-v2.spec.js b/cypress/integration/rendering/sequencediagram-v2.spec.js new file mode 100644 index 000000000..f1c2aafbd --- /dev/null +++ b/cypress/integration/rendering/sequencediagram-v2.spec.js @@ -0,0 +1,659 @@ +import { imgSnapshotTest, renderGraph } from '../../helpers/util.ts'; + +const looks = ['classic']; +const participantTypes = [ + { type: 'participant', display: 'participant' }, + { type: 'actor', display: 'actor' }, + { type: 'boundary', display: 'boundary' }, + { type: 'control', display: 'control' }, + { type: 'entity', display: 'entity' }, + { type: 'database', display: 'database' }, + { type: 'collections', display: 'collections' }, + { type: 'queue', display: 'queue' }, +]; + +const restrictedTypes = ['boundary', 'control', 'entity', 'database', 'collections', 'queue']; + +const interactionTypes = ['->>', '-->>', '->', '-->', '-x', '--x', '->>+', '-->>+']; + +const notePositions = ['left of', 'right of', 'over']; + +function getParticipantLine(name, type, alias) { + if (restrictedTypes.includes(type)) { + return ` participant ${name}@{ "type" : "${type}" }\n`; + } else if (alias) { + return ` participant ${name}@{ "type" : "${type}" } \n`; + } else { + return ` participant ${name}@{ "type" : "${type}" }\n`; + } +} + +looks.forEach((look) => { + describe(`Sequence Diagram Tests - ${look} look`, () => { + it('should render all participant types', () => { + let diagramCode = `sequenceDiagram\n`; + participantTypes.forEach((pt, index) => { + const name = `${pt.display}${index}`; + diagramCode += getParticipantLine(name, pt.type); + }); + for (let i = 0; i < participantTypes.length - 1; i++) { + diagramCode += ` ${participantTypes[i].display}${i} ->> ${participantTypes[i + 1].display}${i + 1}: Message ${i}\n`; + } + imgSnapshotTest(diagramCode, { look, sequence: { diagramMarginX: 50, diagramMarginY: 10 } }); + }); + + it('should render all interaction types', () => { + let diagramCode = `sequenceDiagram\n`; + diagramCode += getParticipantLine('A', 'actor'); + diagramCode += getParticipantLine('B', 'boundary'); + interactionTypes.forEach((interaction, index) => { + diagramCode += ` A ${interaction} B: ${interaction} message ${index}\n`; + }); + imgSnapshotTest(diagramCode, { look }); + }); + + it('should render participant creation and destruction', () => { + let diagramCode = `sequenceDiagram\n`; + participantTypes.forEach((pt, index) => { + const name = `${pt.display}${index}`; + diagramCode += getParticipantLine('A', pt.type); + diagramCode += getParticipantLine('B', pt.type); + diagramCode += ` create participant ${name}@{ "type" : "${pt.type}" }\n`; + diagramCode += ` A ->> ${name}: Hello ${pt.display}\n`; + if (index % 2 === 0) { + diagramCode += ` destroy ${name}\n`; + } + }); + imgSnapshotTest(diagramCode, { look }); + }); + + it('should render notes in all positions', () => { + let diagramCode = `sequenceDiagram\n`; + diagramCode += getParticipantLine('A', 'actor'); + diagramCode += getParticipantLine('B', 'boundary'); + notePositions.forEach((position, index) => { + diagramCode += ` Note ${position} A: Note ${position} ${index}\n`; + }); + diagramCode += ` A ->> B: Message with notes\n`; + imgSnapshotTest(diagramCode, { look }); + }); + + it('should render parallel interactions', () => { + let diagramCode = `sequenceDiagram\n`; + participantTypes.slice(0, 4).forEach((pt, index) => { + diagramCode += getParticipantLine(`${pt.display}${index}`, pt.type); + }); + diagramCode += ` par Parallel actions\n`; + for (let i = 0; i < 3; i += 2) { + diagramCode += ` ${participantTypes[i].display}${i} ->> ${participantTypes[i + 1].display}${i + 1}: Message ${i}\n`; + if (i < participantTypes.length - 2) { + diagramCode += ` and\n`; + } + } + diagramCode += ` end\n`; + imgSnapshotTest(diagramCode, { look }); + }); + + it('should render alternative flows', () => { + let diagramCode = `sequenceDiagram\n`; + diagramCode += getParticipantLine('A', 'actor'); + diagramCode += getParticipantLine('B', 'boundary'); + diagramCode += ` alt Successful case\n`; + diagramCode += ` A ->> B: Request\n`; + diagramCode += ` B -->> A: Success\n`; + diagramCode += ` else Failure case\n`; + diagramCode += ` A ->> B: Request\n`; + diagramCode += ` B --x A: Failure\n`; + diagramCode += ` end\n`; + imgSnapshotTest(diagramCode, { look }); + }); + + it('should render loops', () => { + let diagramCode = `sequenceDiagram\n`; + participantTypes.slice(0, 3).forEach((pt, index) => { + diagramCode += getParticipantLine(`${pt.display}${index}`, pt.type); + }); + diagramCode += ` loop For each participant\n`; + for (let i = 0; i < 3; i++) { + diagramCode += ` ${participantTypes[0].display}0 ->> ${participantTypes[1].display}1: Message ${i}\n`; + } + diagramCode += ` end\n`; + imgSnapshotTest(diagramCode, { look }); + }); + + it('should render boxes around groups', () => { + let diagramCode = `sequenceDiagram\n`; + diagramCode += ` box Group 1\n`; + participantTypes.slice(0, 3).forEach((pt, index) => { + diagramCode += ` ${getParticipantLine(`${pt.display}${index}`, pt.type)}`; + }); + diagramCode += ` end\n`; + diagramCode += ` box rgb(200,220,255) Group 2\n`; + participantTypes.slice(3, 6).forEach((pt, index) => { + diagramCode += ` ${getParticipantLine(`${pt.display}${index}`, pt.type)}`; + }); + diagramCode += ` end\n`; + diagramCode += ` ${participantTypes[0].display}0 ->> ${participantTypes[3].display}0: Cross-group message\n`; + imgSnapshotTest(diagramCode, { look }); + }); + + it('should render with different font settings', () => { + let diagramCode = `sequenceDiagram\n`; + participantTypes.slice(0, 3).forEach((pt, index) => { + diagramCode += getParticipantLine(`${pt.display}${index}`, pt.type); + }); + diagramCode += ` ${participantTypes[0].display}0 ->> ${participantTypes[1].display}1: Regular message\n`; + diagramCode += ` Note right of ${participantTypes[1].display}1: Regular note\n`; + imgSnapshotTest(diagramCode, { + look, + sequence: { + actorFontFamily: 'courier', + actorFontSize: 14, + messageFontFamily: 'Arial', + messageFontSize: 12, + noteFontFamily: 'times', + noteFontSize: 16, + noteAlign: 'left', + }, + }); + }); + }); +}); + +// Additional tests for specific combinations +describe('Sequence Diagram Special Cases', () => { + it('should render complex sequence with all features', () => { + const diagramCode = ` + sequenceDiagram + box rgb(200,220,255) Authentication + actor User + participant LoginUI@{ "type": "boundary" } + participant AuthService@{ "type": "control" } + participant UserDB@{ "type": "database" } + end + + box rgb(200,255,220) Order Processing + participant Order@{ "type": "entity" } + participant OrderQueue@{ "type": "queue" } + participant AuditLogs@{ "type": "collections" } + end + + User ->> LoginUI: Enter credentials + LoginUI ->> AuthService: Validate + AuthService ->> UserDB: Query user + UserDB -->> AuthService: User data + alt Valid credentials + AuthService -->> LoginUI: Success + LoginUI -->> User: Welcome + + par Place order + User ->> Order: New order + Order ->> OrderQueue: Process + and + Order ->> AuditLogs: Record + end + + loop Until confirmed + OrderQueue ->> Order: Update status + Order -->> User: Notification + end + else Invalid credentials + AuthService --x LoginUI: Failure + LoginUI --x User: Retry + end + `; + imgSnapshotTest(diagramCode, {}); + }); + + it('should render with wrapped messages and notes', () => { + const diagramCode = ` + sequenceDiagram + participant A + participant B + + A ->> B: This is a very long message that should wrap properly in the diagram rendering + Note over A,B: This is a very long note that should also wrap properly when rendered in the diagram + + par Wrapped parallel + A ->> B: Parallel message 1
with explicit line break + and + B ->> A: Parallel message 2
with explicit line break + end + + loop Wrapped loop + Note right of B: This is a long note
in a loop + A ->> B: Message in loop + end + `; + imgSnapshotTest(diagramCode, { sequence: { wrap: true } }); + }); + describe('Sequence Diagram Rendering with Different Participant Types', () => { + it('should render a sequence diagram with various participant types', () => { + imgSnapshotTest( + ` + sequenceDiagram + participant User@{ "type": "actor" } + participant AuthService@{ "type": "control" } + participant UI@{ "type": "boundary" } + participant OrderController@{ "type": "control" } + participant Product@{ "type": "entity" } + participant MongoDB@{ "type": "database" } + participant Products@{ "type": "collections" } + participant OrderQueue@{ "type": "queue" } + User ->> UI: Login request + UI ->> AuthService: Validate credentials + AuthService -->> UI: Authentication token + UI ->> OrderController: Place order + OrderController ->> Product: Check availability + Product -->> OrderController: Available + OrderController ->> MongoDB: Save order + MongoDB -->> OrderController: Order saved + OrderController ->> OrderQueue: Process payment + OrderQueue -->> User: Order confirmation + ` + ); + }); + + it('should render participant creation and destruction with different types', () => { + imgSnapshotTest(` + sequenceDiagram + participant Alice@{ "type" : "boundary" } + Alice->>Bob: Hello Bob, how are you ? + Bob->>Alice: Fine, thank you. And you? + create participant Carl@{ "type" : "control" } + Alice->>Carl: Hi Carl! + create actor D as Donald + Carl->>D: Hi! + destroy Carl + Alice-xCarl: We are too many + destroy Bob + Bob->>Alice: I agree + `); + }); + + it('should handle complex interactions between different participant types', () => { + imgSnapshotTest( + ` + sequenceDiagram + box rgb(200,220,255) Authentication + participant User@{ "type": "actor" } + participant LoginUI@{ "type": "boundary" } + participant AuthService@{ "type": "control" } + participant UserDB@{ "type": "database" } + end + + box rgb(200,255,220) Order Processing + participant Order@{ "type": "entity" } + participant OrderQueue@{ "type": "queue" } + participant AuditLogs@{ "type": "collections" } + end + + User ->> LoginUI: Enter credentials + LoginUI ->> AuthService: Validate + AuthService ->> UserDB: Query user + UserDB -->> AuthService: User data + + alt Valid credentials + AuthService -->> LoginUI: Success + LoginUI -->> User: Welcome + + par Place order + User ->> Order: New order + Order ->> OrderQueue: Process + and + Order ->> AuditLogs: Record + end + + loop Until confirmed + OrderQueue ->> Order: Update status + Order -->> User: Notification + end + else Invalid credentials + AuthService --x LoginUI: Failure + LoginUI --x User: Retry + end + `, + { sequence: { useMaxWidth: false } } + ); + }); + + it('should render parallel processes with different participant types', () => { + imgSnapshotTest( + ` + sequenceDiagram + participant Customer@{ "type": "actor" } + participant Frontend@{ "type": "participant" } + participant PaymentService@{ "type": "boundary" } + participant InventoryManager@{ "type": "control" } + participant Order@{ "type": "entity" } + participant OrdersDB@{ "type": "database" } + participant NotificationQueue@{ "type": "queue" } + + Customer ->> Frontend: Place order + Frontend ->> Order: Create order + par Parallel Processing + Order ->> PaymentService: Process payment + and + Order ->> InventoryManager: Reserve items + end + PaymentService -->> Order: Payment confirmed + InventoryManager -->> Order: Items reserved + Order ->> OrdersDB: Save finalized order + OrdersDB -->> Order: Order saved + Order ->> NotificationQueue: Send confirmation + NotificationQueue -->> Customer: Order confirmation + ` + ); + }); + }); + it('should render different participant types with notes and loops', () => { + imgSnapshotTest( + ` + sequenceDiagram + actor Admin + participant Dashboard + participant AuthService@{ "type" : "boundary" } + participant UserManager@{ "type" : "control" } + participant UserProfile@{ "type" : "entity" } + participant UserDB@{ "type" : "database" } + participant Logs@{ "type" : "database" } + + Admin ->> Dashboard: Open user management + loop Authentication check + Dashboard ->> AuthService: Verify admin rights + AuthService ->> Dashboard: Access granted + end + Dashboard ->> UserManager: List users + UserManager ->> UserDB: Query users + UserDB ->> UserManager: Return user data + Note right of UserDB: Encrypted data
requires decryption + UserManager ->> UserProfile: Format profiles + UserProfile ->> UserManager: Formatted data + UserManager ->> Dashboard: Display users + Dashboard ->> Logs: Record access + Logs ->> Admin: Audit trail + ` + ); + }); + + it('should render different participant types with alternative flows', () => { + imgSnapshotTest( + ` + sequenceDiagram + actor Client + participant MobileApp + participant CloudService@{ "type" : "boundary" } + participant DataProcessor@{ "type" : "control" } + participant Transaction@{ "type" : "entity" } + participant TransactionsDB@{ "type" : "database" } + participant EventBus@{ "type" : "queue" } + + Client ->> MobileApp: Initiate transaction + MobileApp ->> CloudService: Authenticate + alt Authentication successful + CloudService -->> MobileApp: Auth token + MobileApp ->> DataProcessor: Process data + DataProcessor ->> Transaction: Create transaction + Transaction ->> TransactionsDB: Save record + TransactionsDB -->> Transaction: Confirmation + Transaction ->> EventBus: Publish event + EventBus -->> Client: Notification + else Authentication failed + CloudService -->> MobileApp: Error + MobileApp -->> Client: Show error + end + ` + ); + }); + + it('should render different participant types with wrapping text', () => { + imgSnapshotTest( + ` + sequenceDiagram + participant B@{ "type" : "boundary" } + participant C@{ "type" : "control" } + participant E@{ "type" : "entity" } + participant DB@{ "type" : "database" } + participant COL@{ "type" : "collections" } + participant Q@{ "type" : "queue" } + + FE ->> B: Another long message
with explicit
line breaks + B -->> FE: Response message that is also quite long and needs to wrap + FE ->> C: Process data + C ->> E: Validate + E -->> C: Validation result + C ->> DB: Save + DB -->> C: Save result + C ->> COL: Log + COL -->> Q: Forward + Q -->> LongNameUser: Final response with confirmation of all actions taken + `, + { sequence: { wrap: true } } + ); + }); + + describe('Sequence Diagram - New Participant Types with Long Notes and Messages', () => { + it('should render long notes left of boundary', () => { + imgSnapshotTest( + ` + sequenceDiagram + participant Alice@{ "type" : "boundary" } + actor Bob + Alice->>Bob: Hola + Note left of Alice: Extremely utterly long line of longness which had previously overflown the actor box as it is much longer than what it should be + Bob->>Alice: I'm short though + `, + {} + ); + }); + + it('should render wrapped long notes left of control', () => { + imgSnapshotTest( + ` + sequenceDiagram + participant Alice@{ "type" : "control" } + actor Bob + Alice->>Bob: Hola + Note left of Alice:wrap: Extremely utterly long line of longness which had previously overflown the actor box as it is much longer than what it should be + Bob->>Alice: I'm short though + `, + {} + ); + }); + + it('should render long notes right of entity', () => { + imgSnapshotTest( + ` + sequenceDiagram + participant Alice@{ "type" : "entity" } + actor Bob + Alice->>Bob: Hola + Note right of Alice: Extremely utterly long line of longness which had previously overflown the actor box as it is much longer than what it should be + Bob->>Alice: I'm short though + `, + {} + ); + }); + + it('should render wrapped long notes right of database', () => { + imgSnapshotTest( + ` + sequenceDiagram + participant Alice@{ "type" : "database" } + actor Bob + Alice->>Bob: Hola + Note right of Alice:wrap: Extremely utterly long line of longness which had previously overflown the actor box as it is much longer than what it should be + Bob->>Alice: I'm short though + `, + {} + ); + }); + + it('should render long notes over collections', () => { + imgSnapshotTest( + ` + sequenceDiagram + participant Alice@{ "type" : "collections" } + actor Bob + Alice->>Bob: Hola + Note over Alice: Extremely utterly long line of longness which had previously overflown the actor box as it is much longer than what it should be + Bob->>Alice: I'm short though + `, + {} + ); + }); + + it('should render wrapped long notes over queue', () => { + imgSnapshotTest( + ` + sequenceDiagram + participant Alice@{ "type" : "queue" } + actor Bob + Alice->>Bob: Hola + Note over Alice:wrap: Extremely utterly long line of longness which had previously overflown the actor box as it is much longer than what it should be + Bob->>Alice: I'm short though + `, + {} + ); + }); + + it('should render notes over actor and boundary', () => { + imgSnapshotTest( + ` + sequenceDiagram + actor Alice + participant Charlie@{ "type" : "boundary" } + note over Alice: Some note + note over Charlie: Other note + `, + {} + ); + }); + + it('should render long messages from database to collections', () => { + imgSnapshotTest( + ` + sequenceDiagram + participant Alice@{ "type" : "database" } + participant Bob@{ "type" : "collections" } + Alice->>Bob: Extremely utterly long line of longness which had previously overflown the actor box as it is much longer than what it should be + Bob->>Alice: I'm short though + `, + {} + ); + }); + + it('should render wrapped long messages from control to entity', () => { + imgSnapshotTest( + ` + sequenceDiagram + participant Alice@{ "type" : "control" } + participant Bob@{ "type" : "entity" } + Alice->>Bob:wrap: Extremely utterly long line of longness which had previously overflown the actor box as it is much longer than what it should be + Bob->>Alice: I'm short though + `, + {} + ); + }); + + it('should render long messages from queue to boundary', () => { + imgSnapshotTest( + ` + sequenceDiagram + participant Alice@{ "type" : "queue" } + participant Bob@{ "type" : "boundary" } + Alice->>Bob: I'm short + Bob->>Alice: Extremely utterly long line of longness which had previously overflown the actor box as it is much longer than what it should be + `, + {} + ); + }); + + it('should render wrapped long messages from actor to database', () => { + imgSnapshotTest( + ` + sequenceDiagram + actor Alice + participant Bob@{ "type" : "database" } + Alice->>Bob: I'm short + Bob->>Alice:wrap: Extremely utterly long line of longness which had previously overflown the actor box as it is much longer than what it should be + `, + {} + ); + }); + }); + + describe('svg size', () => { + it('should render a sequence diagram when useMaxWidth is true (default)', () => { + renderGraph( + ` + sequenceDiagram + actor Alice + participant Bob@{ "type" : "boundary" } + participant John@{ "type" : "control" } + Alice ->> Bob: Hello Bob, how are you? + Bob-->>John: How about you John? + Bob--x Alice: I am good thanks! + Bob-x John: I am good thanks! + Note right of John: Bob thinks a long
long time, so long
that the text does
not fit on a row. + Bob-->Alice: Checking with John... + alt either this + Alice->>John: Yes + else or this + Alice->>John: No + else or this will happen + Alice->John: Maybe + end + par this happens in parallel + Alice -->> Bob: Parallel message 1 + and + Alice -->> John: Parallel message 2 + end + `, + { sequence: { useMaxWidth: true } } + ); + cy.get('svg').should((svg) => { + expect(svg).to.have.attr('width', '100%'); + const style = svg.attr('style'); + expect(style).to.match(/^max-width: [\d.]+px;$/); + const maxWidthValue = parseFloat(style.match(/[\d.]+/g).join('')); + expect(maxWidthValue).to.be.within(820 * 0.95, 820 * 1.05); + }); + }); + + it('should render a sequence diagram when useMaxWidth is false', () => { + renderGraph( + ` + sequenceDiagram + actor Alice + participant Bob@{ "type" : "boundary" } + participant John@{ "type" : "control" } + Alice ->> Bob: Hello Bob, how are you? + Bob-->>John: How about you John? + Bob--x Alice: I am good thanks! + Bob-x John: I am good thanks! + Note right of John: Bob thinks a long
long time, so long
that the text does
not fit on a row. + Bob-->Alice: Checking with John... + alt either this + Alice->>John: Yes + else or this + Alice->>John: No + else or this will happen + Alice->John: Maybe + end + par this happens in parallel + Alice -->> Bob: Parallel message 1 + and + Alice -->> John: Parallel message 2 + end + `, + { sequence: { useMaxWidth: false } } + ); + cy.get('svg').should((svg) => { + const width = parseFloat(svg.attr('width')); + expect(width).to.be.within(820 * 0.95, 820 * 1.05); + expect(svg).to.not.have.attr('style'); + }); + }); + }); +}); diff --git a/cypress/integration/rendering/sequencediagram.spec.js b/cypress/integration/rendering/sequencediagram.spec.js index f18e99abf..6709b557c 100644 --- a/cypress/integration/rendering/sequencediagram.spec.js +++ b/cypress/integration/rendering/sequencediagram.spec.js @@ -893,6 +893,17 @@ describe('Sequence diagram', () => { } ); }); + + it('should handle bidirectional arrows with autonumber', () => { + imgSnapshotTest(` + sequenceDiagram + autonumber + participant A + participant B + A<<->>B: This is a bidirectional message + A->B: This is a normal message`); + }); + it('should support actor links and properties when not mirrored EXPERIMENTAL: USE WITH CAUTION', () => { //Be aware that the syntax for "properties" is likely to be changed. imgSnapshotTest( diff --git a/cypress/integration/rendering/stateDiagram-v2.spec.js b/cypress/integration/rendering/stateDiagram-v2.spec.js index 83190dbc7..e5a0cedd0 100644 --- a/cypress/integration/rendering/stateDiagram-v2.spec.js +++ b/cypress/integration/rendering/stateDiagram-v2.spec.js @@ -602,6 +602,231 @@ State1 --> [*] -- 55 } +`, + {} + ); + }); + it('should render edge labels correctly', () => { + imgSnapshotTest( + `--- +title: On The Way To Something Something DarkSide +config: + look: default + theme: default +--- + +stateDiagram-v2 + + state State1_____________ + { + c0 + } + + state State2_____________ + { + c1 + } + + state State3_____________ + { + c7 + } + + state State4_____________ + { + c2 + } + + state State5_____________ + { + c3 + } + + state State6_____________ + { + c4 + } + + state State7_____________ + { + c5 + } + + state State8_____________ + { + c6 + } + + +[*] --> State1_____________ +State1_____________ --> State2_____________ : Transition1_____ +State2_____________ --> State4_____________ : Transition2_____ +State2_____________ --> State3_____________ : Transition3_____ +State3_____________ --> State2_____________ +State4_____________ --> State2_____________ : Transition5_____ +State4_____________ --> State5_____________ : Transition6_____ +State5_____________ --> State6_____________ : Transition7_____ +State6_____________ --> State4_____________ : Transition8_____ +State2_____________ --> State7_____________ : Transition4_____ +State4_____________ --> State7_____________ : Transition4_____ +State5_____________ --> State7_____________ : Transition4_____ +State6_____________ --> State7_____________ : Transition4_____ +State7_____________ --> State1_____________ : Transition9_____ +State5_____________ --> State8_____________ : Transition10____ +State8_____________ --> State5_____________ : Transition11____ +`, + {} + ); + }); + it('should render edge labels correctly with multiple transitions', () => { + imgSnapshotTest( + `--- +title: Multiple Transitions +config: + look: default + theme: default +--- + +stateDiagram-v2 + + state State1_____________ + { + c0 + } + + state State2_____________ + { + c1 + } + + state State3_____________ + { + c7 + } + + state State4_____________ + { + c2 + } + + state State5_____________ + { + c3 + } + + state State6_____________ + { + c4 + } + + state State7_____________ + { + c5 + } + + state State8_____________ + { + c6 + } + + state State9_____________ + { + c9 + } + +[*] --> State1_____________ +State1_____________ --> State2_____________ : Transition1_____ +State2_____________ --> State4_____________ : Transition2_____ +State2_____________ --> State3_____________ : Transition3_____ +State3_____________ --> State2_____________ +State4_____________ --> State2_____________ : Transition5_____ +State4_____________ --> State5_____________ : Transition6_____ +State5_____________ --> State6_____________ : Transition7_____ +State6_____________ --> State4_____________ : Transition8_____ +State2_____________ --> State7_____________ : Transition4_____ +State4_____________ --> State7_____________ : Transition4_____ +State5_____________ --> State7_____________ : Transition4_____ +State6_____________ --> State7_____________ : Transition4_____ +State7_____________ --> State1_____________ : Transition9_____ +State5_____________ --> State8_____________ : Transition10____ +State8_____________ --> State5_____________ : Transition11____ +State9_____________ --> State8_____________ : Transition12____ +`, + {} + ); + }); + + it('should render edge labels correctly with multiple states', () => { + imgSnapshotTest( + `--- +title: Multiple States +config: + look: default + theme: default +--- + +stateDiagram-v2 + + state State1_____________ + { + c0 + } + + state State2_____________ + { + c1 + } + + state State3_____________ + { + c7 + } + + state State4_____________ + { + c2 + } + + state State5_____________ + { + c3 + } + + state State6_____________ + { + c4 + } + + state State7_____________ + { + c5 + } + + state State8_____________ + { + c6 + } + + state State9_____________ + { + c9 + } + + state State10_____________ + { + c10 + } + +[*] --> State1_____________ +State1_____________ --> State2_____________ : Transition1_____ +State2_____________ --> State3_____________ : Transition2_____ +State3_____________ --> State4_____________ : Transition3_____ +State4_____________ --> State5_____________ : Transition4_____ +State5_____________ --> State6_____________ : Transition5_____ +State6_____________ --> State7_____________ : Transition6_____ +State7_____________ --> State8_____________ : Transition7_____ +State8_____________ --> State9_____________ : Transition8_____ +State9_____________ --> State10_____________ : Transition9_____ `, {} ); diff --git a/cypress/integration/rendering/xyChart.spec.js b/cypress/integration/rendering/xyChart.spec.js index a582355e8..d54086fa7 100644 --- a/cypress/integration/rendering/xyChart.spec.js +++ b/cypress/integration/rendering/xyChart.spec.js @@ -1,7 +1,7 @@ import { imgSnapshotTest, renderGraph } from '../../helpers/util.ts'; describe('XY Chart', () => { - it('should render the simplest possible chart', () => { + it('should render the simplest possible xy-beta chart', () => { imgSnapshotTest( ` xychart-beta @@ -10,10 +10,19 @@ describe('XY Chart', () => { {} ); }); + it('should render the simplest possible xy chart', () => { + imgSnapshotTest( + ` + xychart + line [10, 30, 20] + `, + {} + ); + }); it('Should render a complete chart', () => { imgSnapshotTest( ` - xychart-beta + xychart title "Sales Revenue" x-axis Months [jan, feb, mar, apr, may, jun, jul, aug, sep, oct, nov, dec] y-axis "Revenue (in $)" 4000 --> 11000 @@ -26,7 +35,7 @@ describe('XY Chart', () => { it('Should render a chart without title', () => { imgSnapshotTest( ` - xychart-beta + xychart x-axis Months [jan, feb, mar, apr, may, jun, jul, aug, sep, oct, nov, dec] y-axis "Revenue (in $)" 4000 --> 11000 bar [5000, 6000, 7500, 8200, 9500, 10500, 11000, 10200, 9200, 8500, 7000, 6000] @@ -38,7 +47,7 @@ describe('XY Chart', () => { it('y-axis title not required', () => { imgSnapshotTest( ` - xychart-beta + xychart x-axis Months [jan, feb, mar, apr, may, jun, jul, aug, sep, oct, nov, dec] y-axis 4000 --> 11000 bar [5000, 6000, 7500, 8200, 9500, 10500, 11000, 10200, 9200, 8500, 7000, 6000] @@ -50,7 +59,7 @@ describe('XY Chart', () => { it('Should render a chart without y-axis with different range', () => { imgSnapshotTest( ` - xychart-beta + xychart x-axis Months [jan, feb, mar, apr, may, jun, jul, aug, sep, oct, nov, dec] bar [5000, 6000, 7500, 8200, 9500, 10500, 14000, 3200, 9200, 9900, 3400, 6000] line [2000, 7000, 6500, 9200, 9500, 7500, 11000, 10200, 3200, 8500, 7000, 8800] @@ -61,7 +70,7 @@ describe('XY Chart', () => { it('x axis title not required', () => { imgSnapshotTest( ` - xychart-beta + xychart x-axis [jan, feb, mar, apr, may, jun, jul, aug, sep, oct, nov, dec] bar [5000, 6000, 7500, 8200, 9500, 10500, 14000, 3200, 9200, 9900, 3400, 6000] line [2000, 7000, 6500, 9200, 9500, 7500, 11000, 10200, 3200, 8500, 7000, 8800] @@ -72,7 +81,7 @@ describe('XY Chart', () => { it('Multiple plots can be rendered', () => { imgSnapshotTest( ` - xychart-beta + xychart line [23, 46, 77, 34] line [45, 32, 33, 12] bar [87, 54, 99, 85] @@ -86,7 +95,7 @@ describe('XY Chart', () => { it('Decimals and negative numbers are supported', () => { imgSnapshotTest( ` - xychart-beta + xychart y-axis -2.4 --> 3.5 line [+1.3, .6, 2.4, -.34] `, @@ -104,7 +113,7 @@ describe('XY Chart', () => { height: 20 plotReservedSpacePercent: 100 --- - xychart-beta + xychart line [5000, 9000, 7500, 6200, 9500, 5500, 11000, 8200, 9200, 9500, 7000, 8800] `, {} @@ -130,7 +139,7 @@ describe('XY Chart', () => { showTick: false showAxisLine: false --- - xychart-beta + xychart bar [5000, 9000, 7500, 6200, 9500, 5500, 11000, 8200, 9200, 9500, 7000, 8800] `, {} @@ -140,7 +149,7 @@ describe('XY Chart', () => { imgSnapshotTest( ` %%{init: {"xyChart": {"width": 1000, "height": 600, "titlePadding": 5, "titleFontSize": 10, "xAxis": {"labelFontSize": "20", "labelPadding": 10, "titleFontSize": 30, "titlePadding": 20, "tickLength": 10, "tickWidth": 5}, "yAxis": {"labelFontSize": "20", "labelPadding": 10, "titleFontSize": 30, "titlePadding": 20, "tickLength": 10, "tickWidth": 5}, "plotBorderWidth": 5, "chartOrientation": "horizontal", "plotReservedSpacePercent": 60 }}}%% - xychart-beta + xychart title "Sales Revenue" x-axis Months [jan, feb, mar, apr, may, jun, jul, aug, sep, oct, nov, dec] y-axis "Revenue (in $)" 4000 --> 11000 @@ -181,7 +190,7 @@ describe('XY Chart', () => { plotReservedSpacePercent: 60 showDataLabel: true --- - xychart-beta + xychart title "Sales Revenue" x-axis Months [jan, feb, mar, apr, may, jun, jul, aug, sep, oct, nov, dec] y-axis "Revenue (in $)" 4000 --> 11000 @@ -202,7 +211,7 @@ describe('XY Chart', () => { yAxis: showTitle: false --- - xychart-beta + xychart title "Sales Revenue" x-axis Months [jan, feb, mar, apr, may, jun, jul, aug, sep, oct, nov, dec] y-axis "Revenue (in $)" 4000 --> 11000 @@ -223,7 +232,7 @@ describe('XY Chart', () => { yAxis: showLabel: false --- - xychart-beta + xychart title "Sales Revenue" x-axis Months [jan, feb, mar, apr, may, jun, jul, aug, sep, oct, nov, dec] y-axis "Revenue (in $)" 4000 --> 11000 @@ -244,7 +253,7 @@ describe('XY Chart', () => { yAxis: showTick: false --- - xychart-beta + xychart title "Sales Revenue" x-axis Months [jan, feb, mar, apr, may, jun, jul, aug, sep, oct, nov, dec] y-axis "Revenue (in $)" 4000 --> 11000 @@ -265,7 +274,7 @@ describe('XY Chart', () => { yAxis: showAxisLine: false --- - xychart-beta + xychart title "Sales Revenue" x-axis Months [jan, feb, mar, apr, may, jun, jul, aug, sep, oct, nov, dec] y-axis "Revenue (in $)" 4000 --> 11000 @@ -294,7 +303,7 @@ describe('XY Chart', () => { xAxisLineColor: "#87ceeb" plotColorPalette: "#008000, #faba63" --- - xychart-beta + xychart title "Sales Revenue" x-axis Months [jan, feb, mar, apr, may, jun, jul, aug, sep, oct, nov, dec] y-axis "Revenue (in $)" 4000 --> 11000 @@ -307,7 +316,7 @@ describe('XY Chart', () => { it('should use the correct distances between data points', () => { imgSnapshotTest( ` - xychart-beta + xychart x-axis 0 --> 2 line [0, 1, 0, 1] bar [1, 0, 1, 0] @@ -325,7 +334,7 @@ describe('XY Chart', () => { xyChart: showDataLabel: true --- - xychart-beta + xychart title "Sales Revenue" x-axis Months [jan, feb, mar, apr, may, jun, jul, aug, sep, oct, nov, dec] y-axis "Revenue (in $)" 4000 --> 11000 @@ -344,7 +353,7 @@ describe('XY Chart', () => { showDataLabel: true chartOrientation: horizontal --- - xychart-beta + xychart title "Sales Revenue" x-axis Months [jan, feb, mar, apr, may, jun, jul, aug, sep, oct, nov, dec] y-axis "Revenue (in $)" 4000 --> 11000 @@ -357,7 +366,7 @@ describe('XY Chart', () => { it('should render vertical bar chart without labels by default', () => { imgSnapshotTest( ` - xychart-beta + xychart title "Sales Revenue" x-axis Months [jan, feb, mar, apr, may, jun, jul, aug, sep, oct, nov, dec] y-axis "Revenue (in $)" 4000 --> 11000 @@ -375,7 +384,7 @@ describe('XY Chart', () => { xyChart: chartOrientation: horizontal --- - xychart-beta + xychart title "Sales Revenue" x-axis Months [jan, feb, mar, apr, may, jun, jul, aug, sep, oct, nov, dec] y-axis "Revenue (in $)" 4000 --> 11000 @@ -393,7 +402,7 @@ describe('XY Chart', () => { xyChart: showDataLabel: true --- - xychart-beta + xychart title "Multiple Bar Plots" x-axis Categories [A, B, C] y-axis "Values" 0 --> 100 @@ -412,7 +421,7 @@ describe('XY Chart', () => { showDataLabel: true chartOrientation: horizontal --- - xychart-beta + xychart title "Multiple Bar Plots" x-axis Categories [A, B, C] y-axis "Values" 0 --> 100 @@ -430,7 +439,7 @@ describe('XY Chart', () => { xyChart: showDataLabel: true --- - xychart-beta + xychart title "Single Bar Chart" x-axis Categories [A] y-axis "Value" 0 --> 100 @@ -449,7 +458,7 @@ describe('XY Chart', () => { showDataLabel: true chartOrientation: horizontal --- - xychart-beta + xychart title "Single Bar Chart" x-axis Categories [A] y-axis "Value" 0 --> 100 @@ -467,7 +476,7 @@ describe('XY Chart', () => { xyChart: showDataLabel: true --- - xychart-beta + xychart title "Decimal and Negative Values" x-axis Categories [A, B, C] y-axis -10 --> 10 @@ -486,7 +495,7 @@ describe('XY Chart', () => { showDataLabel: true chartOrientation: horizontal --- - xychart-beta + xychart title "Decimal and Negative Values" x-axis Categories [A, B, C] y-axis -10 --> 10 @@ -504,7 +513,7 @@ describe('XY Chart', () => { xyChart: showDataLabel: true --- - xychart-beta + xychart title "Sales Revenue" x-axis Months [jan,b,c] y-axis "Revenue (in $)" 4000 --> 12000 @@ -561,7 +570,7 @@ describe('XY Chart', () => { showDataLabel: true chartOrientation: horizontal --- - xychart-beta + xychart title "Sales Revenue" x-axis Months [jan,b,c] y-axis "Revenue (in $)" 4000 --> 12000 @@ -615,7 +624,7 @@ describe('XY Chart', () => { xyChart: showDataLabel: true --- - xychart-beta + xychart title "Sales Revenue" x-axis Months [jan,a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s] y-axis "Revenue (in $)" 4000 --> 12000 @@ -672,7 +681,7 @@ describe('XY Chart', () => { showDataLabel: true chartOrientation: horizontal --- - xychart-beta + xychart title "Sales Revenue" x-axis Months [jan,a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s] y-axis "Revenue (in $)" 4000 --> 12000 @@ -726,7 +735,7 @@ describe('XY Chart', () => { xyChart: showDataLabel: true --- - xychart-beta + xychart title "Sales Revenue" x-axis Months [jan] y-axis "Revenue (in $)" 3000 --> 12000 @@ -783,7 +792,7 @@ describe('XY Chart', () => { showDataLabel: true chartOrientation: horizontal --- - xychart-beta + xychart title "Sales Revenue" x-axis Months [jan] y-axis "Revenue (in $)" 3000 --> 12000 diff --git a/cypress/platform/darshan.html b/cypress/platform/darshan.html new file mode 100644 index 000000000..df5994d7d --- /dev/null +++ b/cypress/platform/darshan.html @@ -0,0 +1,35 @@ + + + + + + Mermaid Quick Test Page + + + + + +

Pie chart demos

+
+     pie title Default text position: Animal adoption
+        accTitle: simple pie char demo
+        accDescr: pie chart with 3 sections: dogs, cats, rats. Most are dogs.
+         "dogs" : -60.67
+        "rats" : 40.12
+    
+ +
+ + + diff --git a/cypress/platform/knsv2.html b/cypress/platform/knsv2.html index ab7ded0c2..fc33a58b4 100644 --- a/cypress/platform/knsv2.html +++ b/cypress/platform/knsv2.html @@ -130,6 +130,92 @@ +
+      ---
+      config:
+        layout: tidy-tree
+      ---
+      mindmap
+      root((mindmap))
+        Origins
+          Long history
+          ::icon(fa fa-book)
+          Popularisation
+            British popular psychology author Tony Buzan
+        Research
+          On effectiveness
and features + On Automatic creation + Uses + Creative techniques + Strategic planning + Argument mapping + Tools + Pen and paper + Mermaid + +
+
+      ---
+      config:
+        layout: tidy-tree
+      ---
+      mindmap
+      root((mindmap is a long thing))
+        A
+        B
+        C
+        D
+      
+
+      ---
+      config:
+        layout: tidy-tree
+      ---
+      mindmap
+      root((mindmap))
+        A
+        B
+      
+
+      ---
+      config:
+        layout: tidy-tree
+      ---
+      mindmap
+      root((mindmap))
+        A
+          a
+            apa[I am a long long multline string passing several levels of text. Lorum ipsum and so on. I am a long long multline string passing several levels of text. Lorum ipsum and so on. I am a long long multline string passing several levels of text. Lorum ipsum and so on. I am a long long multline string passing several levels of text. Lorum ipsum and so on]
+            apa2[I am a long long multline string passing several levels of text. Lorum ipsum and so on. I am a long long multline string passing several levels of text. Lorum ipsum and so on. I am a long long multline string passing several levels of text. Lorum ipsum and so on. I am a long long multline string passing several levels of text. Lorum ipsum and so on]
+          b
+          c
+          d
+        B
+            apa3[I am a long long multline string passing several levels of text. Lorum ipsum and so on. I am a long long multline string passing several levels of text. Lorum ipsum and so on. I am a long long multline string passing several levels of text. Lorum ipsum and so on. I am a long long multline string passing several levels of text. Lorum ipsum and so on]
+        D
+          apa5[I am a long long multline string passing several levels of text. Lorum ipsum and so on. I am a long long multline string passing several levels of text. Lorum ipsum and so on. I am a long long multline string passing several levels of text. Lorum ipsum and so on. I am a long long multline string passing several levels of text. Lorum ipsum and so on]
+          apa4[I am a long long multline string passing several levels of text. Lorum ipsum and so on. I am a long long multline string passing several levels of text. Lorum ipsum and so on. I am a long long multline string passing several levels of text. Lorum ipsum and so on. I am a long long multline string passing several levels of text. Lorum ipsum and so on]
+
+    
+ +
+---
+config:
+  layout: elk
+  elk:
+    mergeEdges: false
+    forceNodeModelOrder: false
+    considerModelOrder: NONE
+
+---
+            flowchart TB
+              a --> a1 & a2 & a3 & a4
+              b --> b1 & b2
+              b2 --> b3
+              b1 --> b4
 treemap
 "Section 1"
@@ -175,8 +261,145 @@ treemap
           "Item B2": 25
     
+      ---
+      config:
+        layout: tidy-tree
+      ---
+      mindmap
+      root((mindmap))
+        a
+          apa[I am a long long multline string passing several levels of text. Lorum ipsum and so on. I am a long long multline string passing several levels of text. Lorum ipsum and so on. I am a long long multline string passing several levels of text. Lorum ipsum and so on. I am a long long multline string passing several levels of text. Lorum ipsum and so on]
+          apa2[I am a long long multline string passing several levels of text. Lorum ipsum and so on. I am a long long multline string passing several levels of text. Lorum ipsum and so on. I am a long long multline string passing several levels of text. Lorum ipsum and so on. I am a long long multline string passing several levels of text. Lorum ipsum and so on]
+        b
+          apa3[I am a long long multline string passing several levels of text. Lorum ipsum and so on. I am a long long multline string passing several levels of text. Lorum ipsum and so on. I am a long long multline string passing several levels of text. Lorum ipsum and so on. I am a long long multline string passing several levels of text. Lorum ipsum and so on]
+          apa4[I am a long long multline string passing several levels of text. Lorum ipsum and so on. I am a long long multline string passing several levels of text. Lorum ipsum and so on. I am a long long multline string passing several levels of text. Lorum ipsum and so on. I am a long long multline string passing several levels of text. Lorum ipsum and so on]
+
+
+    
+
+      ---
+      config:
+        layout: tidy-tree
+      ---
+      flowchart TB
+          A --> n0["1"]
+          A --> n1["2"]
+          A --> n2["3"]
+          A --> n3["4"] --> Q & R & S & T
+    
+
+      ---
+      config:
+        layout: elk
+      ---
+      flowchart TB
+          A --> n0["1"]
+          A --> n1["2"]
+          A --> n2["3"]
+          A --> n3["4"] --> Q & R & S & T
+    
+
+      ---
+      config:
+        layout: dagre
+      ---
+      mindmap
+      root((mindmap is a long thing))
+        Origins
+          Long history
+          ::icon(fa fa-book)
+          Popularisation
+            British popular psychology author Tony Buzan
+        Research
+          On effectiveness<br/>and features
+          On Automatic creation
+            Uses
+                Creative techniques
+                Strategic planning
+                Argument mapping
+        Tools
+          Pen and paper
+          Mermaid
+    
+
+      ---
+      config:
+        layout: cose-bilkent
+      ---
+      mindmap
+      root((mindmap))
+        Origins
+          Long history
+          ::icon(fa fa-book)
+          Popularisation
+            British popular psychology author Tony Buzan
+        Research
+          On effectiveness<br/>and features
+          On Automatic creation
+            Uses
+                Creative techniques
+                Strategic planning
+                Argument mapping
+        Tools
+          Pen and paper
+          Mermaid
+    
+
+      ---
+      config:
+        layout: elk
+      ---
+      mindmap
+      root((mindmap))
+        Origins
+          Long history
+          ::icon(fa fa-book)
+          Popularisation
+            British popular psychology author Tony Buzan
+        Research
+          On effectiveness<br/>and features
+          On Automatic creation
+            Uses
+                Creative techniques
+                Strategic planning
+                Argument mapping
+        Tools
+          Pen and paper
+          Mermaid
+    
+
+      ---
+      config:
+        layout: cose-bilkent
+      ---
       flowchart LR
-        AB["apa@apa@"] --> B(("`apa@apa`"))
+      root{mindmap} --- Origins --- Europe
+      Origins --> Asia
+      root --- Background --- Rich
+      Background --- Poor
+      subgraph apa
+        Background
+        Poor
+      end
+
+
+
+
+    
+
+      ---
+      config:
+        layout: elk
+      ---
+      flowchart LR
+      root{mindmap} --- Origins --- Europe
+      Origins --> Asia
+      root --- Background --- Rich
+      Background --- Poor
+
+
+
+
     
       flowchart
@@ -258,6 +481,44 @@ config:
     
 ---
+config:
+  layout: elk
+---
+      flowchart LR
+      a
+      subgraph s0["APA"]
+      subgraph s8["APA"]
+      subgraph s1["APA"]
+        D{"X"}
+        E[Q]
+      end
+      subgraph s3["BAPA"]
+        F[Q]
+        I
+      end
+            D --> I
+            D --> I
+            D --> I
+
+      I{"X"}
+      end
+      end
+    
+
+---
+config:
+  layout: elk
+---
+      flowchart LR
+      a
+        D{"Use the editor"}
+
+      D -- Mermaid js --> I{"fa:fa-code Text"}
+      D-->I
+      D-->I
+    
+
+---
 config:
   layout: elk
 ---
diff --git a/cypress/platform/mindmap-layouts.html b/cypress/platform/mindmap-layouts.html
new file mode 100644
index 000000000..0aef65d42
--- /dev/null
+++ b/cypress/platform/mindmap-layouts.html
@@ -0,0 +1,376 @@
+
+
+  
+    
+    
+    Mermaid Quick Test Page
+    
+    
+  
+
+  
+    
+ ---
+      config:
+        layout: tidy-tree
+      ---
+      mindmap
+      root((mindmap))
+        A
+        B
+    
+
+ ---
+      config:
+        layout: dagre
+      ---
+      mindmap
+      root((mindmap))
+        A
+        B
+    
+
+ ---
+      config:
+        layout: elk
+      ---
+      mindmap
+      root((mindmap))
+        A
+        B
+    
+
+ ---
+      config:
+        layout: cose-bilkent
+      ---
+      mindmap
+      root((mindmap))
+        A
+        B
+    
+
+    ---
+      config:
+        layout: tidy-tree
+      ---
+      mindmap
+      root((mindmap is a long thing))
+        A
+        B
+        C
+        D
+    
+
+    ---
+      config:
+        layout: dagre
+      ---
+      mindmap
+      root((mindmap is a long thing))
+        A
+        B
+        C
+        D
+    
+
+    ---
+      config:
+        layout: elk
+      ---
+      mindmap
+      root((mindmap is a long thing))
+        A
+        B
+        C
+        D
+    
+
+    ---
+      config:
+        layout: cose-bilkent
+      ---
+      mindmap
+      root((mindmap is a long thing))
+        A
+        B
+        C
+        D
+    
+ +
+    ---
+      config:
+        layout: tidy-tree
+      ---
+      mindmap
+      root((mindmap))
+        Origins
+          Long history
+          ::icon(fa fa-book)
+          Popularisation
+            British popular psychology author Tony Buzan
+        Research
+          On effectiveness<br/>and features
+          On Automatic creation
+            Uses
+                Creative techniques
+                Strategic planning
+                Argument mapping
+        Tools
+              id)I am a cloud(
+                  id))I am a bang((
+                    Tools
+    
+
+    ---
+      config:
+        layout: dagre
+      ---
+      mindmap
+      root((mindmap))
+        Origins
+          Long history
+          ::icon(fa fa-book)
+          Popularisation
+            British popular psychology author Tony Buzan
+        Research
+          On effectiveness<br/>and features
+          On Automatic creation
+            Uses
+                Creative techniques
+                Strategic planning
+                Argument mapping
+        Tools
+              id)I am a cloud(
+                  id))I am a bang((
+                    Tools
+    
+
+    ---
+      config:
+        layout: elk
+      ---
+      mindmap
+      root((mindmap))
+        Origins
+          Long history
+          ::icon(fa fa-book)
+          Popularisation
+            British popular psychology author Tony Buzan
+        Research
+          On effectiveness<br/>and features
+          On Automatic creation
+            Uses
+                Creative techniques
+                Strategic planning
+                Argument mapping
+        Tools
+              id)I am a cloud(
+                  id))I am a bang((
+                    Tools
+    
+
+    ---
+      config:
+        layout: cose-bilkent
+      ---
+      mindmap
+      root((mindmap))
+        Origins
+          Long history
+          ::icon(fa fa-book)
+          Popularisation
+            British popular psychology author Tony Buzan
+        Research
+          On effectiveness<br/>and features
+          On Automatic creation
+            Uses
+                Creative techniques
+                Strategic planning
+                Argument mapping
+        Tools
+              id)I am a cloud(
+                  id))I am a bang((
+                    Tools
+    
+
+      ---
+      config:
+        layout: tidy-tree
+      ---
+      mindmap
+      root((mindmap))
+        A
+          a
+            apa[I am a long long multline string passing several levels of text. Lorum ipsum and so on. I am a long long multline string passing several levels of text. Lorum ipsum and so on. I am a long long multline string passing several levels of text. Lorum ipsum and so on. I am a long long multline string passing several levels of text. Lorum ipsum and so on]
+            apa2[I am a long long multline string passing several levels of text. Lorum ipsum and so on. I am a long long multline string passing several levels of text. Lorum ipsum and so on. I am a long long multline string passing several levels of text. Lorum ipsum and so on. I am a long long multline string passing several levels of text. Lorum ipsum and so on]
+          b
+          c
+          d
+        B
+            apa3[I am a long long multline string passing several levels of text. Lorum ipsum and so on. I am a long long multline string passing several levels of text. Lorum ipsum and so on. I am a long long multline string passing several levels of text. Lorum ipsum and so on. I am a long long multline string passing several levels of text. Lorum ipsum and so on]
+        D
+          apa5[I am a long long multline string passing several levels of text. Lorum ipsum and so on. I am a long long multline string passing several levels of text. Lorum ipsum and so on. I am a long long multline string passing several levels of text. Lorum ipsum and so on. I am a long long multline string passing several levels of text. Lorum ipsum and so on]
+          apa4[I am a long long multline string passing several levels of text. Lorum ipsum and so on. I am a long long multline string passing several levels of text. Lorum ipsum and so on. I am a long long multline string passing several levels of text. Lorum ipsum and so on. I am a long long multline string passing several levels of text. Lorum ipsum and so on]
+
+    
+
+      ---
+      config:
+        layout: dagre
+      ---
+      mindmap
+      root((mindmap))
+        A
+          a
+            apa[I am a long long multline string passing several levels of text. Lorum ipsum and so on. I am a long long multline string passing several levels of text. Lorum ipsum and so on. I am a long long multline string passing several levels of text. Lorum ipsum and so on. I am a long long multline string passing several levels of text. Lorum ipsum and so on]
+            apa2[I am a long long multline string passing several levels of text. Lorum ipsum and so on. I am a long long multline string passing several levels of text. Lorum ipsum and so on. I am a long long multline string passing several levels of text. Lorum ipsum and so on. I am a long long multline string passing several levels of text. Lorum ipsum and so on]
+          b
+          c
+          d
+        B
+            apa3[I am a long long multline string passing several levels of text. Lorum ipsum and so on. I am a long long multline string passing several levels of text. Lorum ipsum and so on. I am a long long multline string passing several levels of text. Lorum ipsum and so on. I am a long long multline string passing several levels of text. Lorum ipsum and so on]
+        D
+          apa5[I am a long long multline string passing several levels of text. Lorum ipsum and so on. I am a long long multline string passing several levels of text. Lorum ipsum and so on. I am a long long multline string passing several levels of text. Lorum ipsum and so on. I am a long long multline string passing several levels of text. Lorum ipsum and so on]
+          apa4[I am a long long multline string passing several levels of text. Lorum ipsum and so on. I am a long long multline string passing several levels of text. Lorum ipsum and so on. I am a long long multline string passing several levels of text. Lorum ipsum and so on. I am a long long multline string passing several levels of text. Lorum ipsum and so on]
+
+    
+
+      ---
+      config:
+        layout: elk
+      ---
+      mindmap
+      root((mindmap))
+        A
+          a
+            apa[I am a long long multline string passing several levels of text. Lorum ipsum and so on. I am a long long multline string passing several levels of text. Lorum ipsum and so on. I am a long long multline string passing several levels of text. Lorum ipsum and so on. I am a long long multline string passing several levels of text. Lorum ipsum and so on]
+            apa2[I am a long long multline string passing several levels of text. Lorum ipsum and so on. I am a long long multline string passing several levels of text. Lorum ipsum and so on. I am a long long multline string passing several levels of text. Lorum ipsum and so on. I am a long long multline string passing several levels of text. Lorum ipsum and so on]
+          b
+          c
+          d
+        B
+            apa3[I am a long long multline string passing several levels of text. Lorum ipsum and so on. I am a long long multline string passing several levels of text. Lorum ipsum and so on. I am a long long multline string passing several levels of text. Lorum ipsum and so on. I am a long long multline string passing several levels of text. Lorum ipsum and so on]
+        D
+          apa5[I am a long long multline string passing several levels of text. Lorum ipsum and so on. I am a long long multline string passing several levels of text. Lorum ipsum and so on. I am a long long multline string passing several levels of text. Lorum ipsum and so on. I am a long long multline string passing several levels of text. Lorum ipsum and so on]
+          apa4[I am a long long multline string passing several levels of text. Lorum ipsum and so on. I am a long long multline string passing several levels of text. Lorum ipsum and so on. I am a long long multline string passing several levels of text. Lorum ipsum and so on. I am a long long multline string passing several levels of text. Lorum ipsum and so on]
+
+    
+
+      ---
+      config:
+        layout: cose-bilkent
+      ---
+      mindmap
+      root((mindmap))
+        A
+          a
+            apa[I am a long long multline string passing several levels of text. Lorum ipsum and so on. I am a long long multline string passing several levels of text. Lorum ipsum and so on. I am a long long multline string passing several levels of text. Lorum ipsum and so on. I am a long long multline string passing several levels of text. Lorum ipsum and so on]
+            apa2[I am a long long multline string passing several levels of text. Lorum ipsum and so on. I am a long long multline string passing several levels of text. Lorum ipsum and so on. I am a long long multline string passing several levels of text. Lorum ipsum and so on. I am a long long multline string passing several levels of text. Lorum ipsum and so on]
+          b
+          c
+          d
+        B
+            apa3[I am a long long multline string passing several levels of text. Lorum ipsum and so on. I am a long long multline string passing several levels of text. Lorum ipsum and so on. I am a long long multline string passing several levels of text. Lorum ipsum and so on. I am a long long multline string passing several levels of text. Lorum ipsum and so on]
+        D
+          apa5[I am a long long multline string passing several levels of text. Lorum ipsum and so on. I am a long long multline string passing several levels of text. Lorum ipsum and so on. I am a long long multline string passing several levels of text. Lorum ipsum and so on. I am a long long multline string passing several levels of text. Lorum ipsum and so on]
+          apa4[I am a long long multline string passing several levels of text. Lorum ipsum and so on. I am a long long multline string passing several levels of text. Lorum ipsum and so on. I am a long long multline string passing several levels of text. Lorum ipsum and so on. I am a long long multline string passing several levels of text. Lorum ipsum and so on]
+
+    
+ +
+ ---
+      config:
+        layout: tidy-tree
+      ---
+      mindmap
+      ((This is a mindmap))
+        child1
+         grandchild 1
+         grandchild 2
+        child2
+         grandchild 3
+         grandchild 4
+        child3
+         grandchild 5
+         grandchild 6
+      
+    
+ +
+ ---
+      config:
+        layout: dagre
+      ---
+      mindmap
+      ((This is a mindmap))
+        child1
+         grandchild 1
+         grandchild 2
+        child2
+         grandchild 3
+         grandchild 4
+        child3
+         grandchild 5
+         grandchild 6
+      
+    
+ +
+ ---
+      config:
+        layout: elk
+      ---
+      mindmap
+      ((This is a mindmap))
+        child1
+         grandchild 1
+         grandchild 2
+        child2
+         grandchild 3
+         grandchild 4
+        child3
+         grandchild 5
+         grandchild 6
+      
+    
+ +
+ ---
+      config:
+        layout: cose-bilkent
+      ---
+      mindmap
+      ((This is a mindmap))
+        child1
+         grandchild 1
+         grandchild 2
+        child2
+         grandchild 3
+         grandchild 4
+        child3
+         grandchild 5
+         grandchild 6
+      
+    
+ +
+ + + diff --git a/cypress/platform/sidv.html b/cypress/platform/sidv.html index b0a1699da..1651b0737 100644 --- a/cypress/platform/sidv.html +++ b/cypress/platform/sidv.html @@ -41,10 +41,6 @@ graph TB const { svg } = await mermaid.render('d22', value); console.log(svg); el.innerHTML = svg; - // mermaid.test1('first_slow', 1200).then((r) => console.info(r)); - // mermaid.test1('second_fast', 200).then((r) => console.info(r)); - // mermaid.test1('third_fast', 200).then((r) => console.info(r)); - // mermaid.test1('forth_slow', 1200).then((r) => console.info(r)); diff --git a/cypress/platform/viewer.js b/cypress/platform/viewer.js index e120469fe..de7dcafe8 100644 --- a/cypress/platform/viewer.js +++ b/cypress/platform/viewer.js @@ -1,5 +1,6 @@ import externalExample from './mermaid-example-diagram.esm.mjs'; import layouts from './mermaid-layout-elk.esm.mjs'; +import tidyTree from './mermaid-layout-tidy-tree.esm.mjs'; import zenUml from './mermaid-zenuml.esm.mjs'; import mermaid from './mermaid.esm.mjs'; @@ -65,6 +66,7 @@ const contentLoaded = async function () { await mermaid.registerExternalDiagrams([externalExample, zenUml]); mermaid.registerLayoutLoaders(layouts); + mermaid.registerLayoutLoaders(tidyTree); mermaid.initialize(graphObj.mermaid); /** * CC-BY-4.0 @@ -182,7 +184,7 @@ const contentLoadedApi = async function () { for (let i = 0; i < numCodes; i++) { const { svg, bindFunctions } = await mermaid.render('newid' + i, graphObj.code[i], divs[i]); div.innerHTML = svg; - bindFunctions(div); + bindFunctions?.(div); } } else { const div = document.createElement('div'); @@ -194,7 +196,7 @@ const contentLoadedApi = async function () { const { svg, bindFunctions } = await mermaid.render('newid', graphObj.code, div); div.innerHTML = svg; console.log(div.innerHTML); - bindFunctions(div); + bindFunctions?.(div); } } }; diff --git a/cypress/timings.json b/cypress/timings.json index 05263ad9f..8a6a4c00e 100644 --- a/cypress/timings.json +++ b/cypress/timings.json @@ -2,219 +2,227 @@ "durations": [ { "spec": "cypress/integration/other/configuration.spec.js", - "duration": 5672 + "duration": 5841 }, { "spec": "cypress/integration/other/external-diagrams.spec.js", - "duration": 1990 + "duration": 2138 }, { "spec": "cypress/integration/other/ghsa.spec.js", - "duration": 3186 + "duration": 3370 }, { "spec": "cypress/integration/other/iife.spec.js", - "duration": 1948 + "duration": 2052 }, { "spec": "cypress/integration/other/interaction.spec.js", - "duration": 11938 + "duration": 12243 }, { "spec": "cypress/integration/other/rerender.spec.js", - "duration": 1932 + "duration": 2065 }, { "spec": "cypress/integration/other/xss.spec.js", - "duration": 27237 + "duration": 31288 }, { "spec": "cypress/integration/rendering/appli.spec.js", - "duration": 3170 + "duration": 3421 }, { "spec": "cypress/integration/rendering/architecture.spec.ts", - "duration": 104 + "duration": 97 }, { "spec": "cypress/integration/rendering/block.spec.js", - "duration": 17390 + "duration": 18500 }, { "spec": "cypress/integration/rendering/c4.spec.js", - "duration": 5296 + "duration": 5793 }, { "spec": "cypress/integration/rendering/classDiagram-elk-v3.spec.js", - "duration": 39004 + "duration": 40966 }, { "spec": "cypress/integration/rendering/classDiagram-handDrawn-v3.spec.js", - "duration": 37653 + "duration": 39176 }, { "spec": "cypress/integration/rendering/classDiagram-v2.spec.js", - "duration": 23278 + "duration": 23468 }, { "spec": "cypress/integration/rendering/classDiagram-v3.spec.js", - "duration": 36645 + "duration": 38291 }, { "spec": "cypress/integration/rendering/classDiagram.spec.js", - "duration": 15418 + "duration": 16949 }, { "spec": "cypress/integration/rendering/conf-and-directives.spec.js", - "duration": 9684 + "duration": 9480 }, { "spec": "cypress/integration/rendering/current.spec.js", - "duration": 2570 + "duration": 2753 }, { "spec": "cypress/integration/rendering/erDiagram-unified.spec.js", - "duration": 84687 + "duration": 88028 }, { "spec": "cypress/integration/rendering/erDiagram.spec.js", - "duration": 14819 + "duration": 15615 }, { "spec": "cypress/integration/rendering/errorDiagram.spec.js", - "duration": 3371 + "duration": 3706 }, { "spec": "cypress/integration/rendering/flowchart-elk.spec.js", - "duration": 39925 + "duration": 43905 }, { "spec": "cypress/integration/rendering/flowchart-handDrawn.spec.js", - "duration": 34694 + "duration": 31217 }, { "spec": "cypress/integration/rendering/flowchart-icon.spec.js", - "duration": 7137 + "duration": 7531 }, { "spec": "cypress/integration/rendering/flowchart-shape-alias.spec.ts", - "duration": 24740 + "duration": 25423 }, { "spec": "cypress/integration/rendering/flowchart-v2.spec.js", - "duration": 42077 + "duration": 49664 }, { "spec": "cypress/integration/rendering/flowchart.spec.js", - "duration": 30642 + "duration": 32525 }, { "spec": "cypress/integration/rendering/gantt.spec.js", - "duration": 18085 + "duration": 20915 }, { "spec": "cypress/integration/rendering/gitGraph.spec.js", - "duration": 50107 + "duration": 53556 }, { "spec": "cypress/integration/rendering/iconShape.spec.ts", - "duration": 276279 + "duration": 283038 }, { "spec": "cypress/integration/rendering/imageShape.spec.ts", - "duration": 56505 + "duration": 59434 }, { "spec": "cypress/integration/rendering/info.spec.ts", - "duration": 3036 + "duration": 3101 }, { "spec": "cypress/integration/rendering/journey.spec.js", - "duration": 6889 + "duration": 7099 }, { "spec": "cypress/integration/rendering/kanban.spec.ts", - "duration": 7353 + "duration": 7567 }, { "spec": "cypress/integration/rendering/katex.spec.js", - "duration": 3580 + "duration": 3817 }, { "spec": "cypress/integration/rendering/marker_unique_id.spec.js", - "duration": 2508 + "duration": 2624 + }, + { + "spec": "cypress/integration/rendering/mindmap-tidy-tree.spec.js", + "duration": 4246 }, { "spec": "cypress/integration/rendering/mindmap.spec.ts", - "duration": 10939 + "duration": 11967 }, { "spec": "cypress/integration/rendering/newShapes.spec.ts", - "duration": 149102 + "duration": 151914 }, { "spec": "cypress/integration/rendering/oldShapes.spec.ts", - "duration": 113987 + "duration": 116698 }, { "spec": "cypress/integration/rendering/packet.spec.ts", - "duration": 4060 + "duration": 4967 }, { "spec": "cypress/integration/rendering/pie.spec.ts", - "duration": 5715 + "duration": 6700 }, { "spec": "cypress/integration/rendering/quadrantChart.spec.js", - "duration": 8945 + "duration": 8963 }, { "spec": "cypress/integration/rendering/radar.spec.js", - "duration": 5337 + "duration": 5540 }, { "spec": "cypress/integration/rendering/requirement.spec.js", - "duration": 2643 + "duration": 2782 }, { "spec": "cypress/integration/rendering/requirementDiagram-unified.spec.js", - "duration": 52072 + "duration": 54797 }, { "spec": "cypress/integration/rendering/sankey.spec.ts", - "duration": 6692 + "duration": 6914 + }, + { + "spec": "cypress/integration/rendering/sequencediagram-v2.spec.js", + "duration": 20481 }, { "spec": "cypress/integration/rendering/sequencediagram.spec.js", - "duration": 35721 + "duration": 38490 }, { "spec": "cypress/integration/rendering/stateDiagram-v2.spec.js", - "duration": 26030 + "duration": 30766 }, { "spec": "cypress/integration/rendering/stateDiagram.spec.js", - "duration": 16333 + "duration": 16705 }, { "spec": "cypress/integration/rendering/theme.spec.js", - "duration": 29287 + "duration": 30928 }, { "spec": "cypress/integration/rendering/timeline.spec.ts", - "duration": 8491 + "duration": 8424 }, { "spec": "cypress/integration/rendering/treemap.spec.ts", - "duration": 12291 + "duration": 12533 }, { "spec": "cypress/integration/rendering/xyChart.spec.js", - "duration": 20651 + "duration": 21197 }, { "spec": "cypress/integration/rendering/zenuml.spec.js", - "duration": 3218 + "duration": 3455 } ] } diff --git a/demos/block.html b/demos/block.html index f0957b670..5296126e0 100644 --- a/demos/block.html +++ b/demos/block.html @@ -10,7 +10,7 @@

Block diagram demos

-block-beta
+block
 columns 1
   db(("DB"))
   blockArrowId6<["   "]>(down)
@@ -26,7 +26,7 @@ columns 1
   style B fill:#f9F,stroke:#333,stroke-width:4px
     
-block-beta
+block
     A1["square"]
     B1("rounded")
     C1(("circle"))
@@ -36,7 +36,7 @@ block-beta
     
-block-beta
+block
     A1(["stadium"])
     A2[["subroutine"]]
     B1[("cylinder")]
@@ -48,7 +48,7 @@ block-beta
     
-block-beta
+block
   block:e:4
     columns 2
       f
@@ -57,7 +57,7 @@ block-beta
 
     
-block-beta
+block
   block:e:4
     columns 2
       f
@@ -67,7 +67,7 @@ block-beta
 
     
-block-beta
+block
   columns 3
   a:3
   block:e:3
@@ -80,7 +80,7 @@ block-beta
 
     
-block-beta
+block
   columns 4
   a b c d
   block:e:4
@@ -97,19 +97,19 @@ flowchart LR
   X-- "a label" -->z
     
-block-beta
+block
 columns 5
    A space B
    A --x B
     
-block-beta
+block
 columns 3
   a["A wide one"] b:2 c:2 d
     
-block-beta
+block
 columns 3
   a b c
   e:3
@@ -117,7 +117,7 @@ columns 3
     
-block-beta
+block
 
   A1:3
   A2:1
diff --git a/demos/sankey.html b/demos/sankey.html
index 2439cb589..92e0f587d 100644
--- a/demos/sankey.html
+++ b/demos/sankey.html
@@ -20,12 +20,14 @@
           width: 800
           nodeAlignment: left
       ---
-      sankey-beta
-        Revenue,Expenses,10
-        Revenue,Profit,10
-        Expenses,Manufacturing,5
-        Expenses,Tax,3
-        Expenses,Research,2
+     sankey
+        a,b,8
+        b,c,8
+        c,d,8
+        d,e,8
+
+        x,c,4
+        c,y,4
     

Energy flow

@@ -40,7 +42,7 @@ linkColor: gradient nodeAlignment: justify --- - sankey-beta + sankey Agricultural 'waste',Bio-conversion,124.729 Bio-conversion,Liquid,0.597 diff --git a/demos/xychart.html b/demos/xychart.html index 25f8ec8ca..5706b15ea 100644 --- a/demos/xychart.html +++ b/demos/xychart.html @@ -16,7 +16,7 @@

XY Charts demos

-    xychart-beta
+    xychart
     title "Sales Revenue (in $)"
     x-axis [jan, feb, mar, apr, may, jun, jul, aug, sep, oct, nov, dec]
     y-axis "Revenue (in $)" 4000 --> 11000
@@ -26,7 +26,7 @@
     

XY Charts horizontal

-    xychart-beta horizontal
+    xychart horizontal
     title "Basic xychart"
     x-axis "this is x axis" [category1, "category 2", category3, category4]
     y-axis yaxisText 10 --> 150
@@ -36,7 +36,7 @@
     

XY Charts only lines and bar

-    xychart-beta
+    xychart
     line [23, 46, 77, 34]
     line [45, 32, 33, 12]
     line [87, 54, 99, 85]
@@ -48,13 +48,13 @@
     

XY Charts with +ve and -ve numbers

-    xychart-beta
+    xychart
     line [+1.3, .6, 2.4, -.34]
     

XY Charts Bar with multiple category

-    xychart-beta
+    xychart
     title "Basic xychart with many categories"
     x-axis "this is x axis" [category1, "category 2", category3, category4, category5, category6, category7]
     y-axis yaxisText 10 --> 150
@@ -63,7 +63,7 @@
 
     

XY Charts line with multiple category

-    xychart-beta
+    xychart
     title "Line chart with many category"
     x-axis "this is x axis" [category1, "category 2", category3, category4, category5, category6, category7]
     y-axis yaxisText 10 --> 150
@@ -72,7 +72,7 @@
 
     

XY Charts category with large text

-    xychart-beta
+    xychart
     title "Basic xychart with many categories with category overlap"
     x-axis "this is x axis" [category1, "Lorem ipsum dolor sit amet, qui minim labore adipisicing minim sint cillum sint consectetur cupidatat.", category3, category4, category5, category6, category7]
     y-axis yaxisText 10 --> 150
@@ -89,7 +89,7 @@ config:
     height: 20
     plotReservedSpacePercent: 100
 ---
-    xychart-beta
+    xychart
       line [5000, 9000, 7500, 6200, 9500, 5500, 11000, 8200, 9200, 9500, 7000, 8800]
     
@@ -103,7 +103,7 @@ config: height: 20 plotReservedSpacePercent: 100 --- - xychart-beta + xychart bar [5000, 9000, 7500, 6200, 9500, 5500, 11000, 8200, 9200, 9500, 7000, 8800]
@@ -136,7 +136,7 @@ config: chartOrientation: horizontal plotReservedSpacePercent: 60 --- - xychart-beta + xychart title "Sales Revenue" x-axis Months [jan, feb, mar, apr, may, jun, jul, aug, sep, oct, nov, dec] y-axis "Revenue (in $)" 4000 --> 11000 @@ -162,7 +162,7 @@ config: xAxisLineColor: "#87ceeb" plotColorPalette: "#008000, #faba63" --- - xychart-beta + xychart title "Sales Revenue" x-axis Months [jan, feb, mar, apr, may, jun, jul, aug, sep, oct, nov, dec] y-axis "Revenue (in $)" 4000 --> 11000 diff --git a/docs/config/faq.md b/docs/config/faq.md index db775e438..6d27b658e 100644 --- a/docs/config/faq.md +++ b/docs/config/faq.md @@ -6,7 +6,7 @@ # Frequently Asked Questions -1. [How to add title to flowchart?](https://github.com/mermaid-js/mermaid/issues/556#issuecomment-363182217) +1. [How to add title to flowchart?](https://github.com/mermaid-js/mermaid/issues/1433#issuecomment-1991554712) 2. [How to specify custom CSS file?](https://github.com/mermaidjs/mermaid.cli/pull/24#issuecomment-373402785) 3. [How to fix tooltip misplacement issue?](https://github.com/mermaid-js/mermaid/issues/542#issuecomment-3343564621) 4. [How to specify gantt diagram xAxis format?](https://github.com/mermaid-js/mermaid/issues/269#issuecomment-373229136) diff --git a/docs/config/layouts.md b/docs/config/layouts.md new file mode 100644 index 000000000..18e9c9423 --- /dev/null +++ b/docs/config/layouts.md @@ -0,0 +1,40 @@ +> **Warning** +> +> ## THIS IS AN AUTOGENERATED FILE. DO NOT EDIT. +> +> ## Please edit the corresponding file in [/packages/mermaid/src/docs/config/layouts.md](../../packages/mermaid/src/docs/config/layouts.md). + +# Layouts + +This page lists the available layout algorithms supported in Mermaid diagrams. + +## Supported Layouts + +- **elk**: [ELK (Eclipse Layout Kernel)](https://www.eclipse.org/elk/) +- **tidy-tree**: Tidy tree layout for hierarchical diagrams [Tidy Tree Configuration](/config/tidy-tree) +- **cose-bilkent**: Cose Bilkent layout for force-directed graphs +- **dagre**: Dagre layout for layered graphs + +## How to Use + +You can specify the layout in your diagram's YAML config or initialization options. For example: + +```mermaid-example +--- +config: + layout: elk +--- +graph TD; + A-->B; + B-->C; +``` + +```mermaid +--- +config: + layout: elk +--- +graph TD; + A-->B; + B-->C; +``` diff --git a/docs/config/setup/config/README.md b/docs/config/setup/config/README.md index 67fca78eb..c811c7b08 100644 --- a/docs/config/setup/config/README.md +++ b/docs/config/setup/config/README.md @@ -19,6 +19,7 @@ - [addDirective](functions/addDirective.md) - [getConfig](functions/getConfig.md) - [getSiteConfig](functions/getSiteConfig.md) +- [getUserDefinedConfig](functions/getUserDefinedConfig.md) - [reset](functions/reset.md) - [sanitize](functions/sanitize.md) - [saveConfigFromInitialize](functions/saveConfigFromInitialize.md) diff --git a/docs/config/setup/config/functions/getUserDefinedConfig.md b/docs/config/setup/config/functions/getUserDefinedConfig.md new file mode 100644 index 000000000..ed39f1337 --- /dev/null +++ b/docs/config/setup/config/functions/getUserDefinedConfig.md @@ -0,0 +1,19 @@ +> **Warning** +> +> ## THIS IS AN AUTOGENERATED FILE. DO NOT EDIT. +> +> ## Please edit the corresponding file in [/packages/mermaid/src/docs/config/setup/config/functions/getUserDefinedConfig.md](../../../../../packages/mermaid/src/docs/config/setup/config/functions/getUserDefinedConfig.md). + +[**mermaid**](../../README.md) + +--- + +# Function: getUserDefinedConfig() + +> **getUserDefinedConfig**(): [`MermaidConfig`](../../mermaid/interfaces/MermaidConfig.md) + +Defined in: [packages/mermaid/src/config.ts:252](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/config.ts#L252) + +## Returns + +[`MermaidConfig`](../../mermaid/interfaces/MermaidConfig.md) diff --git a/docs/config/setup/defaultConfig/variables/configKeys.md b/docs/config/setup/defaultConfig/variables/configKeys.md index 222111bd5..82b68d780 100644 --- a/docs/config/setup/defaultConfig/variables/configKeys.md +++ b/docs/config/setup/defaultConfig/variables/configKeys.md @@ -12,4 +12,4 @@ > `const` **configKeys**: `Set`<`string`> -Defined in: [packages/mermaid/src/defaultConfig.ts:290](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/defaultConfig.ts#L290) +Defined in: [packages/mermaid/src/defaultConfig.ts:292](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/defaultConfig.ts#L292) diff --git a/docs/config/setup/mermaid/README.md b/docs/config/setup/mermaid/README.md index 3e2cd7a28..653d90592 100644 --- a/docs/config/setup/mermaid/README.md +++ b/docs/config/setup/mermaid/README.md @@ -10,10 +10,6 @@ # mermaid -## Classes - -- [UnknownDiagramError](classes/UnknownDiagramError.md) - ## Interfaces - [DetailedError](interfaces/DetailedError.md) @@ -27,6 +23,7 @@ - [RenderOptions](interfaces/RenderOptions.md) - [RenderResult](interfaces/RenderResult.md) - [RunOptions](interfaces/RunOptions.md) +- [UnknownDiagramError](interfaces/UnknownDiagramError.md) ## Type Aliases diff --git a/docs/config/setup/mermaid/classes/UnknownDiagramError.md b/docs/config/setup/mermaid/classes/UnknownDiagramError.md deleted file mode 100644 index c077f0e34..000000000 --- a/docs/config/setup/mermaid/classes/UnknownDiagramError.md +++ /dev/null @@ -1,159 +0,0 @@ -> **Warning** -> -> ## THIS IS AN AUTOGENERATED FILE. DO NOT EDIT. -> -> ## Please edit the corresponding file in [/packages/mermaid/src/docs/config/setup/mermaid/classes/UnknownDiagramError.md](../../../../../packages/mermaid/src/docs/config/setup/mermaid/classes/UnknownDiagramError.md). - -[**mermaid**](../../README.md) - ---- - -# Class: UnknownDiagramError - -Defined in: [packages/mermaid/src/errors.ts:1](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/errors.ts#L1) - -## Extends - -- `Error` - -## Constructors - -### new UnknownDiagramError() - -> **new UnknownDiagramError**(`message`): [`UnknownDiagramError`](UnknownDiagramError.md) - -Defined in: [packages/mermaid/src/errors.ts:2](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/errors.ts#L2) - -#### Parameters - -##### message - -`string` - -#### Returns - -[`UnknownDiagramError`](UnknownDiagramError.md) - -#### Overrides - -`Error.constructor` - -## Properties - -### cause? - -> `optional` **cause**: `unknown` - -Defined in: node_modules/.pnpm/typescript\@5.7.3/node_modules/typescript/lib/lib.es2022.error.d.ts:26 - -#### Inherited from - -`Error.cause` - ---- - -### message - -> **message**: `string` - -Defined in: node_modules/.pnpm/typescript\@5.7.3/node_modules/typescript/lib/lib.es5.d.ts:1077 - -#### Inherited from - -`Error.message` - ---- - -### name - -> **name**: `string` - -Defined in: node_modules/.pnpm/typescript\@5.7.3/node_modules/typescript/lib/lib.es5.d.ts:1076 - -#### Inherited from - -`Error.name` - ---- - -### stack? - -> `optional` **stack**: `string` - -Defined in: node_modules/.pnpm/typescript\@5.7.3/node_modules/typescript/lib/lib.es5.d.ts:1078 - -#### Inherited from - -`Error.stack` - ---- - -### prepareStackTrace()? - -> `static` `optional` **prepareStackTrace**: (`err`, `stackTraces`) => `any` - -Defined in: node_modules/.pnpm/@types+node\@22.13.5/node_modules/@types/node/globals.d.ts:143 - -Optional override for formatting stack traces - -#### Parameters - -##### err - -`Error` - -##### stackTraces - -`CallSite`\[] - -#### Returns - -`any` - -#### See - - - -#### Inherited from - -`Error.prepareStackTrace` - ---- - -### stackTraceLimit - -> `static` **stackTraceLimit**: `number` - -Defined in: node_modules/.pnpm/@types+node\@22.13.5/node_modules/@types/node/globals.d.ts:145 - -#### Inherited from - -`Error.stackTraceLimit` - -## Methods - -### captureStackTrace() - -> `static` **captureStackTrace**(`targetObject`, `constructorOpt`?): `void` - -Defined in: node_modules/.pnpm/@types+node\@22.13.5/node_modules/@types/node/globals.d.ts:136 - -Create .stack property on a target object - -#### Parameters - -##### targetObject - -`object` - -##### constructorOpt? - -`Function` - -#### Returns - -`void` - -#### Inherited from - -`Error.captureStackTrace` diff --git a/docs/config/setup/mermaid/interfaces/LayoutData.md b/docs/config/setup/mermaid/interfaces/LayoutData.md index b4c88454e..32bef322c 100644 --- a/docs/config/setup/mermaid/interfaces/LayoutData.md +++ b/docs/config/setup/mermaid/interfaces/LayoutData.md @@ -10,7 +10,7 @@ # Interface: LayoutData -Defined in: [packages/mermaid/src/rendering-util/types.ts:145](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/rendering-util/types.ts#L145) +Defined in: [packages/mermaid/src/rendering-util/types.ts:168](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/rendering-util/types.ts#L168) ## Indexable @@ -22,7 +22,7 @@ Defined in: [packages/mermaid/src/rendering-util/types.ts:145](https://github.co > **config**: [`MermaidConfig`](MermaidConfig.md) -Defined in: [packages/mermaid/src/rendering-util/types.ts:148](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/rendering-util/types.ts#L148) +Defined in: [packages/mermaid/src/rendering-util/types.ts:171](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/rendering-util/types.ts#L171) --- @@ -30,7 +30,7 @@ Defined in: [packages/mermaid/src/rendering-util/types.ts:148](https://github.co > **edges**: `Edge`\[] -Defined in: [packages/mermaid/src/rendering-util/types.ts:147](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/rendering-util/types.ts#L147) +Defined in: [packages/mermaid/src/rendering-util/types.ts:170](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/rendering-util/types.ts#L170) --- @@ -38,4 +38,4 @@ Defined in: [packages/mermaid/src/rendering-util/types.ts:147](https://github.co > **nodes**: `Node`\[] -Defined in: [packages/mermaid/src/rendering-util/types.ts:146](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/rendering-util/types.ts#L146) +Defined in: [packages/mermaid/src/rendering-util/types.ts:169](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/rendering-util/types.ts#L169) diff --git a/docs/config/setup/mermaid/interfaces/Mermaid.md b/docs/config/setup/mermaid/interfaces/Mermaid.md index fd15b306b..0c63d140a 100644 --- a/docs/config/setup/mermaid/interfaces/Mermaid.md +++ b/docs/config/setup/mermaid/interfaces/Mermaid.md @@ -32,7 +32,7 @@ page. ### detectType() -> **detectType**: (`text`, `config`?) => `string` +> **detectType**: (`text`, `config?`) => `string` Defined in: [packages/mermaid/src/mermaid.ts:449](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/mermaid.ts#L449) @@ -105,7 +105,7 @@ An array of objects with the id of the diagram. ### ~~init()~~ -> **init**: (`config`?, `nodes`?, `callback`?) => `Promise`<`void`> +> **init**: (`config?`, `nodes?`, `callback?`) => `Promise`<`void`> Defined in: [packages/mermaid/src/mermaid.ts:442](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/mermaid.ts#L442) @@ -117,7 +117,7 @@ Defined in: [packages/mermaid/src/mermaid.ts:442](https://github.com/mermaid-js/ [`MermaidConfig`](MermaidConfig.md) -**Deprecated**, please set configuration in [initialize](Mermaid.md#initialize). +**Deprecated**, please set configuration in [initialize](#initialize). ##### nodes? @@ -141,13 +141,13 @@ Called once for each rendered diagram's id. #### Deprecated -Use [initialize](Mermaid.md#initialize) and [run](Mermaid.md#run) instead. +Use [initialize](#initialize) and [run](#run) instead. Renders the mermaid diagrams #### Deprecated -Use [initialize](Mermaid.md#initialize) and [run](Mermaid.md#run) instead. +Use [initialize](#initialize) and [run](#run) instead. --- @@ -176,7 +176,7 @@ Configuration object for mermaid. ### ~~mermaidAPI~~ -> **mermaidAPI**: `Readonly`<{ `defaultConfig`: [`MermaidConfig`](MermaidConfig.md); `getConfig`: () => [`MermaidConfig`](MermaidConfig.md); `getDiagramFromText`: (`text`, `metadata`) => `Promise`<`Diagram`>; `getSiteConfig`: () => [`MermaidConfig`](MermaidConfig.md); `globalReset`: () => `void`; `initialize`: (`userOptions`) => `void`; `parse`: (`text`, `parseOptions`) => `Promise`<`false` | [`ParseResult`](ParseResult.md)>(`text`, `parseOptions`?) => `Promise`<[`ParseResult`](ParseResult.md)>; `render`: (`id`, `text`, `svgContainingElement`?) => `Promise`<[`RenderResult`](RenderResult.md)>; `reset`: () => `void`; `setConfig`: (`conf`) => [`MermaidConfig`](MermaidConfig.md); `updateSiteConfig`: (`conf`) => [`MermaidConfig`](MermaidConfig.md); }> +> **mermaidAPI**: `Readonly`<{ `defaultConfig`: [`MermaidConfig`](MermaidConfig.md); `getConfig`: () => [`MermaidConfig`](MermaidConfig.md); `getDiagramFromText`: (`text`, `metadata`) => `Promise`<`Diagram`>; `getSiteConfig`: () => [`MermaidConfig`](MermaidConfig.md); `globalReset`: () => `void`; `initialize`: (`userOptions`) => `void`; `parse`: {(`text`, `parseOptions`): `Promise`<`false` | [`ParseResult`](ParseResult.md)>; (`text`, `parseOptions?`): `Promise`<[`ParseResult`](ParseResult.md)>; }; `render`: (`id`, `text`, `svgContainingElement?`) => `Promise`<[`RenderResult`](RenderResult.md)>; `reset`: () => `void`; `setConfig`: (`conf`) => [`MermaidConfig`](MermaidConfig.md); `updateSiteConfig`: (`conf`) => [`MermaidConfig`](MermaidConfig.md); }> Defined in: [packages/mermaid/src/mermaid.ts:436](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/mermaid.ts#L436) @@ -184,73 +184,81 @@ Defined in: [packages/mermaid/src/mermaid.ts:436](https://github.com/mermaid-js/ #### Deprecated -Use [parse](Mermaid.md#parse) and [render](Mermaid.md#render) instead. Please [open a discussion](https://github.com/mermaid-js/mermaid/discussions) if your use case does not fit the new API. +Use [parse](#parse) and [render](#render) instead. Please [open a discussion](https://github.com/mermaid-js/mermaid/discussions) if your use case does not fit the new API. --- ### parse() -> **parse**: (`text`, `parseOptions`) => `Promise`<`false` | [`ParseResult`](ParseResult.md)>(`text`, `parseOptions`?) => `Promise`<[`ParseResult`](ParseResult.md)> +> **parse**: {(`text`, `parseOptions`): `Promise`<`false` | [`ParseResult`](ParseResult.md)>; (`text`, `parseOptions?`): `Promise`<[`ParseResult`](ParseResult.md)>; } Defined in: [packages/mermaid/src/mermaid.ts:437](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/mermaid.ts#L437) +#### Call Signature + +> (`text`, `parseOptions`): `Promise`<`false` | [`ParseResult`](ParseResult.md)> + Parse the text and validate the syntax. -#### Parameters +##### Parameters -##### text +###### text `string` The mermaid diagram definition. -##### parseOptions +###### parseOptions [`ParseOptions`](ParseOptions.md) & `object` Options for parsing. -#### Returns +##### Returns `Promise`<`false` | [`ParseResult`](ParseResult.md)> An object with the `diagramType` set to type of the diagram if valid. Otherwise `false` if parseOptions.suppressErrors is `true`. -#### See +##### See [ParseOptions](ParseOptions.md) -#### Throws +##### Throws Error if the diagram is invalid and parseOptions.suppressErrors is false or not set. +#### Call Signature + +> (`text`, `parseOptions?`): `Promise`<[`ParseResult`](ParseResult.md)> + Parse the text and validate the syntax. -#### Parameters +##### Parameters -##### text +###### text `string` The mermaid diagram definition. -##### parseOptions? +###### parseOptions? [`ParseOptions`](ParseOptions.md) Options for parsing. -#### Returns +##### Returns `Promise`<[`ParseResult`](ParseResult.md)> An object with the `diagramType` set to type of the diagram if valid. Otherwise `false` if parseOptions.suppressErrors is `true`. -#### See +##### See [ParseOptions](ParseOptions.md) -#### Throws +##### Throws Error if the diagram is invalid and parseOptions.suppressErrors is false or not set. @@ -332,7 +340,7 @@ Defined in: [packages/mermaid/src/mermaid.ts:444](https://github.com/mermaid-js/ ### render() -> **render**: (`id`, `text`, `svgContainingElement`?) => `Promise`<[`RenderResult`](RenderResult.md)> +> **render**: (`id`, `text`, `svgContainingElement?`) => `Promise`<[`RenderResult`](RenderResult.md)> Defined in: [packages/mermaid/src/mermaid.ts:438](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/mermaid.ts#L438) diff --git a/docs/config/setup/mermaid/interfaces/MermaidConfig.md b/docs/config/setup/mermaid/interfaces/MermaidConfig.md index d08533713..f4c5b0b2b 100644 --- a/docs/config/setup/mermaid/interfaces/MermaidConfig.md +++ b/docs/config/setup/mermaid/interfaces/MermaidConfig.md @@ -18,7 +18,7 @@ Defined in: [packages/mermaid/src/config.type.ts:58](https://github.com/mermaid- > `optional` **altFontFamily**: `string` -Defined in: [packages/mermaid/src/config.type.ts:122](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/config.type.ts#L122) +Defined in: [packages/mermaid/src/config.type.ts:132](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/config.type.ts#L132) --- @@ -26,7 +26,7 @@ Defined in: [packages/mermaid/src/config.type.ts:122](https://github.com/mermaid > `optional` **architecture**: `ArchitectureDiagramConfig` -Defined in: [packages/mermaid/src/config.type.ts:194](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/config.type.ts#L194) +Defined in: [packages/mermaid/src/config.type.ts:204](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/config.type.ts#L204) --- @@ -34,7 +34,7 @@ Defined in: [packages/mermaid/src/config.type.ts:194](https://github.com/mermaid > `optional` **arrowMarkerAbsolute**: `boolean` -Defined in: [packages/mermaid/src/config.type.ts:141](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/config.type.ts#L141) +Defined in: [packages/mermaid/src/config.type.ts:151](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/config.type.ts#L151) Controls whether or arrow markers in html code are absolute paths or anchors. This matters if you are using base tag settings. @@ -45,7 +45,7 @@ This matters if you are using base tag settings. > `optional` **block**: `BlockDiagramConfig` -Defined in: [packages/mermaid/src/config.type.ts:201](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/config.type.ts#L201) +Defined in: [packages/mermaid/src/config.type.ts:211](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/config.type.ts#L211) --- @@ -53,7 +53,7 @@ Defined in: [packages/mermaid/src/config.type.ts:201](https://github.com/mermaid > `optional` **c4**: `C4DiagramConfig` -Defined in: [packages/mermaid/src/config.type.ts:198](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/config.type.ts#L198) +Defined in: [packages/mermaid/src/config.type.ts:208](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/config.type.ts#L208) --- @@ -61,7 +61,7 @@ Defined in: [packages/mermaid/src/config.type.ts:198](https://github.com/mermaid > `optional` **class**: `ClassDiagramConfig` -Defined in: [packages/mermaid/src/config.type.ts:187](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/config.type.ts#L187) +Defined in: [packages/mermaid/src/config.type.ts:197](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/config.type.ts#L197) --- @@ -69,7 +69,7 @@ Defined in: [packages/mermaid/src/config.type.ts:187](https://github.com/mermaid > `optional` **darkMode**: `boolean` -Defined in: [packages/mermaid/src/config.type.ts:113](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/config.type.ts#L113) +Defined in: [packages/mermaid/src/config.type.ts:123](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/config.type.ts#L123) --- @@ -77,7 +77,7 @@ Defined in: [packages/mermaid/src/config.type.ts:113](https://github.com/mermaid > `optional` **deterministicIds**: `boolean` -Defined in: [packages/mermaid/src/config.type.ts:174](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/config.type.ts#L174) +Defined in: [packages/mermaid/src/config.type.ts:184](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/config.type.ts#L184) This option controls if the generated ids of nodes in the SVG are generated randomly or based on a seed. @@ -93,7 +93,7 @@ should not change unless content is changed. > `optional` **deterministicIDSeed**: `string` -Defined in: [packages/mermaid/src/config.type.ts:181](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/config.type.ts#L181) +Defined in: [packages/mermaid/src/config.type.ts:191](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/config.type.ts#L191) This option is the optional seed for deterministic ids. If set to `undefined` but deterministicIds is `true`, a simple number iterator is used. @@ -105,7 +105,7 @@ You can set this attribute to base the seed on a static string. > `optional` **dompurifyConfig**: `Config` -Defined in: [packages/mermaid/src/config.type.ts:203](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/config.type.ts#L203) +Defined in: [packages/mermaid/src/config.type.ts:213](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/config.type.ts#L213) --- @@ -115,12 +115,24 @@ Defined in: [packages/mermaid/src/config.type.ts:203](https://github.com/mermaid Defined in: [packages/mermaid/src/config.type.ts:91](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/config.type.ts#L91) +#### considerModelOrder? + +> `optional` **considerModelOrder**: `"NONE"` | `"NODES_AND_EDGES"` | `"PREFER_EDGES"` | `"PREFER_NODES"` + +Preserves the order of nodes and edges in the model file if this does not lead to additional edge crossings. Depending on the strategy this is not always possible since the node and edge order might be conflicting. + #### cycleBreakingStrategy? > `optional` **cycleBreakingStrategy**: `"GREEDY"` | `"DEPTH_FIRST"` | `"INTERACTIVE"` | `"MODEL_ORDER"` | `"GREEDY_MODEL_ORDER"` This strategy decides how to find cycles in the graph and deciding which edges need adjustment to break loops. +#### forceNodeModelOrder? + +> `optional` **forceNodeModelOrder**: `boolean` + +The node order given by the model does not change to produce a better layout. E.g. if node A is before node B in the model this is not changed during crossing minimization. This assumes that the node model order is already respected before crossing minimization. This can be achieved by setting considerModelOrder.strategy to NODES_AND_EDGES. + #### mergeEdges? > `optional` **mergeEdges**: `boolean` @@ -139,7 +151,7 @@ Elk specific option affecting how nodes are placed. > `optional` **er**: `ErDiagramConfig` -Defined in: [packages/mermaid/src/config.type.ts:189](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/config.type.ts#L189) +Defined in: [packages/mermaid/src/config.type.ts:199](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/config.type.ts#L199) --- @@ -147,7 +159,7 @@ Defined in: [packages/mermaid/src/config.type.ts:189](https://github.com/mermaid > `optional` **flowchart**: `FlowchartDiagramConfig` -Defined in: [packages/mermaid/src/config.type.ts:182](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/config.type.ts#L182) +Defined in: [packages/mermaid/src/config.type.ts:192](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/config.type.ts#L192) --- @@ -155,7 +167,7 @@ Defined in: [packages/mermaid/src/config.type.ts:182](https://github.com/mermaid > `optional` **fontFamily**: `string` -Defined in: [packages/mermaid/src/config.type.ts:121](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/config.type.ts#L121) +Defined in: [packages/mermaid/src/config.type.ts:131](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/config.type.ts#L131) Specifies the font to be used in the rendered diagrams. Can be any possible CSS `font-family`. @@ -167,7 +179,7 @@ See > `optional` **fontSize**: `number` -Defined in: [packages/mermaid/src/config.type.ts:205](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/config.type.ts#L205) +Defined in: [packages/mermaid/src/config.type.ts:215](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/config.type.ts#L215) --- @@ -175,7 +187,7 @@ Defined in: [packages/mermaid/src/config.type.ts:205](https://github.com/mermaid > `optional` **forceLegacyMathML**: `boolean` -Defined in: [packages/mermaid/src/config.type.ts:163](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/config.type.ts#L163) +Defined in: [packages/mermaid/src/config.type.ts:173](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/config.type.ts#L173) This option forces Mermaid to rely on KaTeX's own stylesheet for rendering MathML. Due to differences between OS fonts and browser's MathML implementation, this option is recommended if consistent rendering is important. @@ -187,7 +199,7 @@ If set to true, ignores legacyMathML. > `optional` **gantt**: `GanttDiagramConfig` -Defined in: [packages/mermaid/src/config.type.ts:184](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/config.type.ts#L184) +Defined in: [packages/mermaid/src/config.type.ts:194](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/config.type.ts#L194) --- @@ -195,7 +207,7 @@ Defined in: [packages/mermaid/src/config.type.ts:184](https://github.com/mermaid > `optional` **gitGraph**: `GitGraphDiagramConfig` -Defined in: [packages/mermaid/src/config.type.ts:197](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/config.type.ts#L197) +Defined in: [packages/mermaid/src/config.type.ts:207](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/config.type.ts#L207) --- @@ -213,7 +225,7 @@ Defines the seed to be used when using handDrawn look. This is important for the > `optional` **htmlLabels**: `boolean` -Defined in: [packages/mermaid/src/config.type.ts:114](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/config.type.ts#L114) +Defined in: [packages/mermaid/src/config.type.ts:124](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/config.type.ts#L124) --- @@ -221,7 +233,7 @@ Defined in: [packages/mermaid/src/config.type.ts:114](https://github.com/mermaid > `optional` **journey**: `JourneyDiagramConfig` -Defined in: [packages/mermaid/src/config.type.ts:185](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/config.type.ts#L185) +Defined in: [packages/mermaid/src/config.type.ts:195](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/config.type.ts#L195) --- @@ -229,7 +241,7 @@ Defined in: [packages/mermaid/src/config.type.ts:185](https://github.com/mermaid > `optional` **kanban**: `KanbanDiagramConfig` -Defined in: [packages/mermaid/src/config.type.ts:196](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/config.type.ts#L196) +Defined in: [packages/mermaid/src/config.type.ts:206](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/config.type.ts#L206) --- @@ -247,7 +259,7 @@ Defines which layout algorithm to use for rendering the diagram. > `optional` **legacyMathML**: `boolean` -Defined in: [packages/mermaid/src/config.type.ts:156](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/config.type.ts#L156) +Defined in: [packages/mermaid/src/config.type.ts:166](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/config.type.ts#L166) This option specifies if Mermaid can expect the dependent to include KaTeX stylesheets for browsers without their own MathML implementation. If this option is disabled and MathML is not supported, the math @@ -260,7 +272,7 @@ fall back to legacy rendering for KaTeX. > `optional` **logLevel**: `0` | `2` | `1` | `"trace"` | `"debug"` | `"info"` | `"warn"` | `"error"` | `"fatal"` | `3` | `4` | `5` -Defined in: [packages/mermaid/src/config.type.ts:127](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/config.type.ts#L127) +Defined in: [packages/mermaid/src/config.type.ts:137](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/config.type.ts#L137) This option decides the amount of logging to be used by mermaid. @@ -280,7 +292,7 @@ Defines which main look to use for the diagram. > `optional` **markdownAutoWrap**: `boolean` -Defined in: [packages/mermaid/src/config.type.ts:206](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/config.type.ts#L206) +Defined in: [packages/mermaid/src/config.type.ts:216](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/config.type.ts#L216) --- @@ -308,7 +320,7 @@ The maximum allowed size of the users text diagram > `optional` **mindmap**: `MindmapDiagramConfig` -Defined in: [packages/mermaid/src/config.type.ts:195](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/config.type.ts#L195) +Defined in: [packages/mermaid/src/config.type.ts:205](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/config.type.ts#L205) --- @@ -316,7 +328,7 @@ Defined in: [packages/mermaid/src/config.type.ts:195](https://github.com/mermaid > `optional` **packet**: `PacketDiagramConfig` -Defined in: [packages/mermaid/src/config.type.ts:200](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/config.type.ts#L200) +Defined in: [packages/mermaid/src/config.type.ts:210](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/config.type.ts#L210) --- @@ -324,7 +336,7 @@ Defined in: [packages/mermaid/src/config.type.ts:200](https://github.com/mermaid > `optional` **pie**: `PieDiagramConfig` -Defined in: [packages/mermaid/src/config.type.ts:190](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/config.type.ts#L190) +Defined in: [packages/mermaid/src/config.type.ts:200](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/config.type.ts#L200) --- @@ -332,7 +344,7 @@ Defined in: [packages/mermaid/src/config.type.ts:190](https://github.com/mermaid > `optional` **quadrantChart**: `QuadrantChartConfig` -Defined in: [packages/mermaid/src/config.type.ts:191](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/config.type.ts#L191) +Defined in: [packages/mermaid/src/config.type.ts:201](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/config.type.ts#L201) --- @@ -340,7 +352,7 @@ Defined in: [packages/mermaid/src/config.type.ts:191](https://github.com/mermaid > `optional` **radar**: `RadarDiagramConfig` -Defined in: [packages/mermaid/src/config.type.ts:202](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/config.type.ts#L202) +Defined in: [packages/mermaid/src/config.type.ts:212](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/config.type.ts#L212) --- @@ -348,7 +360,7 @@ Defined in: [packages/mermaid/src/config.type.ts:202](https://github.com/mermaid > `optional` **requirement**: `RequirementDiagramConfig` -Defined in: [packages/mermaid/src/config.type.ts:193](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/config.type.ts#L193) +Defined in: [packages/mermaid/src/config.type.ts:203](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/config.type.ts#L203) --- @@ -356,7 +368,7 @@ Defined in: [packages/mermaid/src/config.type.ts:193](https://github.com/mermaid > `optional` **sankey**: `SankeyDiagramConfig` -Defined in: [packages/mermaid/src/config.type.ts:199](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/config.type.ts#L199) +Defined in: [packages/mermaid/src/config.type.ts:209](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/config.type.ts#L209) --- @@ -364,7 +376,7 @@ Defined in: [packages/mermaid/src/config.type.ts:199](https://github.com/mermaid > `optional` **secure**: `string`\[] -Defined in: [packages/mermaid/src/config.type.ts:148](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/config.type.ts#L148) +Defined in: [packages/mermaid/src/config.type.ts:158](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/config.type.ts#L158) This option controls which `currentConfig` keys are considered secure and can only be changed via call to `mermaid.initialize`. @@ -376,7 +388,7 @@ This prevents malicious graph directives from overriding a site's default securi > `optional` **securityLevel**: `"strict"` | `"loose"` | `"antiscript"` | `"sandbox"` -Defined in: [packages/mermaid/src/config.type.ts:131](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/config.type.ts#L131) +Defined in: [packages/mermaid/src/config.type.ts:141](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/config.type.ts#L141) Level of trust for parsed diagram @@ -386,7 +398,7 @@ Level of trust for parsed diagram > `optional` **sequence**: `SequenceDiagramConfig` -Defined in: [packages/mermaid/src/config.type.ts:183](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/config.type.ts#L183) +Defined in: [packages/mermaid/src/config.type.ts:193](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/config.type.ts#L193) --- @@ -394,7 +406,7 @@ Defined in: [packages/mermaid/src/config.type.ts:183](https://github.com/mermaid > `optional` **startOnLoad**: `boolean` -Defined in: [packages/mermaid/src/config.type.ts:135](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/config.type.ts#L135) +Defined in: [packages/mermaid/src/config.type.ts:145](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/config.type.ts#L145) Dictates whether mermaid starts on Page load @@ -404,7 +416,7 @@ Dictates whether mermaid starts on Page load > `optional` **state**: `StateDiagramConfig` -Defined in: [packages/mermaid/src/config.type.ts:188](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/config.type.ts#L188) +Defined in: [packages/mermaid/src/config.type.ts:198](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/config.type.ts#L198) --- @@ -412,7 +424,7 @@ Defined in: [packages/mermaid/src/config.type.ts:188](https://github.com/mermaid > `optional` **suppressErrorRendering**: `boolean` -Defined in: [packages/mermaid/src/config.type.ts:212](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/config.type.ts#L212) +Defined in: [packages/mermaid/src/config.type.ts:222](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/config.type.ts#L222) Suppresses inserting 'Syntax error' diagram in the DOM. This is useful when you want to control how to handle syntax errors in your application. @@ -450,7 +462,7 @@ Defined in: [packages/mermaid/src/config.type.ts:65](https://github.com/mermaid- > `optional` **timeline**: `TimelineDiagramConfig` -Defined in: [packages/mermaid/src/config.type.ts:186](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/config.type.ts#L186) +Defined in: [packages/mermaid/src/config.type.ts:196](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/config.type.ts#L196) --- @@ -458,7 +470,7 @@ Defined in: [packages/mermaid/src/config.type.ts:186](https://github.com/mermaid > `optional` **wrap**: `boolean` -Defined in: [packages/mermaid/src/config.type.ts:204](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/config.type.ts#L204) +Defined in: [packages/mermaid/src/config.type.ts:214](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/config.type.ts#L214) --- @@ -466,4 +478,4 @@ Defined in: [packages/mermaid/src/config.type.ts:204](https://github.com/mermaid > `optional` **xyChart**: `XYChartConfig` -Defined in: [packages/mermaid/src/config.type.ts:192](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/config.type.ts#L192) +Defined in: [packages/mermaid/src/config.type.ts:202](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/config.type.ts#L202) diff --git a/docs/config/setup/mermaid/interfaces/ParseOptions.md b/docs/config/setup/mermaid/interfaces/ParseOptions.md index e3a968378..628da0da0 100644 --- a/docs/config/setup/mermaid/interfaces/ParseOptions.md +++ b/docs/config/setup/mermaid/interfaces/ParseOptions.md @@ -10,7 +10,7 @@ # Interface: ParseOptions -Defined in: [packages/mermaid/src/types.ts:59](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/types.ts#L59) +Defined in: [packages/mermaid/src/types.ts:88](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/types.ts#L88) ## Properties @@ -18,7 +18,7 @@ Defined in: [packages/mermaid/src/types.ts:59](https://github.com/mermaid-js/mer > `optional` **suppressErrors**: `boolean` -Defined in: [packages/mermaid/src/types.ts:64](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/types.ts#L64) +Defined in: [packages/mermaid/src/types.ts:93](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/types.ts#L93) If `true`, parse will return `false` instead of throwing error when the diagram is invalid. The `parseError` function will not be called. diff --git a/docs/config/setup/mermaid/interfaces/ParseResult.md b/docs/config/setup/mermaid/interfaces/ParseResult.md index 95d662b42..0e200aa95 100644 --- a/docs/config/setup/mermaid/interfaces/ParseResult.md +++ b/docs/config/setup/mermaid/interfaces/ParseResult.md @@ -10,7 +10,7 @@ # Interface: ParseResult -Defined in: [packages/mermaid/src/types.ts:67](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/types.ts#L67) +Defined in: [packages/mermaid/src/types.ts:96](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/types.ts#L96) ## Properties @@ -18,7 +18,7 @@ Defined in: [packages/mermaid/src/types.ts:67](https://github.com/mermaid-js/mer > **config**: [`MermaidConfig`](MermaidConfig.md) -Defined in: [packages/mermaid/src/types.ts:75](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/types.ts#L75) +Defined in: [packages/mermaid/src/types.ts:104](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/types.ts#L104) The config passed as YAML frontmatter or directives @@ -28,6 +28,6 @@ The config passed as YAML frontmatter or directives > **diagramType**: `string` -Defined in: [packages/mermaid/src/types.ts:71](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/types.ts#L71) +Defined in: [packages/mermaid/src/types.ts:100](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/types.ts#L100) The diagram type, e.g. 'flowchart', 'sequence', etc. diff --git a/docs/config/setup/mermaid/interfaces/RenderResult.md b/docs/config/setup/mermaid/interfaces/RenderResult.md index c6dc3cf08..237c51de2 100644 --- a/docs/config/setup/mermaid/interfaces/RenderResult.md +++ b/docs/config/setup/mermaid/interfaces/RenderResult.md @@ -10,7 +10,7 @@ # Interface: RenderResult -Defined in: [packages/mermaid/src/types.ts:85](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/types.ts#L85) +Defined in: [packages/mermaid/src/types.ts:114](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/types.ts#L114) ## Properties @@ -18,7 +18,7 @@ Defined in: [packages/mermaid/src/types.ts:85](https://github.com/mermaid-js/mer > `optional` **bindFunctions**: (`element`) => `void` -Defined in: [packages/mermaid/src/types.ts:103](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/types.ts#L103) +Defined in: [packages/mermaid/src/types.ts:132](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/types.ts#L132) Bind function to be called after the svg has been inserted into the DOM. This is necessary for adding event listeners to the elements in the svg. @@ -45,7 +45,7 @@ bindFunctions?.(div); // To call bindFunctions only if it's present. > **diagramType**: `string` -Defined in: [packages/mermaid/src/types.ts:93](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/types.ts#L93) +Defined in: [packages/mermaid/src/types.ts:122](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/types.ts#L122) The diagram type, e.g. 'flowchart', 'sequence', etc. @@ -55,6 +55,6 @@ The diagram type, e.g. 'flowchart', 'sequence', etc. > **svg**: `string` -Defined in: [packages/mermaid/src/types.ts:89](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/types.ts#L89) +Defined in: [packages/mermaid/src/types.ts:118](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/types.ts#L118) The svg code for the rendered graph. diff --git a/docs/config/setup/mermaid/interfaces/UnknownDiagramError.md b/docs/config/setup/mermaid/interfaces/UnknownDiagramError.md new file mode 100644 index 000000000..2415d77ee --- /dev/null +++ b/docs/config/setup/mermaid/interfaces/UnknownDiagramError.md @@ -0,0 +1,65 @@ +> **Warning** +> +> ## THIS IS AN AUTOGENERATED FILE. DO NOT EDIT. +> +> ## Please edit the corresponding file in [/packages/mermaid/src/docs/config/setup/mermaid/interfaces/UnknownDiagramError.md](../../../../../packages/mermaid/src/docs/config/setup/mermaid/interfaces/UnknownDiagramError.md). + +[**mermaid**](../../README.md) + +--- + +# Interface: UnknownDiagramError + +Defined in: [packages/mermaid/src/errors.ts:1](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/errors.ts#L1) + +## Extends + +- `Error` + +## Properties + +### cause? + +> `optional` **cause**: `unknown` + +Defined in: node_modules/.pnpm/typescript\@5.7.3/node_modules/typescript/lib/lib.es2022.error.d.ts:26 + +#### Inherited from + +`Error.cause` + +--- + +### message + +> **message**: `string` + +Defined in: node_modules/.pnpm/typescript\@5.7.3/node_modules/typescript/lib/lib.es5.d.ts:1077 + +#### Inherited from + +`Error.message` + +--- + +### name + +> **name**: `string` + +Defined in: node_modules/.pnpm/typescript\@5.7.3/node_modules/typescript/lib/lib.es5.d.ts:1076 + +#### Inherited from + +`Error.name` + +--- + +### stack? + +> `optional` **stack**: `string` + +Defined in: node_modules/.pnpm/typescript\@5.7.3/node_modules/typescript/lib/lib.es5.d.ts:1078 + +#### Inherited from + +`Error.stack` diff --git a/docs/config/setup/mermaid/type-aliases/InternalHelpers.md b/docs/config/setup/mermaid/type-aliases/InternalHelpers.md index 6baf786fe..bfaeabd12 100644 --- a/docs/config/setup/mermaid/type-aliases/InternalHelpers.md +++ b/docs/config/setup/mermaid/type-aliases/InternalHelpers.md @@ -10,6 +10,6 @@ # Type Alias: InternalHelpers -> **InternalHelpers**: _typeof_ `internalHelpers` +> **InternalHelpers** = _typeof_ `internalHelpers` Defined in: [packages/mermaid/src/internals.ts:33](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/internals.ts#L33) diff --git a/docs/config/setup/mermaid/type-aliases/ParseErrorFunction.md b/docs/config/setup/mermaid/type-aliases/ParseErrorFunction.md index 78f27854c..dd5938478 100644 --- a/docs/config/setup/mermaid/type-aliases/ParseErrorFunction.md +++ b/docs/config/setup/mermaid/type-aliases/ParseErrorFunction.md @@ -10,7 +10,7 @@ # Type Alias: ParseErrorFunction() -> **ParseErrorFunction**: (`err`, `hash`?) => `void` +> **ParseErrorFunction** = (`err`, `hash?`) => `void` Defined in: [packages/mermaid/src/Diagram.ts:10](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/Diagram.ts#L10) diff --git a/docs/config/setup/mermaid/type-aliases/SVG.md b/docs/config/setup/mermaid/type-aliases/SVG.md index 8bfb7bda0..184f3e2cd 100644 --- a/docs/config/setup/mermaid/type-aliases/SVG.md +++ b/docs/config/setup/mermaid/type-aliases/SVG.md @@ -10,6 +10,6 @@ # Type Alias: SVG -> **SVG**: `d3.Selection`<`SVGSVGElement`, `unknown`, `Element` | `null`, `unknown`> +> **SVG** = `d3.Selection`<`SVGSVGElement`, `unknown`, `Element` | `null`, `unknown`> Defined in: [packages/mermaid/src/diagram-api/types.ts:126](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/diagram-api/types.ts#L126) diff --git a/docs/config/setup/mermaid/type-aliases/SVGGroup.md b/docs/config/setup/mermaid/type-aliases/SVGGroup.md index 5e53052fd..8d673aafb 100644 --- a/docs/config/setup/mermaid/type-aliases/SVGGroup.md +++ b/docs/config/setup/mermaid/type-aliases/SVGGroup.md @@ -10,6 +10,6 @@ # Type Alias: SVGGroup -> **SVGGroup**: `d3.Selection`<`SVGGElement`, `unknown`, `Element` | `null`, `unknown`> +> **SVGGroup** = `d3.Selection`<`SVGGElement`, `unknown`, `Element` | `null`, `unknown`> Defined in: [packages/mermaid/src/diagram-api/types.ts:128](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/diagram-api/types.ts#L128) diff --git a/docs/config/tidy-tree.md b/docs/config/tidy-tree.md new file mode 100644 index 000000000..1d4227596 --- /dev/null +++ b/docs/config/tidy-tree.md @@ -0,0 +1,89 @@ +> **Warning** +> +> ## THIS IS AN AUTOGENERATED FILE. DO NOT EDIT. +> +> ## Please edit the corresponding file in [/packages/mermaid/src/docs/config/tidy-tree.md](../../packages/mermaid/src/docs/config/tidy-tree.md). + +# Tidy-tree Layout + +The **tidy-tree** layout arranges nodes in a hierarchical, tree-like structure. It is especially useful for diagrams where parent-child relationships are important, such as mindmaps. + +## Features + +- Organizes nodes in a tidy, non-overlapping tree +- Ideal for mindmaps and hierarchical data +- Automatically adjusts spacing for readability + +## Example Usage + +```mermaid-example +--- +config: + layout: tidy-tree +--- +mindmap +root((mindmap is a long thing)) + A + B + C + D +``` + +```mermaid +--- +config: + layout: tidy-tree +--- +mindmap +root((mindmap is a long thing)) + A + B + C + D +``` + +```mermaid-example +--- +config: + layout: tidy-tree +--- +mindmap +root((mindmap)) + Origins + Long history + ::icon(fa fa-book) + Popularisation + British popular psychology author Tony Buzan + Research + On effectiveness
and features + On Automatic creation + Uses + Creative techniques + Strategic planning + Argument mapping +``` + +```mermaid +--- +config: + layout: tidy-tree +--- +mindmap +root((mindmap)) + Origins + Long history + ::icon(fa fa-book) + Popularisation + British popular psychology author Tony Buzan + Research + On effectiveness
and features + On Automatic creation + Uses + Creative techniques + Strategic planning + Argument mapping +``` + +## Note + +- Currently, tidy-tree is primarily supported for mindmap diagrams. diff --git a/docs/diagrams/flowchart-code-flow.mmd b/docs/diagrams/flowchart-code-flow.mmd new file mode 100644 index 000000000..d306dac7b --- /dev/null +++ b/docs/diagrams/flowchart-code-flow.mmd @@ -0,0 +1,189 @@ +--- +references: + - "File: /packages/mermaid/src/diagrams/flowchart/flowDiagram.ts" + - "File: /packages/mermaid/src/diagrams/flowchart/flowDb.ts" + - "File: /packages/mermaid/src/diagrams/flowchart/flowDetector.ts" + - "File: /packages/mermaid/src/diagrams/flowchart/flowDetector-v2.ts" + - "File: /packages/mermaid/src/diagrams/flowchart/flowRenderer-v3-unified.ts" + - "File: /packages/mermaid/src/diagrams/flowchart/styles.ts" + - "File: /packages/mermaid/src/diagrams/flowchart/types.ts" + - "File: /packages/mermaid/src/diagrams/flowchart/flowChartShapes.js" + - "File: /packages/mermaid/src/diagrams/flowchart/parser/flowParser.ts" + - "File: /packages/mermaid/src/diagrams/flowchart/elk/detector.ts" +generationTime: 2025-07-23T10:31:53.266Z +--- +flowchart TD + %% Entry Points and Detection + Input["User Input Text"] --> Detection{Detection Phase} + + Detection --> flowDetector["flowDetector.ts
detector(txt, config)"] + Detection --> flowDetectorV2["flowDetector-v2.ts
detector(txt, config)"] + Detection --> elkDetector["elk/detector.ts
detector(txt, config)"] + + flowDetector --> |"Checks /^\s*graph/"| DetectLegacy{Legacy Flowchart?} + flowDetectorV2 --> |"Checks /^\s*flowchart/"| DetectNew{New Flowchart?} + elkDetector --> |"Checks /^\s*flowchart-elk/"| DetectElk{ELK Layout?} + + DetectLegacy --> |Yes| LoadDiagram + DetectNew --> |Yes| LoadDiagram + DetectElk --> |Yes| LoadDiagram + + %% Loading Phase + LoadDiagram["loader() function"] --> flowDiagram["flowDiagram.ts
diagram object"] + + flowDiagram --> DiagramStructure{Diagram Components} + DiagramStructure --> Parser["parser: flowParser"] + DiagramStructure --> Database["db: new FlowDB()"] + DiagramStructure --> Renderer["renderer: flowRenderer-v3-unified"] + DiagramStructure --> Styles["styles: flowStyles"] + DiagramStructure --> Init["init: (cnf: MermaidConfig)"] + + %% Parser Phase + Parser --> flowParser["parser/flowParser.ts
newParser.parse(src)"] + flowParser --> |"Preprocesses src"| RemoveWhitespace["Remove trailing whitespace
src.replace(/}\s*\n/g, '}\n')"] + RemoveWhitespace --> flowJison["parser/flow.jison
flowJisonParser.parse(newSrc)"] + + flowJison --> ParseGraph["Parse Graph Structure"] + ParseGraph --> ParseVertices["Parse Vertices"] + ParseGraph --> ParseEdges["Parse Edges"] + ParseGraph --> ParseSubgraphs["Parse Subgraphs"] + ParseGraph --> ParseClasses["Parse Classes"] + ParseGraph --> ParseStyles["Parse Styles"] + + %% Database Phase - FlowDB Class + Database --> FlowDBClass["flowDb.ts
FlowDB class"] + + FlowDBClass --> DBInit["constructor()
- Initialize counters
- Bind methods
- Setup toolTips
- Call clear()"] + + DBInit --> DBMethods{FlowDB Methods} + + DBMethods --> addVertex["addVertex(id, textObj, type, style,
classes, dir, props, metadata)"] + DBMethods --> addLink["addLink(_start[], _end[], linkData)"] + DBMethods --> addSingleLink["addSingleLink(_start, _end, type, id)"] + DBMethods --> setDirection["setDirection(dir)"] + DBMethods --> addSubGraph["addSubGraph(nodes[], id, title)"] + DBMethods --> addClass["addClass(id, style)"] + DBMethods --> setClass["setClass(ids, className)"] + DBMethods --> setTooltip["setTooltip(ids, tooltip)"] + DBMethods --> setClickEvent["setClickEvent(id, functionName, args)"] + DBMethods --> setClickFun["setClickFun(id, functionName, args)"] + + %% Vertex Processing + addVertex --> VertexProcess{Vertex Processing} + VertexProcess --> CreateVertex["Create FlowVertex object
- id, labelType, domId
- styles[], classes[]"] + VertexProcess --> SanitizeText["sanitizeText(textObj.text)"] + VertexProcess --> ParseMetadata["Parse YAML metadata
yaml.load(yamlData)"] + VertexProcess --> SetVertexProps["Set vertex properties
- shape, label, icon, form
- pos, img, constraint, w, h"] + + %% Edge Processing + addSingleLink --> EdgeProcess{Edge Processing} + EdgeProcess --> CreateEdge["Create FlowEdge object
- start, end, type, text
- labelType, classes[]"] + EdgeProcess --> ProcessLinkText["Process link text
- sanitizeText()
- strip quotes"] + EdgeProcess --> SetEdgeProps["Set edge properties
- type, stroke, length"] + EdgeProcess --> GenerateEdgeId["Generate edge ID
getEdgeId(start, end, counter)"] + EdgeProcess --> ValidateEdgeLimit["Validate edge limit
maxEdges check"] + + %% Data Collection + DBMethods --> GetData["getData()"] + GetData --> CollectNodes["Collect nodes[] from vertices"] + GetData --> CollectEdges["Collect edges[] from edges"] + GetData --> ProcessSubGraphs["Process subgraphs
- parentDB Map
- subGraphDB Map"] + GetData --> AddNodeFromVertex["addNodeFromVertex()
for each vertex"] + GetData --> ProcessEdgeTypes["destructEdgeType()
arrowTypeStart, arrowTypeEnd"] + + %% Node Creation + AddNodeFromVertex --> NodeCreation{Node Creation} + NodeCreation --> FindExistingNode["findNode(nodes, vertex.id)"] + NodeCreation --> CreateBaseNode["Create base node
- id, label, parentId
- cssStyles, cssClasses
- shape, domId, tooltip"] + NodeCreation --> GetCompiledStyles["getCompiledStyles(classDefs)"] + NodeCreation --> GetTypeFromVertex["getTypeFromVertex(vertex)"] + + %% Rendering Phase + Renderer --> flowRendererV3["flowRenderer-v3-unified.ts
draw(text, id, version, diag)"] + + flowRendererV3 --> RenderInit["Initialize rendering
- getConfig()
- handle securityLevel
- getDiagramElement()"] + + RenderInit --> GetLayoutData["diag.db.getData()
as LayoutData"] + GetLayoutData --> SetupLayoutData["Setup layout data
- type, layoutAlgorithm
- direction, spacing
- markers, diagramId"] + + SetupLayoutData --> CallRender["render(data4Layout, svg)"] + CallRender --> SetupViewPort["setupViewPortForSVG(svg, padding)"] + SetupViewPort --> ProcessLinks["Process vertex links
- create anchor elements
- handle click events"] + + %% Shape Rendering + CallRender --> ShapeSystem["flowChartShapes.js
Shape Functions"] + + ShapeSystem --> ShapeFunctions{Shape Functions} + ShapeFunctions --> question["question(parent, bbox, node)"] + ShapeFunctions --> hexagon["hexagon(parent, bbox, node)"] + ShapeFunctions --> rect_left_inv_arrow["rect_left_inv_arrow(parent, bbox, node)"] + ShapeFunctions --> lean_right["lean_right(parent, bbox, node)"] + ShapeFunctions --> lean_left["lean_left(parent, bbox, node)"] + + ShapeFunctions --> insertPolygonShape["insertPolygonShape(parent, w, h, points)"] + ShapeFunctions --> intersectPolygon["intersectPolygon(node, points, point)"] + ShapeFunctions --> intersectRect["intersectRect(node, point)"] + + %% Styling System + Styles --> stylesTS["styles.ts
getStyles(options)"] + stylesTS --> StyleOptions["FlowChartStyleOptions
- arrowheadColor, border2
- clusterBkg, mainBkg
- fontFamily, textColor"] + + StyleOptions --> GenerateCSS["Generate CSS styles
- .label, .cluster-label
- .node, .edgePath
- .flowchart-link, .edgeLabel"] + GenerateCSS --> GetIconStyles["getIconStyles()"] + + %% Type System + Parser --> TypeSystem["types.ts
Type Definitions"] + TypeSystem --> FlowVertex["FlowVertex interface"] + TypeSystem --> FlowEdge["FlowEdge interface"] + TypeSystem --> FlowClass["FlowClass interface"] + TypeSystem --> FlowSubGraph["FlowSubGraph interface"] + TypeSystem --> FlowVertexTypeParam["FlowVertexTypeParam
Shape types"] + + %% Utility Functions + DBMethods --> UtilityFunctions{Utility Functions} + UtilityFunctions --> lookUpDomId["lookUpDomId(id)"] + UtilityFunctions --> getClasses["getClasses()"] + UtilityFunctions --> getDirection["getDirection()"] + UtilityFunctions --> getVertices["getVertices()"] + UtilityFunctions --> getEdges["getEdges()"] + UtilityFunctions --> getSubGraphs["getSubGraphs()"] + UtilityFunctions --> clear["clear()"] + UtilityFunctions --> defaultConfig["defaultConfig()"] + + %% Event Handling + ProcessLinks --> EventHandling{Event Handling} + EventHandling --> setupToolTips["setupToolTips(element)"] + EventHandling --> bindFunctions["bindFunctions(element)"] + EventHandling --> runFunc["utils.runFunc(functionName, args)"] + + %% Common Database Functions + DBMethods --> CommonDB["commonDb.js functions"] + CommonDB --> setAccTitle["setAccTitle()"] + CommonDB --> getAccTitle["getAccTitle()"] + CommonDB --> setAccDescription["setAccDescription()"] + CommonDB --> getAccDescription["getAccDescription()"] + CommonDB --> setDiagramTitle["setDiagramTitle()"] + CommonDB --> getDiagramTitle["getDiagramTitle()"] + CommonDB --> commonClear["clear()"] + + %% Final Output + ProcessLinks --> FinalSVG["Final SVG Output"] + + %% Layout Algorithm Selection + SetupLayoutData --> LayoutAlgorithm{Layout Algorithm} + LayoutAlgorithm --> Dagre["dagre
(default)"] + LayoutAlgorithm --> DagreWrapper["dagre-wrapper
(v2 renderer)"] + LayoutAlgorithm --> ELK["elk
(external package)"] + + %% Testing Components + FlowDBClass --> TestFiles["Test Files"] + TestFiles --> flowDbSpec["flowDb.spec.ts"] + TestFiles --> flowChartShapesSpec["flowChartShapes.spec.js"] + TestFiles --> ParserTests["parser/*.spec.js files
- flow-text.spec.js
- flow-edges.spec.js
- flow-style.spec.js
- subgraph.spec.js"] + + %% Configuration + Init --> ConfigSetup["Configuration Setup"] + ConfigSetup --> FlowchartConfig["cnf.flowchart config"] + ConfigSetup --> ArrowMarkers["arrowMarkerAbsolute"] + ConfigSetup --> LayoutConfig["layout config"] + ConfigSetup --> SetConfig["setConfig() calls"] \ No newline at end of file diff --git a/docs/diagrams/mermaid-api-sequence.mmd b/docs/diagrams/mermaid-api-sequence.mmd new file mode 100644 index 000000000..ce7597525 --- /dev/null +++ b/docs/diagrams/mermaid-api-sequence.mmd @@ -0,0 +1,307 @@ +--- +references: + - "File: /packages/mermaid/src/mermaidAPI.ts" + - "File: /packages/mermaid/src/mermaid.ts" +generationTime: 2025-01-28T16:30:00.000Z +--- +sequenceDiagram + participant User as User/Browser + participant Mermaid as mermaid.ts + participant Queue as executionQueue + participant API as mermaidAPI.ts + participant Config as configApi + participant Preprocessor as preprocessDiagram + participant DiagramAPI as diagram-api + participant Diagram as Diagram.fromText + participant Renderer as diagram.renderer + participant Styles as Styling System + participant DOM as DOM/SVG + + Note over User, DOM: Mermaid Complete API Flow + + %% Initialization Phase + User->>+Mermaid: mermaid.initialize(config) + Mermaid->>+API: mermaidAPI.initialize(config) + + API->>API: assignWithDepth({}, userOptions) + API->>API: handle legacy fontFamily config + API->>Config: saveConfigFromInitialize(options) + + alt Theme Configuration Available + API->>API: check if theme in theme object + API->>API: set themeVariables from theme + else Default Theme + API->>API: use default theme variables + end + + API->>Config: setSiteConfig(options) or getSiteConfig() + API->>API: setLogLevel(config.logLevel) + API->>DiagramAPI: addDiagrams() + + API-->>-Mermaid: initialization complete + Mermaid-->>-User: ready to render + + %% Content Loaded Event + User->>DOM: document.load event + DOM->>+Mermaid: contentLoaded() + + opt startOnLoad is true + Mermaid->>Config: getConfig() + Config-->>Mermaid: { startOnLoad: true } + Mermaid->>Mermaid: run() + end + + Mermaid-->>-DOM: event handling complete + + %% Main Run Function + User->>+Mermaid: mermaid.run(options) + + Mermaid->>Mermaid: runThrowsErrors(options) + Mermaid->>Config: getConfig() + Config-->>Mermaid: configuration object + + alt nodes provided + Mermaid->>Mermaid: use provided nodes + else querySelector provided + Mermaid->>DOM: document.querySelectorAll(querySelector) + DOM-->>Mermaid: nodesToProcess + end + + Mermaid->>Mermaid: new InitIDGenerator(deterministicIds, seed) + + loop For each diagram element + Mermaid->>DOM: check element.getAttribute('data-processed') + + opt not processed + Mermaid->>DOM: element.setAttribute('data-processed', 'true') + Mermaid->>Mermaid: generate unique id + Mermaid->>DOM: get element.innerHTML + Mermaid->>Mermaid: entityDecode and clean text + Mermaid->>Mermaid: detectInit(txt) + + Mermaid->>Queue: render(id, txt, element) + end + end + + Mermaid-->>-User: processing initiated + + %% Render Function (Queued) + activate Queue + Queue->>+API: mermaidAPI.render(id, text, container) + + API->>DiagramAPI: addDiagrams() + API->>+Preprocessor: processAndSetConfigs(text) + + Preprocessor->>Preprocessor: preprocessDiagram(text) + Preprocessor->>Config: reset() + Preprocessor->>Config: addDirective(processed.config) + Preprocessor-->>-API: { code, config } + + API->>Config: getConfig() + Config-->>API: current configuration + + opt text length > maxTextSize + API->>API: text = MAX_TEXTLENGTH_EXCEEDED_MSG + end + + API->>API: setup id selectors and element IDs + API->>API: determine security level (sandbox/loose) + + %% DOM Setup + alt svgContainingElement provided + alt isSandboxed + API->>DOM: sandboxedIframe(select(svgContainingElement), iFrameID) + API->>DOM: select iframe contentDocument body + else + API->>DOM: select(svgContainingElement) + end + else no container + API->>API: removeExistingElements(document, id, divId, iFrameId) + alt isSandboxed + API->>DOM: sandboxedIframe(select('body'), iFrameID) + else + API->>DOM: select('body') + end + end + + API->>DOM: appendDivSvgG(root, id, enclosingDivID, fontFamily, XMLNS_XLINK_STD) + + %% Diagram Creation + API->>+Diagram: Diagram.fromText(text, { title: processed.title }) + + Diagram->>DiagramAPI: detect diagram type + Diagram->>DiagramAPI: load appropriate diagram + Diagram-->>-API: diagram instance + + opt parsing error occurred + API->>+Diagram: Diagram.fromText('error') + Diagram-->>-API: error diagram + API->>API: store parseEncounteredException + end + + %% Style Generation + API->>DOM: get svg element and firstChild + API->>Renderer: diag.renderer.getClasses(text, diag) + Renderer-->>API: diagramClassDefs + + API->>+Styles: createUserStyles(config, diagramType, diagramClassDefs, idSelector) + + Styles->>Styles: createCssStyles(config, classDefs) + + opt config.themeCSS defined + Styles->>Styles: append themeCSS + end + + opt fontFamily configured + Styles->>Styles: add CSS variables for fonts + end + + opt classDefs exist + loop For each styleClassDef + opt has styles + Styles->>Styles: cssImportantStyles for each CSS element + end + opt has textStyles + Styles->>Styles: cssImportantStyles for tspan elements + end + end + end + + Styles->>Styles: getStyles(graphType, userCSSstyles, themeVariables) + Styles->>Styles: serialize(compile(svgId{allStyles}), stringify) + Styles-->>-API: compiled CSS rules + + API->>DOM: create style element + API->>DOM: style.innerHTML = rules + API->>DOM: svg.insertBefore(style, firstChild) + + %% Diagram Rendering + API->>+Renderer: diag.renderer.draw(text, id, version, diag) + + Renderer->>Renderer: diagram-specific rendering logic + Renderer->>DOM: create SVG elements + Renderer->>DOM: apply positioning and styling + Renderer-->>-API: rendered diagram + + opt rendering error + alt suppressErrorRendering + API->>API: removeTempElements() + API->>Mermaid: throw error + else + API->>Renderer: errorRenderer.draw(text, id, version) + end + end + + %% Accessibility and Cleanup + API->>DOM: select svg element + API->>Diagram: diag.db.getAccTitle() + API->>Diagram: diag.db.getAccDescription() + API->>API: addA11yInfo(diagramType, svgNode, a11yTitle, a11yDescr) + + API->>DOM: set xmlns for foreignobject elements + API->>DOM: get innerHTML from enclosing div + + API->>+API: cleanUpSvgCode(svgCode, isSandboxed, arrowMarkerAbsolute) + + opt not useArrowMarkerUrls and not sandboxed + API->>API: replace marker-end URLs with anchors + end + + API->>API: decodeEntities(svgCode) + API->>API: replace
with
+ API-->>-API: cleaned SVG code + + alt isSandboxed + API->>+API: putIntoIFrame(svgCode, svgEl) + API->>API: calculate iframe height + API->>API: toBase64 encode SVG content + API->>API: create iframe with sandbox attributes + API-->>-API: iframe HTML + else not loose security + API->>API: DOMPurify.sanitize(svgCode, options) + end + + API->>API: attachFunctions() + API->>API: removeTempElements() + + opt parseEncounteredException + API->>Mermaid: throw parseEncounteredException + end + + API-->>-Queue: { diagramType, svg: svgCode, bindFunctions } + + %% Return to Web Integration + activate Mermaid + Queue-->>Mermaid: render result + Mermaid->>DOM: element.innerHTML = svg + + opt postRenderCallback + Mermaid->>User: postRenderCallback(id) + end + + opt bindFunctions exist + Mermaid->>DOM: bindFunctions(element) + end + deactivate Mermaid + + %% Parse Function Flow + User->>+Mermaid: mermaid.parse(text, parseOptions) + activate Queue + + Queue->>+API: mermaidAPI.parse(text, parseOptions) + + API->>DiagramAPI: addDiagrams() + API->>Preprocessor: processAndSetConfigs(text) + Preprocessor-->>API: { code, config } + API->>Diagram: getDiagramFromText(code) + Diagram-->>API: diagram instance + API-->>-Queue: { diagramType: diagram.type, config } + + Queue-->>-Mermaid: parse result + Mermaid-->>-User: ParseResult or false + + %% External Diagram Registration + User->>+Mermaid: registerExternalDiagrams(diagrams, options) + + Mermaid->>DiagramAPI: addDiagrams() + Mermaid->>DiagramAPI: registerLazyLoadedDiagrams(...diagrams) + + opt lazyLoad is false + Mermaid->>DiagramAPI: loadRegisteredDiagrams() + end + + Mermaid-->>-User: registration complete + + %% Error Handling + Note over Mermaid, API: Error Handling Throughout + alt Error occurs + API->>Mermaid: throw error + Mermaid->>+Mermaid: handleError(error, errors, parseError) + + Mermaid->>Mermaid: log.warn(error) + + alt isDetailedError + Mermaid->>User: parseError(error.str, error.hash) + else + Mermaid->>User: parseError(error) + end + + opt not suppressErrors + Mermaid->>User: throw error + end + + Mermaid-->>-User: error handled + end + + %% Configuration Details + Note over Config: Configuration Functions + Note right of Config: Functions:
- reset()
- getConfig()
- setConfig()
- getSiteConfig()
- updateSiteConfig()
- saveConfigFromInitialize() + + Note over Styles: CSS Generation + Note right of Styles: Features:
- createCssStyles()
- createUserStyles()
- cssImportantStyles()
- Theme integration
- Class definitions + + Note over API: Security Levels + Note right of API: Modes:
- sandbox: iframe isolation
- loose: minimal sanitization
- default: DOMPurify sanitization + + Note over API: Helper Functions + Note right of API: Utilities:
- cleanUpSvgCode()
- putIntoIFrame()
- appendDivSvgG()
- removeExistingElements() \ No newline at end of file diff --git a/docs/diagrams/mindmap-implementation-sequence.mmd b/docs/diagrams/mindmap-implementation-sequence.mmd new file mode 100644 index 000000000..335855380 --- /dev/null +++ b/docs/diagrams/mindmap-implementation-sequence.mmd @@ -0,0 +1,180 @@ +--- +references: + - "File: /packages/mermaid/src/diagrams/mindmap/mindmap-definition.ts" + - "File: /packages/mermaid/src/diagrams/mindmap/mindmapDb.ts" + - "File: /packages/mermaid/src/diagrams/mindmap/detector.ts" + - "File: /packages/mermaid/src/diagrams/mindmap/mindmapTypes.ts" + - "File: /packages/mermaid/src/diagrams/mindmap/mindmapRenderer.ts" + - "File: /packages/mermaid/src/diagrams/mindmap/styles.ts" + - "File: /packages/mermaid/src/diagrams/mindmap/svgDraw.ts" +generationTime: 2025-01-28T16:00:00.000Z +--- +sequenceDiagram + participant User as User Input Text + participant Detector as detector.ts + participant Loader as DiagramLoader + participant Definition as mindmap-definition.ts + participant Parser as parser/mindmap.jison + participant DB as MindmapDB + participant Renderer as mindmapRenderer.ts + participant Cytoscape as cytoscape.js + participant SVGDraw as svgDraw.ts + participant Styles as styles.ts + participant Output as Final SVG + + Note over User, Output: Mindmap Implementation Flow + + %% Detection Phase + User->>Detector: /^\s*mindmap/ text input + activate Detector + Detector->>Detector: detector(txt) validates pattern + Detector->>Loader: loader() function called + deactivate Detector + + activate Loader + Loader->>Definition: import mindmap-definition.js + deactivate Loader + + %% Core Structure Setup + activate Definition + Definition->>DB: get db() → new MindmapDB() + Definition->>Renderer: setup renderer + Definition->>Parser: setup parser + Definition->>Styles: setup styles + deactivate Definition + + %% Database Initialization + activate DB + Note over DB: MindmapDB Constructor + DB->>DB: initialize nodes array + DB->>DB: setup nodeType constants + DB->>DB: bind methods + DB->>DB: clear() state + + %% Parsing Phase + activate Parser + User->>Parser: mindmap syntax text + + loop For each node in hierarchy + Parser->>DB: addNode(level, id, descr, type) + activate DB + DB->>DB: sanitizeText(id, descr) + DB->>DB: getType(startStr, endStr) + Note right of DB: Shape Detection:
[ → RECT
( → ROUNDED_RECT
(( → CIRCLE
)) → BANG
{{ → HEXAGON + DB->>DB: getParent(level) + DB->>DB: create MindmapNode + DB->>DB: add to hierarchy + deactivate DB + end + + opt Icon/Class Decoration + Parser->>DB: decorateNode(decoration) + DB->>DB: set icon/class properties + end + deactivate Parser + + %% Data Preparation + Renderer->>DB: getData() for layout + activate DB + DB->>DB: collect all nodes + DB->>DB: build parent-child relationships + DB-->>Renderer: return node hierarchy + deactivate DB + + %% Rendering Pipeline + activate Renderer + Note over Renderer: Rendering Phase + + Renderer->>Cytoscape: initialize cytoscape + activate Cytoscape + + loop For each node in mindmap + Renderer->>Cytoscape: addNodes(mindmap, cy, conf, level) + Cytoscape->>Cytoscape: create node data + Cytoscape->>Cytoscape: set position (x, y) + end + + loop For parent-child relationships + Renderer->>Cytoscape: add edges + Cytoscape->>Cytoscape: create edge data + end + + Renderer->>Cytoscape: configure cose-bilkent layout + Cytoscape->>Cytoscape: calculate optimal positions + Cytoscape-->>Renderer: return positioned graph + deactivate Cytoscape + + %% SVG Generation + Renderer->>SVGDraw: drawNodes(db, svg, mindmap, section, conf) + activate SVGDraw + + loop For each node recursively + SVGDraw->>SVGDraw: select shape function + + alt Default Shape + SVGDraw->>SVGDraw: defaultBkg() - rounded rectangle + else Rectangle Shape + SVGDraw->>SVGDraw: rectBkg() - sharp corners + else Circle Shape + SVGDraw->>SVGDraw: circleBkg() - perfect circle + else Cloud Shape + SVGDraw->>SVGDraw: cloudBkg() - organic curves + else Bang Shape + SVGDraw->>SVGDraw: bangBkg() - explosion style + else Hexagon Shape + SVGDraw->>SVGDraw: hexagonBkg() - six sides + end + + SVGDraw->>SVGDraw: create SVG elements + SVGDraw->>SVGDraw: add text labels + SVGDraw->>SVGDraw: position node + + opt Node has children + SVGDraw->>SVGDraw: drawNodes() recursive call + end + end + deactivate SVGDraw + + %% Edge Rendering + Renderer->>Renderer: drawEdges(edgesEl, cy) + loop For each edge + Renderer->>Renderer: extract edge bounds + Renderer->>Renderer: draw SVG path + end + + %% Styling Application + Renderer->>Styles: getStyles(options) + activate Styles + + Styles->>Styles: genSections(options) + loop For THEME_COLOR_LIMIT sections + Styles->>Styles: generate color scale + Styles->>Styles: create CSS rules + Note right of Styles: .section-X fills
.edge-depth-X widths
.node-icon-X colors + end + + Styles->>Styles: apply theme integration + Styles-->>Renderer: return compiled CSS + deactivate Styles + + %% Final Assembly + Renderer->>Output: selectSvgElement() + Renderer->>Output: setupGraphViewbox() + Renderer->>Output: apply styles + Renderer->>Output: add interactive elements + deactivate Renderer + + activate Output + Note over Output: Final Mindmap Features + Output->>Output: responsive layout + Output->>Output: accessibility attributes + Output->>Output: hover effects + Output->>Output: click handling + Output-->>User: rendered mindmap + deactivate Output + + %% Configuration Details + Note over DB, Styles: Configuration Options + Note right of DB: Padding Calculations:
Base padding from config
RECT: ×2 padding
ROUNDED_RECT: ×2 padding
HEXAGON: ×2 padding + Note right of Styles: Section Management:
MAX_SECTIONS = 12
Dynamic color generation
Git theme integration + Note right of Renderer: Layout Parameters:
Cytoscape configuration
coseBilkent settings
Node spacing rules \ No newline at end of file diff --git a/docs/ecosystem/integrations-community.md b/docs/ecosystem/integrations-community.md index 463fcfae7..6bc16e3e2 100644 --- a/docs/ecosystem/integrations-community.md +++ b/docs/ecosystem/integrations-community.md @@ -73,7 +73,7 @@ To add an integration to this list, see the [Integrations - create page](./integ - [Obsidian](https://help.obsidian.md/Editing+and+formatting/Advanced+formatting+syntax#Diagram) ✅ - [Outline](https://docs.getoutline.com/s/guide/doc/diagrams-KQiKoT4wzK) ✅ - [Redmine](https://redmine.org) - - [Mermaid Macro](https://www.redmine.org/plugins/redmine_mermaid_macro) + - [Mermaid Macro](https://redmine.org/plugins/redmine_mermaid_macro) - [Markdown for mermaid plugin](https://github.com/jamieh-mongolian/markdown-for-mermaid-plugin) - [redmine-mermaid](https://github.com/styz/redmine_mermaid) - Visual Studio Code [Polyglot Interactive Notebooks](https://github.com/dotnet/interactive#net-interactive) @@ -84,6 +84,7 @@ To add an integration to this list, see the [Integrations - create page](./integ LLM integrations to create mermaid diagrams using AI from text descriptions. - [HueHive - Create mermaid diagrams with text](https://huehive.co/tools/diagrams) +- [MCP Server Mermaid](https://github.com/hustcc/mcp-mermaid) - Generate mermaid diagram and chart with AI MCP dynamically. ### CRM/ERP @@ -103,6 +104,7 @@ Blogging frameworks and platforms - [Mermaid](https://nextra.site/docs/guide/mermaid) - [WordPress](https://wordpress.org) - [MerPRess](https://wordpress.org/plugins/merpress/) + - [WP Documentation](https://wordpress.org/themes/wp-documentation/) ### CMS/ECM @@ -115,7 +117,7 @@ Content Management Systems/Enterprise Content Management - [Grav CMS](https://getgrav.org/) - [Mermaid Diagrams Plugin](https://github.com/DanielFlaum/grav-plugin-mermaid-diagrams) - [GitLab Markdown Adapter](https://github.com/Goutte/grav-plugin-gitlab-markdown-adapter) -- [Tiki](https://tiki.org) +- [Tiki Wiki CMS Groupware](https://tiki.org) - [Tracker Entity Relationship Diagram](https://doc.tiki.org/Tracker-Entity-Relationship-Diagram) - [VitePress](https://vitepress.vuejs.org/) - [Plugin for Mermaid.js](https://emersonbottero.github.io/vitepress-plugin-mermaid/) diff --git a/docs/ecosystem/integrations-create.md b/docs/ecosystem/integrations-create.md index 921368406..9538243f3 100644 --- a/docs/ecosystem/integrations-create.md +++ b/docs/ecosystem/integrations-create.md @@ -16,9 +16,7 @@ Applications that support Mermaid files [SHOULD](https://datatracker.ietf.org/do ### MIME Type -The recommended [MIME type](https://www.iana.org/assignments/media-types/media-types.xhtml) for Mermaid media is `text/vnd.mermaid`. - -Currently pending [IANA](https://www.iana.org/) recognition. +The recommended [MIME type](https://www.iana.org/assignments/media-types/media-types.xhtml) for Mermaid media is [`text/vnd.mermaid`](https://www.iana.org/assignments/media-types/application/vnd.mermaid). ## Showcase diff --git a/docs/news/blog.md b/docs/news/blog.md index ff5f1b46b..eda497fdf 100644 --- a/docs/news/blog.md +++ b/docs/news/blog.md @@ -6,6 +6,66 @@ # Blog +## [Mermaid introduces the Visual Editor for Entity Relationship diagrams](https://docs.mermaidchart.com/blog/posts/mermaid-introduces-the-visual-editor-for-entity-relationship-diagrams) + +7/15/2025 • 7 mins + +Mermaid just introduced a Visual Editor for Entity Relationship diagrams, letting anyone map database structures through a simple point-and-click interface instead of code. This no-code ER builder now sits alongside Mermaid’s editors for flowcharts, sequence, and class diagrams, enabling teams to craft and share polished data models for apps, AI, and business processes. + +## [Mermaid supports Treemap Diagrams now!!!](https://docs.mermaidchart.com/blog/posts/mermaid-have-treemap-diagrams-now) + +7/3/2025 • 4 mins + +Mermaid has introduced Treemap diagrams, currently in beta, enhancing hierarchical data visualization. Treemap diagrams use nested rectangles to represent data relationships, focusing on size and proportions. They offer various applications, including budget visualization and market analysis. With simple syntax and customization options, users can effectively present complex data hierarchies. + +## [AI Diagram Generators and Data Visualization: Best Practices](https://docs.mermaidchart.com/blog/posts/ai-diagram-generators-and-data-visualization-best-practices) + +7/2/2025 • 6 mins + +AI diagram generators transform complex data into clear, interactive visuals – enabling faster analysis, better decisions, and stronger collaboration across teams. By combining automation with manual refinement, these tools empower anyone to communicate insights effectively, regardless of technical skill level. + +## [How to Choose the Best AI Diagram Generator for Your Needs (2025)](https://docs.mermaidchart.com/blog/posts/how-to-choose-the-best-ai-diagram-generator-for-your-needs-2025) + +6/26/2025 • 14 mins + +AI diagram generators are transforming how developers visualize and communicate complex systems, reducing hours of manual work into minutes. With tools like Mermaid AI, users benefit from both code-based and visual editing, enabling seamless collaboration and precision. Whether you’re diagramming workflows, software architecture, or data relationships, the right AI tool can significantly boost productivity and streamline communication. + +## [5 Time-Saving Tips for Using Mermaid’s AI Diagram Generator Effectively](https://docs.mermaidchart.com/blog/posts/5-time-saving-tips-for-using-mermaids-ai-diagram-generator-effectively) + +6/11/2025 • 10 mins + +See how developers can save time and boost productivity using Mermaid Chart’s AI diagram generator. Learn five practical tips that help turn plain language into powerful, professional diagrams. + +## [Enhancing Team Collaboration with AI-Powered Diagrams](https://docs.mermaidchart.com/blog/posts/enhancing-team-collaboration-with-ai-powered-diagrams) + +5/27/2025 • 6 mins + +Software teams move fast, but old-school diagramming tools can’t keep up. Mermaid Chart replaces static slides and whiteboards with real-time, AI-generated visuals that evolve with your code and ideas. Just describe a process in plain English, and watch it come to life. + +## [What is an AI Diagram Generator? Benefits and Use Cases](https://docs.mermaidchart.com/blog/posts/what-is-an-ai-diagram-generator-benefits-and-use-cases) + +5/22/2025 • 6 mins + +Discover how AI diagram generators like Mermaid Chart transform developer workflows. Instantly turn text into flowcharts, ERDs, and system diagrams, no manual drag-and-drop needed. Learn how it works, key benefits, and real-world use cases. + +## [How to Use Mermaid Chart as an AI Diagram Generator for Developers](https://docs.mermaidchart.com/blog/posts/how-to-use-mermaid-chart-as-an-ai-diagram-generator) + +5/21/2025 • 9 mins + +Would an AI diagram generator make your life easier? We think it would! + +## [Mermaid Chart VS Code Plugin: Create and Edit Mermaid.js Diagrams in Visual Studio Code](https://docs.mermaidchart.com/blog/posts/mermaid-chart-vs-code-plugin-create-and-edit-mermaid-js-diagrams-in-visual-studio-code) + +3/21/2025 • 5 mins + +The Mermaid Chart VS Code Plugin is a powerful developer diagramming tool that brings Mermaid.js diagramming directly into your Visual Studio Code environment. Whether you’re visualizing software architecture, documenting API flows, fixing bad documentation, or managing flowcharts and sequence diagrams, this plugin integrates seamlessly into your workflow. Key Features of the Mermaid Chart VS Code \[…] + +## [Mermaid Chart: The Evolution of Mermaid](https://docs.mermaidchart.com/blog/posts/mermaid-chart-the-evolution-of-mermaid) + +1/30/2025 • 3 mins + +Mermaid revolutionized diagramming with its simple, markdown-style syntax, empowering millions of developers worldwide. Now, Mermaid Chart takes it further with AI-powered visuals, a GUI for seamless editing, real-time collaboration, and advanced design tools. Experience the next generation of diagramming—faster, smarter, and built for modern teams. Try Mermaid Chart today! + ## [GUI for editing Mermaid Class Diagrams](https://docs.mermaidchart.com/blog/posts/gui-for-editing-mermaid-class-diagrams) 1/17/2025 • 5 mins diff --git a/docs/syntax/block.md b/docs/syntax/block.md index d711a2c92..5ca0db719 100644 --- a/docs/syntax/block.md +++ b/docs/syntax/block.md @@ -9,7 +9,7 @@ ## Introduction to Block Diagrams ```mermaid-example -block-beta +block columns 1 db(("DB")) blockArrowId6<["   "]>(down) @@ -26,7 +26,7 @@ columns 1 ``` ```mermaid -block-beta +block columns 1 db(("DB")) blockArrowId6<["   "]>(down) @@ -80,12 +80,12 @@ At its core, a block diagram consists of blocks representing different entities To create a simple block diagram with three blocks labeled 'a', 'b', and 'c', the syntax is as follows: ```mermaid-example -block-beta +block a b c ``` ```mermaid -block-beta +block a b c ``` @@ -101,13 +101,13 @@ While simple block diagrams are linear and straightforward, more complex systems In scenarios where you need to distribute blocks across multiple columns, you can specify the number of columns and arrange the blocks accordingly. Here's how to create a block diagram with three columns and four blocks, where the fourth block appears in a second row: ```mermaid-example -block-beta +block columns 3 a b c d ``` ```mermaid -block-beta +block columns 3 a b c d ``` @@ -130,13 +130,13 @@ In more complex diagrams, you may need blocks that span multiple columns to emph To create a block diagram where one block spans across two columns, you can specify the desired width for each block: ```mermaid-example -block-beta +block columns 3 a["A label"] b:2 c:2 d ``` ```mermaid -block-beta +block columns 3 a["A label"] b:2 c:2 d ``` @@ -153,7 +153,7 @@ Composite blocks, or blocks within blocks, are an advanced feature in Mermaid's Creating a composite block involves defining a parent block and then nesting other blocks within it. Here's how to define a composite block with nested elements: ```mermaid-example -block-beta +block block D end @@ -161,7 +161,7 @@ block-beta ``` ```mermaid -block-beta +block block D end @@ -180,7 +180,7 @@ Mermaid also allows for dynamic adjustment of column widths based on the content In diagrams with varying block sizes, Mermaid automatically adjusts the column widths to fit the largest block in each column. Here's an example: ```mermaid-example -block-beta +block columns 3 a:3 block:group1:2 @@ -195,7 +195,7 @@ block-beta ``` ```mermaid -block-beta +block columns 3 a:3 block:group1:2 @@ -215,7 +215,7 @@ This example demonstrates how Mermaid dynamically adjusts the width of the colum In scenarios where you need to stack blocks horizontally, you can use column width to accomplish the task. Blocks can be arranged vertically by putting them in a single column. Here is how you can create a block diagram in which 4 blocks are stacked on top of each other: ```mermaid-example -block-beta +block block columns 1 a["A label"] b c d @@ -223,7 +223,7 @@ block-beta ``` ```mermaid -block-beta +block block columns 1 a["A label"] b c d @@ -247,12 +247,12 @@ Mermaid supports a range of block shapes to suit different diagramming needs, fr To create a block with round edges, which can be used to represent a softer or more flexible component: ```mermaid-example -block-beta +block id1("This is the text in the box") ``` ```mermaid -block-beta +block id1("This is the text in the box") ``` @@ -261,12 +261,12 @@ block-beta A stadium-shaped block, resembling an elongated circle, can be used for components that are process-oriented: ```mermaid-example -block-beta +block id1(["This is the text in the box"]) ``` ```mermaid -block-beta +block id1(["This is the text in the box"]) ``` @@ -275,12 +275,12 @@ block-beta For representing subroutines or contained processes, a block with double vertical lines is useful: ```mermaid-example -block-beta +block id1[["This is the text in the box"]] ``` ```mermaid -block-beta +block id1[["This is the text in the box"]] ``` @@ -289,12 +289,12 @@ block-beta The cylindrical shape is ideal for representing databases or storage components: ```mermaid-example -block-beta +block id1[("Database")] ``` ```mermaid -block-beta +block id1[("Database")] ``` @@ -303,12 +303,12 @@ block-beta A circle can be used for centralized or pivotal components: ```mermaid-example -block-beta +block id1(("This is the text in the circle")) ``` ```mermaid -block-beta +block id1(("This is the text in the circle")) ``` @@ -319,36 +319,36 @@ For decision points, use a rhombus, and for unique or specialized processes, asy **Asymmetric** ```mermaid-example -block-beta +block id1>"This is the text in the box"] ``` ```mermaid -block-beta +block id1>"This is the text in the box"] ``` **Rhombus** ```mermaid-example -block-beta +block id1{"This is the text in the box"} ``` ```mermaid -block-beta +block id1{"This is the text in the box"} ``` **Hexagon** ```mermaid-example -block-beta +block id1{{"This is the text in the box"}} ``` ```mermaid -block-beta +block id1{{"This is the text in the box"}} ``` @@ -357,7 +357,7 @@ block-beta Parallelogram and trapezoid shapes are perfect for inputs/outputs and transitional processes: ```mermaid-example -block-beta +block id1[/"This is the text in the box"/] id2[\"This is the text in the box"\] A[/"Christmas"\] @@ -365,7 +365,7 @@ block-beta ``` ```mermaid -block-beta +block id1[/"This is the text in the box"/] id2[\"This is the text in the box"\] A[/"Christmas"\] @@ -377,12 +377,12 @@ block-beta For highlighting critical or high-priority components, a double circle can be effective: ```mermaid-example -block-beta +block id1((("This is the text in the circle"))) ``` ```mermaid -block-beta +block id1((("This is the text in the circle"))) ``` @@ -395,7 +395,7 @@ Mermaid also offers unique shapes like block arrows and space blocks for directi Block arrows can visually indicate direction or flow within a process: ```mermaid-example -block-beta +block blockArrowId<["Label"]>(right) blockArrowId2<["Label"]>(left) blockArrowId3<["Label"]>(up) @@ -406,7 +406,7 @@ block-beta ``` ```mermaid -block-beta +block blockArrowId<["Label"]>(right) blockArrowId2<["Label"]>(left) blockArrowId3<["Label"]>(up) @@ -421,14 +421,14 @@ block-beta Space blocks can be used to create intentional empty spaces in the diagram, which is useful for layout and readability: ```mermaid-example -block-beta +block columns 3 a space b c d e ``` ```mermaid -block-beta +block columns 3 a space b c d e @@ -437,12 +437,12 @@ block-beta or ```mermaid-example -block-beta +block ida space:3 idb idc ``` ```mermaid -block-beta +block ida space:3 idb idc ``` @@ -467,13 +467,13 @@ The most fundamental aspect of connecting blocks is the use of arrows or links. A simple link with an arrow can be created to show direction or flow from one block to another: ```mermaid-example -block-beta +block A space B A-->B ``` ```mermaid -block-beta +block A space B A-->B ``` @@ -490,13 +490,13 @@ Example - Text with Links To add text to a link, the syntax includes the text within the link definition: ```mermaid-example -block-beta +block A space:2 B A-- "X" -->B ``` ```mermaid -block-beta +block A space:2 B A-- "X" -->B ``` @@ -506,7 +506,7 @@ This example show how to add descriptive text to the links, enhancing the inform Example - Edges and Styles: ```mermaid-example -block-beta +block columns 1 db(("DB")) blockArrowId6<["   "]>(down) @@ -523,7 +523,7 @@ columns 1 ``` ```mermaid -block-beta +block columns 1 db(("DB")) blockArrowId6<["   "]>(down) @@ -552,7 +552,7 @@ Mermaid enables detailed styling of individual blocks, allowing you to apply var To apply custom styles to a block, you can use the `style` keyword followed by the block identifier and the desired CSS properties: ```mermaid-example -block-beta +block id1 space id2 id1("Start")-->id2("Stop") style id1 fill:#636,stroke:#333,stroke-width:4px @@ -560,7 +560,7 @@ block-beta ``` ```mermaid -block-beta +block id1 space id2 id1("Start")-->id2("Stop") style id1 fill:#636,stroke:#333,stroke-width:4px @@ -574,7 +574,7 @@ Mermaid enables applying styling to classes, which could make styling easier if #### Example - Styling a Single Class ```mermaid-example -block-beta +block A space B A-->B classDef blue fill:#6e6ce6,stroke:#333,stroke-width:4px; @@ -583,7 +583,7 @@ block-beta ``` ```mermaid -block-beta +block A space B A-->B classDef blue fill:#6e6ce6,stroke:#333,stroke-width:4px; @@ -608,7 +608,7 @@ Combining the elements of structure, linking, and styling, we can create compreh Illustrating a simple software system architecture with interconnected components: ```mermaid-example -block-beta +block columns 3 Frontend blockArrowId6<[" "]>(right) Backend space:2 down<[" "]>(down) @@ -621,7 +621,7 @@ block-beta ``` ```mermaid -block-beta +block columns 3 Frontend blockArrowId6<[" "]>(right) Backend space:2 down<[" "]>(down) @@ -640,7 +640,7 @@ This example shows a basic architecture with a frontend, backend, and database. Representing a business process flow with decision points and multiple stages: ```mermaid-example -block-beta +block columns 3 Start(("Start")) space:2 down<[" "]>(down) space:2 @@ -653,7 +653,7 @@ block-beta ``` ```mermaid -block-beta +block columns 3 Start(("Start")) space:2 down<[" "]>(down) space:2 @@ -682,7 +682,7 @@ Understanding and avoiding common syntax errors is key to a smooth experience wi A common mistake is incorrect linking syntax, which can lead to unexpected results or broken diagrams: ``` -block-beta +block A - B ``` @@ -690,13 +690,13 @@ block-beta Ensure that links between blocks are correctly specified with arrows (--> or ---) to define the direction and type of connection. Also remember that one of the fundamentals for block diagram is to give the author full control of where the boxes are positioned so in the example you need to add a space between the boxes: ```mermaid-example -block-beta +block A space B A --> B ``` ```mermaid -block-beta +block A space B A --> B ``` @@ -706,13 +706,13 @@ block-beta Applying styles in the wrong context or with incorrect syntax can lead to blocks not being styled as intended: ```mermaid-example - block-beta + block A style A fill#969; ``` ```mermaid - block-beta + block A style A fill#969; ``` @@ -721,14 +721,14 @@ Applying styles in the wrong context or with incorrect syntax can lead to blocks Correct the syntax by ensuring proper separation of style properties with commas and using the correct CSS property format: ```mermaid-example -block-beta +block A style A fill:#969,stroke:#333; ``` ```mermaid -block-beta +block A style A fill:#969,stroke:#333; diff --git a/docs/syntax/flowchart.md b/docs/syntax/flowchart.md index 243592515..23c34509c 100644 --- a/docs/syntax/flowchart.md +++ b/docs/syntax/flowchart.md @@ -326,7 +326,9 @@ Below is a comprehensive list of the newly introduced shapes and their correspon | **Semantic Name** | **Shape Name** | **Short Name** | **Description** | **Alias Supported** | | --------------------------------- | ---------------------- | -------------- | ------------------------------ | ---------------------------------------------------------------- | +| Bang | Bang | `bang` | Bang | `bang` | | Card | Notched Rectangle | `notch-rect` | Represents a card | `card`, `notched-rectangle` | +| Cloud | Cloud | `cloud` | cloud | `cloud` | | Collate | Hourglass | `hourglass` | Represents a collate operation | `collate`, `hourglass` | | Com Link | Lightning Bolt | `bolt` | Communication link | `com-link`, `lightning-bolt` | | Comment | Curly Brace | `brace` | Adds a comment | `brace-l`, `comment` | @@ -983,11 +985,23 @@ flowchart TD - `b` - **w**: The width of the image. If not defined, this will default to the natural width of the image. - **h**: The height of the image. If not defined, this will default to the natural height of the image. -- **constraint**: Determines if the image should constrain the node size. This setting also ensures the image maintains its original aspect ratio, adjusting the height (`h`) accordingly to the width (`w`). If not defined, this will default to `off` Possible values are: +- **constraint**: Determines if the image should constrain the node size. This setting also ensures the image maintains its original aspect ratio, adjusting the width (`w`) accordingly to the height (`h`). If not defined, this will default to `off` Possible values are: - `on` - `off` -These new shapes provide additional flexibility and visual appeal to your flowcharts, making them more informative and engaging. +If you want to resize an image, but keep the same aspect ratio, set `h`, and set `constraint: on` to constrain the aspect ratio. E.g. + +```mermaid-example +flowchart TD + %% My image with a constrained aspect ratio + A@{ img: "https://mermaid.js.org/favicon.svg", label: "My example image label", pos: "t", h: 60, constraint: "on" } +``` + +```mermaid +flowchart TD + %% My image with a constrained aspect ratio + A@{ img: "https://mermaid.js.org/favicon.svg", label: "My example image label", pos: "t", h: 60, constraint: "on" } +``` ## Links between nodes @@ -1795,15 +1809,54 @@ It is possible to style the type of curve used for lines between items, if the d Available curve styles include `basis`, `bumpX`, `bumpY`, `cardinal`, `catmullRom`, `linear`, `monotoneX`, `monotoneY`, `natural`, `step`, `stepAfter`, and `stepBefore`. +For a full list of available curves, including an explanation of custom curves, refer to +the [Shapes](https://d3js.org/d3-shape/curve) documentation in the [d3-shape](https://github.com/d3/d3-shape/) project. + +Line styling can be achieved in two ways: + +1. Change the curve style of all the lines +2. Change the curve style of a particular line + +#### Diagram level curve style + In this example, a left-to-right graph uses the `stepBefore` curve style: ``` -%%{ init: { 'flowchart': { 'curve': 'stepBefore' } } }%% +--- +config: + flowchart: + curve: stepBefore +--- graph LR ``` -For a full list of available curves, including an explanation of custom curves, refer to -the [Shapes](https://d3js.org/d3-shape/curve) documentation in the [d3-shape](https://github.com/d3/d3-shape/) project. +#### Edge level curve style using Edge IDs (v11.10.0+) + +You can assign IDs to [edges](#attaching-an-id-to-edges). After assigning an ID you can modify the line style by modifying the edge's `curve` property using the following syntax: + +```mermaid-example +flowchart LR + A e1@==> B + A e2@--> C + e1@{ curve: linear } + e2@{ curve: natural } +``` + +```mermaid +flowchart LR + A e1@==> B + A e2@--> C + e1@{ curve: linear } + e2@{ curve: natural } +``` + +```info +Any edge curve style modified at the edge level overrides the diagram level style. +``` + +```info +If the same edge is modified multiple times the last modification will be rendered. +``` ### Styling a node diff --git a/docs/syntax/mindmap.md b/docs/syntax/mindmap.md index 1adaa2c49..844b3293c 100644 --- a/docs/syntax/mindmap.md +++ b/docs/syntax/mindmap.md @@ -314,3 +314,22 @@ You can also refer the [implementation in the live editor](https://github.com/me cspell:locale en,en-gb cspell:ignore Buzan ---> + +## Layouts + +Mermaid also supports a Tidy Tree layout for mindmaps. + +``` +--- +config: + layout: tidy-tree +--- +mindmap +root((mindmap is a long thing)) + A + B + C + D +``` + +Instructions to add and register tidy-tree layout are present in [Tidy Tree Configuration](/config/tidy-tree) diff --git a/docs/syntax/pie.md b/docs/syntax/pie.md index b8f452b66..fd5ec1db0 100644 --- a/docs/syntax/pie.md +++ b/docs/syntax/pie.md @@ -37,6 +37,11 @@ Drawing a pie chart is really simple in mermaid. - Followed by `:` colon as separator - Followed by `positive numeric value` (supported up to two decimal places) +**Note:** + +> Pie chart values must be **positive numbers greater than zero**. +> **Negative values are not allowed** and will result in an error. + \[pie] \[showData] (OPTIONAL) \[title] \[titlevalue] (OPTIONAL) "\[datakey1]" : \[dataValue1] diff --git a/docs/syntax/sankey.md b/docs/syntax/sankey.md index ccabc11c9..e981358b5 100644 --- a/docs/syntax/sankey.md +++ b/docs/syntax/sankey.md @@ -23,7 +23,7 @@ config: sankey: showValues: false --- -sankey-beta +sankey Agricultural 'waste',Bio-conversion,124.729 Bio-conversion,Liquid,0.597 @@ -101,7 +101,7 @@ config: sankey: showValues: false --- -sankey-beta +sankey Agricultural 'waste',Bio-conversion,124.729 Bio-conversion,Liquid,0.597 @@ -175,7 +175,7 @@ Wind,Electricity grid,289.366 ## Syntax -The idea behind syntax is that a user types `sankey-beta` keyword first, then pastes raw CSV below and get the result. +The idea behind syntax is that a user types `sankey` keyword first, then pastes raw CSV below and get the result. It implements CSV standard as [described here](https://www.ietf.org/rfc/rfc4180.txt) with subtle **differences**: @@ -187,7 +187,7 @@ It implements CSV standard as [described here](https://www.ietf.org/rfc/rfc4180. It is implied that 3 columns inside CSV should represent `source`, `target` and `value` accordingly: ```mermaid-example -sankey-beta +sankey %% source,target,value Electricity grid,Over generation / exports,104.453 @@ -196,7 +196,7 @@ Electricity grid,H2 conversion,27.14 ``` ```mermaid -sankey-beta +sankey %% source,target,value Electricity grid,Over generation / exports,104.453 @@ -209,7 +209,7 @@ Electricity grid,H2 conversion,27.14 CSV does not support empty lines without comma delimiters by default. But you can add them if needed: ```mermaid-example -sankey-beta +sankey Bio-conversion,Losses,26.862 @@ -219,7 +219,7 @@ Bio-conversion,Gas,81.144 ``` ```mermaid -sankey-beta +sankey Bio-conversion,Losses,26.862 @@ -233,14 +233,14 @@ Bio-conversion,Gas,81.144 If you need to have a comma, wrap it in double quotes: ```mermaid-example -sankey-beta +sankey Pumped heat,"Heating and cooling, homes",193.026 Pumped heat,"Heating and cooling, commercial",70.672 ``` ```mermaid -sankey-beta +sankey Pumped heat,"Heating and cooling, homes",193.026 Pumped heat,"Heating and cooling, commercial",70.672 @@ -251,14 +251,14 @@ Pumped heat,"Heating and cooling, commercial",70.672 If you need to have double quote, put a pair of them inside quoted string: ```mermaid-example -sankey-beta +sankey Pumped heat,"Heating and cooling, ""homes""",193.026 Pumped heat,"Heating and cooling, ""commercial""",70.672 ``` ```mermaid -sankey-beta +sankey Pumped heat,"Heating and cooling, ""homes""",193.026 Pumped heat,"Heating and cooling, ""commercial""",70.672 diff --git a/docs/syntax/sequenceDiagram.md b/docs/syntax/sequenceDiagram.md index 84240a0cd..a8f502dcd 100644 --- a/docs/syntax/sequenceDiagram.md +++ b/docs/syntax/sequenceDiagram.md @@ -74,6 +74,126 @@ sequenceDiagram Bob->>Alice: Hi Alice ``` +### Boundary + +If you want to use the boundary symbol for a participant, use the JSON configuration syntax as shown below. + +```mermaid-example +sequenceDiagram + participant Alice@{ "type" : "boundary" } + participant Bob + Alice->>Bob: Request from boundary + Bob->>Alice: Response to boundary +``` + +```mermaid +sequenceDiagram + participant Alice@{ "type" : "boundary" } + participant Bob + Alice->>Bob: Request from boundary + Bob->>Alice: Response to boundary +``` + +### Control + +If you want to use the control symbol for a participant, use the JSON configuration syntax as shown below. + +```mermaid-example +sequenceDiagram + participant Alice@{ "type" : "control" } + participant Bob + Alice->>Bob: Control request + Bob->>Alice: Control response +``` + +```mermaid +sequenceDiagram + participant Alice@{ "type" : "control" } + participant Bob + Alice->>Bob: Control request + Bob->>Alice: Control response +``` + +### Entity + +If you want to use the entity symbol for a participant, use the JSON configuration syntax as shown below. + +```mermaid-example +sequenceDiagram + participant Alice@{ "type" : "entity" } + participant Bob + Alice->>Bob: Entity request + Bob->>Alice: Entity response +``` + +```mermaid +sequenceDiagram + participant Alice@{ "type" : "entity" } + participant Bob + Alice->>Bob: Entity request + Bob->>Alice: Entity response +``` + +### Database + +If you want to use the database symbol for a participant, use the JSON configuration syntax as shown below. + +```mermaid-example +sequenceDiagram + participant Alice@{ "type" : "database" } + participant Bob + Alice->>Bob: DB query + Bob->>Alice: DB result +``` + +```mermaid +sequenceDiagram + participant Alice@{ "type" : "database" } + participant Bob + Alice->>Bob: DB query + Bob->>Alice: DB result +``` + +### Collections + +If you want to use the collections symbol for a participant, use the JSON configuration syntax as shown below. + +```mermaid-example +sequenceDiagram + participant Alice@{ "type" : "collections" } + participant Bob + Alice->>Bob: Collections request + Bob->>Alice: Collections response +``` + +```mermaid +sequenceDiagram + participant Alice@{ "type" : "collections" } + participant Bob + Alice->>Bob: Collections request + Bob->>Alice: Collections response +``` + +### Queue + +If you want to use the queue symbol for a participant, use the JSON configuration syntax as shown below. + +```mermaid-example +sequenceDiagram + participant Alice@{ "type" : "queue" } + participant Bob + Alice->>Bob: Queue message + Bob->>Alice: Queue response +``` + +```mermaid +sequenceDiagram + participant Alice@{ "type" : "queue" } + participant Bob + Alice->>Bob: Queue message + Bob->>Alice: Queue response +``` + ### Aliases The actor can have a convenient identifier and a descriptive label. diff --git a/docs/syntax/xyChart.md b/docs/syntax/xyChart.md index dd64f742d..742a4f18a 100644 --- a/docs/syntax/xyChart.md +++ b/docs/syntax/xyChart.md @@ -13,7 +13,7 @@ ## Example ```mermaid-example -xychart-beta +xychart title "Sales Revenue" x-axis [jan, feb, mar, apr, may, jun, jul, aug, sep, oct, nov, dec] y-axis "Revenue (in $)" 4000 --> 11000 @@ -22,7 +22,7 @@ xychart-beta ``` ```mermaid -xychart-beta +xychart title "Sales Revenue" x-axis [jan, feb, mar, apr, may, jun, jul, aug, sep, oct, nov, dec] y-axis "Revenue (in $)" 4000 --> 11000 @@ -40,7 +40,7 @@ xychart-beta The chart can be drawn horizontal or vertical, default value is vertical. ``` -xychart-beta horizontal +xychart horizontal ... ``` @@ -51,7 +51,7 @@ The title is a short description of the chart and it will always render on top o #### Example ``` -xychart-beta +xychart title "This is a simple example" ... ``` @@ -98,10 +98,10 @@ A bar chart offers the capability to graphically depict bars. #### Simplest example -The only two things required are the chart name (`xychart-beta`) and one data set. So you will be able to draw a chart with a simple config like +The only two things required are the chart name (`xychart`) and one data set. So you will be able to draw a chart with a simple config like ``` -xychart-beta +xychart line [+1.3, .6, 2.4, -.34] ``` @@ -138,7 +138,7 @@ xychart-beta ## Chart Theme Variables -Themes for xychart resides inside xychart attribute so to set the variables use this syntax: +Themes for xychart reside inside the `xychart` attribute, allowing customization through the following syntax: ```yaml --- @@ -163,6 +163,52 @@ config: | yAxisLineColor | Color of the y-axis line | | plotColorPalette | String of colors separated by comma e.g. "#f3456, #43445" | +### Setting Colors for Lines and Bars + +To set the color for lines and bars, use the `plotColorPalette` parameter. Colors in the palette will correspond sequentially to the elements in your chart (e.g., first bar/line will use the first color specified in the palette). + +```mermaid-example +--- +config: + themeVariables: + xyChart: + plotColorPalette: '#000000, #0000FF, #00FF00, #FF0000' +--- +xychart +title "Different Colors in xyChart" +x-axis "categoriesX" ["Category 1", "Category 2", "Category 3", "Category 4"] +y-axis "valuesY" 0 --> 50 +%% Black line +line [10,20,30,40] +%% Blue bar +bar [20,30,25,35] +%% Green bar +bar [15,25,20,30] +%% Red line +line [5,15,25,35] +``` + +```mermaid +--- +config: + themeVariables: + xyChart: + plotColorPalette: '#000000, #0000FF, #00FF00, #FF0000' +--- +xychart +title "Different Colors in xyChart" +x-axis "categoriesX" ["Category 1", "Category 2", "Category 3", "Category 4"] +y-axis "valuesY" 0 --> 50 +%% Black line +line [10,20,30,40] +%% Blue bar +bar [20,30,25,35] +%% Green bar +bar [15,25,20,30] +%% Red line +line [5,15,25,35] +``` + ## Example on config and theme ```mermaid-example @@ -176,7 +222,7 @@ config: xyChart: titleColor: "#ff0000" --- -xychart-beta +xychart title "Sales Revenue" x-axis [jan, feb, mar, apr, may, jun, jul, aug, sep, oct, nov, dec] y-axis "Revenue (in $)" 4000 --> 11000 @@ -195,7 +241,7 @@ config: xyChart: titleColor: "#ff0000" --- -xychart-beta +xychart title "Sales Revenue" x-axis [jan, feb, mar, apr, may, jun, jul, aug, sep, oct, nov, dec] y-axis "Revenue (in $)" 4000 --> 11000 diff --git a/eslint.config.js b/eslint.config.js index 7a144ee00..416fca2c6 100644 --- a/eslint.config.js +++ b/eslint.config.js @@ -17,6 +17,7 @@ export default tseslint.config( ...tseslint.configs.stylisticTypeChecked, { ignores: [ + '**/*.d.ts', '**/dist/', '**/node_modules/', '.git/', diff --git a/package.json b/package.json index e85e380f9..ddd0446ed 100644 --- a/package.json +++ b/package.json @@ -67,7 +67,7 @@ "@argos-ci/cypress": "^5.0.2", "@changesets/changelog-github": "^0.5.1", "@changesets/cli": "^2.27.12", - "@cspell/eslint-plugin": "^8.19.3", + "@cspell/eslint-plugin": "^8.19.4", "@cypress/code-coverage": "^3.12.49", "@eslint/js": "^9.26.0", "@rollup/plugin-typescript": "^12.1.2", @@ -94,17 +94,17 @@ "cypress-split": "^1.24.14", "esbuild": "^0.25.0", "eslint": "^9.26.0", - "eslint-config-prettier": "^10.1.1", + "eslint-config-prettier": "^10.1.8", "eslint-plugin-cypress": "^4.3.0", - "eslint-plugin-html": "^8.1.2", - "eslint-plugin-jest": "^28.11.0", - "eslint-plugin-jsdoc": "^50.6.9", + "eslint-plugin-html": "^8.1.3", + "eslint-plugin-jest": "^28.14.0", + "eslint-plugin-jsdoc": "^50.8.0", "eslint-plugin-json": "^4.0.1", "eslint-plugin-lodash": "^8.0.0", "eslint-plugin-markdown": "^5.1.0", "eslint-plugin-no-only-tests": "^3.3.0", "eslint-plugin-tsdoc": "^0.4.0", - "eslint-plugin-unicorn": "^59.0.0", + "eslint-plugin-unicorn": "^59.0.1", "express": "^5.1.0", "globals": "^16.0.0", "globby": "^14.0.2", @@ -126,7 +126,7 @@ "tslib": "^2.8.1", "tsx": "^4.7.3", "typescript": "~5.7.3", - "typescript-eslint": "^8.32.0", + "typescript-eslint": "^8.38.0", "vite": "^7.0.3", "vite-plugin-istanbul": "^7.0.0", "vitest": "^3.0.6" diff --git a/packages/examples/CHANGELOG.md b/packages/examples/CHANGELOG.md new file mode 100644 index 000000000..befef1a41 --- /dev/null +++ b/packages/examples/CHANGELOG.md @@ -0,0 +1,14 @@ +# @mermaid-js/examples + +## 1.0.0 + +### Minor Changes + +- [#6453](https://github.com/mermaid-js/mermaid/pull/6453) [`4936ef5`](https://github.com/mermaid-js/mermaid/commit/4936ef5c306d2f892cca9a95a5deac4af6d4882b) Thanks [@sidharthv96](https://github.com/sidharthv96)! - feat: Add examples for diagrams in the `@mermaid-js/examples` package + +### Patch Changes + +- [#6510](https://github.com/mermaid-js/mermaid/pull/6510) [`7a38eb7`](https://github.com/mermaid-js/mermaid/commit/7a38eb715d795cd5c66cb59357d64ec197b432e6) Thanks [@sidharthv96](https://github.com/sidharthv96)! - chore: Move packet diagram out of beta + +- Updated dependencies [[`5acbd7e`](https://github.com/mermaid-js/mermaid/commit/5acbd7e762469d9d89a9c77faf6617ee13367f3a), [`d90634b`](https://github.com/mermaid-js/mermaid/commit/d90634bf2b09e586b055729e07e9a1a31b21827c), [`7a38eb7`](https://github.com/mermaid-js/mermaid/commit/7a38eb715d795cd5c66cb59357d64ec197b432e6), [`3e3ae08`](https://github.com/mermaid-js/mermaid/commit/3e3ae089305e1c7b9948b9e149eba6854fe7f2d6), [`d3e2be3`](https://github.com/mermaid-js/mermaid/commit/d3e2be35be066adeb7fd502b4a24c223c3b53947), [`637680d`](https://github.com/mermaid-js/mermaid/commit/637680d4d9e39b4f8cb6f05b4cb261e8f5693ac3)]: + - mermaid@11.9.0 diff --git a/packages/examples/README.md b/packages/examples/README.md new file mode 100644 index 000000000..603d0cea8 --- /dev/null +++ b/packages/examples/README.md @@ -0,0 +1,41 @@ +# @mermaid-js/examples + +The `@mermaid-js/examples` package contains a collection of examples used by tools like [mermaid.live](https://mermaid.live) to help users get started with new diagrams. + +You can duplicate an existing diagram example file, e.g., `packages/examples/src/examples/flowchart.ts`, and modify it with details specific to your diagram. + +Then, import the example in the `packages/examples/src/index.ts` file and add it to the `examples` array. + +Each diagram should have at least one example, which should be marked as the default. It's a good idea to add more examples to showcase different features of the diagram. + +## Usage + +```bash +pnpm add @mermaid-js/examples +``` + +A sample usage of the package in mermaid.live, to get the default example for every diagram type: + +```ts +import { diagramData } from '@mermaid-js/examples'; + +type DiagramDefinition = (typeof diagramData)[number]; + +const isValidDiagram = (diagram: DiagramDefinition): diagram is Required => { + return Boolean(diagram.name && diagram.examples && diagram.examples.length > 0); +}; + +export const getSampleDiagrams = () => { + const diagrams = diagramData + .filter((d) => isValidDiagram(d)) + .map(({ examples, ...rest }) => ({ + ...rest, + example: examples?.filter(({ isDefault }) => isDefault)[0], + })); + const examples: Record = {}; + for (const diagram of diagrams) { + examples[diagram.name.replace(/ (Diagram|Chart|Graph)/, '')] = diagram.example.code; + } + return examples; +}; +``` diff --git a/packages/examples/package.json b/packages/examples/package.json index 90abc9da9..cd0fc0bd0 100644 --- a/packages/examples/package.json +++ b/packages/examples/package.json @@ -1,6 +1,6 @@ { "name": "@mermaid-js/examples", - "version": "0.0.1-beta.1", + "version": "1.0.0", "description": "Mermaid examples package", "author": "Sidharth Vinod", "type": "module", @@ -16,6 +16,10 @@ "files": [ "dist" ], + "repository": { + "type": "git", + "url": "https://github.com/mermaid-js/mermaid" + }, "scripts": { "clean": "rimraf dist" }, @@ -23,9 +27,6 @@ "devDependencies": { "mermaid": "workspace:*" }, - "peerDependencies": { - "mermaid": "workspace:~" - }, "publishConfig": { "access": "public" } diff --git a/packages/mermaid-layout-elk/CHANGELOG.md b/packages/mermaid-layout-elk/CHANGELOG.md index 96b5d2fae..ef40f04a0 100644 --- a/packages/mermaid-layout-elk/CHANGELOG.md +++ b/packages/mermaid-layout-elk/CHANGELOG.md @@ -1,5 +1,16 @@ # @mermaid-js/layout-elk +## 0.1.9 + +### Patch Changes + +- [#6857](https://github.com/mermaid-js/mermaid/pull/6857) [`b9ef683`](https://github.com/mermaid-js/mermaid/commit/b9ef683fb67b8959abc455d6cc5266c37ba435f6) Thanks [@knsv](https://github.com/knsv)! - feat: Exposing elk configuration forceNodeModelOrder and considerModelOrder to the mermaid configuration + +- [#6849](https://github.com/mermaid-js/mermaid/pull/6849) [`2260948`](https://github.com/mermaid-js/mermaid/commit/2260948b7bda08f00616c2ce678bed1da69eb96c) Thanks [@anderium](https://github.com/anderium)! - Make elk not force node model order, but strongly consider it instead + +- Updated dependencies [[`b9ef683`](https://github.com/mermaid-js/mermaid/commit/b9ef683fb67b8959abc455d6cc5266c37ba435f6), [`2c0931d`](https://github.com/mermaid-js/mermaid/commit/2c0931da46794b49d2523211e25f782900c34e94), [`33e08da`](https://github.com/mermaid-js/mermaid/commit/33e08daf175125295a06b1b80279437004a4e865), [`814b68b`](https://github.com/mermaid-js/mermaid/commit/814b68b4a94813f7c6b3d7fb4559532a7bab2652), [`fce7cab`](https://github.com/mermaid-js/mermaid/commit/fce7cabb71d68a20a66246fe23d066512126a412), [`fc07f0d`](https://github.com/mermaid-js/mermaid/commit/fc07f0d8abca49e4f887d7457b7b94fb07d1e3da), [`12e01bd`](https://github.com/mermaid-js/mermaid/commit/12e01bdb5cacf3569133979a5a4f1d8973e9aec1), [`01aaef3`](https://github.com/mermaid-js/mermaid/commit/01aaef39b4a1ec8bc5a0c6bfa3a20b712d67f4dc), [`daf8d8d`](https://github.com/mermaid-js/mermaid/commit/daf8d8d3befcd600618a629977b76463b38d0ad9), [`c36cd05`](https://github.com/mermaid-js/mermaid/commit/c36cd05c45ac3090181152b4dae41f8d7b569bd6), [`8bb29fc`](https://github.com/mermaid-js/mermaid/commit/8bb29fc879329ad109898e4025b4f4eba2ab0649), [`71b04f9`](https://github.com/mermaid-js/mermaid/commit/71b04f93b07f876df2b30656ef36036c1d0e4e4f), [`c99bce6`](https://github.com/mermaid-js/mermaid/commit/c99bce6bab4c7ce0b81b66d44f44853ce4aeb1c3), [`6cc1926`](https://github.com/mermaid-js/mermaid/commit/6cc192680a2531cab28f87a8061a53b786e010f3), [`9da6fb3`](https://github.com/mermaid-js/mermaid/commit/9da6fb39ae278401771943ac85d6d1b875f78cf1), [`e48b0ba`](https://github.com/mermaid-js/mermaid/commit/e48b0ba61dab7f95aa02da603b5b7d383b894932), [`4d62d59`](https://github.com/mermaid-js/mermaid/commit/4d62d5963238400270e9314c6e4d506f48147074), [`e9ce8cf`](https://github.com/mermaid-js/mermaid/commit/e9ce8cf4da9062d85098042044822100889bb0dd), [`9258b29`](https://github.com/mermaid-js/mermaid/commit/9258b2933bbe1ef41087345ffea3731673671c49), [`da90f67`](https://github.com/mermaid-js/mermaid/commit/da90f6760b6efb0da998bcb63b75eecc29e06c08), [`0133f1c`](https://github.com/mermaid-js/mermaid/commit/0133f1c0c5cff4fc4c8e0b99e9cf0b3d49dcbe71), [`895f9d4`](https://github.com/mermaid-js/mermaid/commit/895f9d43ff98ca05ebfba530789f677f31a011ff)]: + - mermaid@11.10.0 + ## 0.1.8 ### Patch Changes diff --git a/packages/mermaid-layout-elk/README.md b/packages/mermaid-layout-elk/README.md index ab3289d6e..eec287263 100644 --- a/packages/mermaid-layout-elk/README.md +++ b/packages/mermaid-layout-elk/README.md @@ -2,7 +2,7 @@ This package provides a layout engine for Mermaid based on the [ELK](https://www.eclipse.org/elk/) layout engine. -> [!NOTE] +> [!NOTE] > The ELK Layout engine will not be available in all providers that support mermaid by default. > The websites will have to install the `@mermaid-js/layout-elk` package to use the ELK layout engine. @@ -69,4 +69,4 @@ mermaid.registerLayoutLoaders(elkLayouts); - `elk.mrtree`: Multi-root tree layout - `elk.sporeOverlap`: Spore overlap layout - + diff --git a/packages/mermaid-layout-elk/package.json b/packages/mermaid-layout-elk/package.json index 023958c1f..176c14b25 100644 --- a/packages/mermaid-layout-elk/package.json +++ b/packages/mermaid-layout-elk/package.json @@ -1,6 +1,6 @@ { "name": "@mermaid-js/layout-elk", - "version": "0.1.8", + "version": "0.1.9", "description": "ELK layout engine for mermaid", "module": "dist/mermaid-layout-elk.core.mjs", "types": "dist/layouts.d.ts", diff --git a/packages/mermaid-layout-elk/src/find-common-ancestor.d.ts b/packages/mermaid-layout-elk/src/find-common-ancestor.d.ts new file mode 100644 index 000000000..db94f42c9 --- /dev/null +++ b/packages/mermaid-layout-elk/src/find-common-ancestor.d.ts @@ -0,0 +1,9 @@ +export interface TreeData { + parentById: Record; + childrenById: Record; +} +export declare const findCommonAncestor: ( + id1: string, + id2: string, + { parentById }: TreeData +) => string; diff --git a/packages/mermaid-layout-elk/src/render.ts b/packages/mermaid-layout-elk/src/render.ts index 9f361bf7b..d7d6974f5 100644 --- a/packages/mermaid-layout-elk/src/render.ts +++ b/packages/mermaid-layout-elk/src/render.ts @@ -4,7 +4,8 @@ import type { InternalHelpers, LayoutData, RenderOptions, SVG, SVGGroup } from ' import { type TreeData, findCommonAncestor } from './find-common-ancestor.js'; type Node = LayoutData['nodes'][number]; - +// Used to calculate distances in order to avoid floating number rounding issues when comparing floating numbers +const epsilon = 0.0001; interface LabelData { width: number; height: number; @@ -13,11 +14,20 @@ interface LabelData { } interface NodeWithVertex extends Omit { - children?: unknown[]; + children?: LayoutData['nodes']; labelData?: LabelData; domId?: Node['domId'] | SVGGroup | d3.Selection; } - +interface Point { + x: number; + y: number; +} +function distance(p1?: Point, p2?: Point): number { + if (!p1 || !p2) { + return 0; + } + return Math.sqrt(Math.pow(p2.x - p1.x, 2) + Math.pow(p2.y - p1.y, 2)); +} export const render = async ( data4Layout: LayoutData, svg: SVG, @@ -51,15 +61,30 @@ export const render = async ( // Add the element to the DOM if (!node.isGroup) { + // Create a clean node object for ELK with only the properties it expects const child: NodeWithVertex = { - ...node, + id: node.id, + width: node.width, + height: node.height, + // Store the original node data for later use + label: node.label, + isGroup: node.isGroup, + shape: node.shape, + padding: node.padding, + cssClasses: node.cssClasses, + cssStyles: node.cssStyles, + look: node.look, + // Include parentId for subgraph processing + parentId: node.parentId, }; graph.children.push(child); nodeDb[node.id] = child; const childNodeEl = await insertNode(nodeEl, node, { config, dir: node.dir }); const boundingBox = childNodeEl.node()!.getBBox(); + // Store the domId separately for rendering, not in the ELK graph child.domId = childNodeEl; + child.calcIntersect = node.calcIntersect; child.width = boundingBox.width; child.height = boundingBox.height; } else { @@ -459,302 +484,6 @@ export const render = async ( } } - function intersectLine( - p1: { y: number; x: number }, - p2: { y: number; x: number }, - q1: { x: any; y: any }, - q2: { x: any; y: any } - ) { - log.debug('UIO intersectLine', p1, p2, q1, q2); - // Algorithm from J. Avro, (ed.) Graphics Gems, No 2, Morgan Kaufmann, 1994, - // p7 and p473. - - // let a1, a2, b1, b2, c1, c2; - // let r1, r2, r3, r4; - // let denom, offset, num; - // let x, y; - - // Compute a1, b1, c1, where line joining points 1 and 2 is F(x,y) = a1 x + - // b1 y + c1 = 0. - const a1 = p2.y - p1.y; - const b1 = p1.x - p2.x; - const c1 = p2.x * p1.y - p1.x * p2.y; - - // Compute r3 and r4. - const r3 = a1 * q1.x + b1 * q1.y + c1; - const r4 = a1 * q2.x + b1 * q2.y + c1; - - const epsilon = 1e-6; - - // Check signs of r3 and r4. If both point 3 and point 4 lie on - // same side of line 1, the line segments do not intersect. - if (r3 !== 0 && r4 !== 0 && sameSign(r3, r4)) { - return /*DON'T_INTERSECT*/; - } - - // Compute a2, b2, c2 where line joining points 3 and 4 is G(x,y) = a2 x + b2 y + c2 = 0 - const a2 = q2.y - q1.y; - const b2 = q1.x - q2.x; - const c2 = q2.x * q1.y - q1.x * q2.y; - - // Compute r1 and r2 - const r1 = a2 * p1.x + b2 * p1.y + c2; - const r2 = a2 * p2.x + b2 * p2.y + c2; - - // Check signs of r1 and r2. If both point 1 and point 2 lie - // on same side of second line segment, the line segments do - // not intersect. - if (Math.abs(r1) < epsilon && Math.abs(r2) < epsilon && sameSign(r1, r2)) { - return /*DON'T_INTERSECT*/; - } - - // Line segments intersect: compute intersection point. - const denom = a1 * b2 - a2 * b1; - if (denom === 0) { - return /*COLLINEAR*/; - } - - const offset = Math.abs(denom / 2); - - // The denom/2 is to get rounding instead of truncating. It - // is added or subtracted to the numerator, depending upon the - // sign of the numerator. - let num = b1 * c2 - b2 * c1; - const x = num < 0 ? (num - offset) / denom : (num + offset) / denom; - - num = a2 * c1 - a1 * c2; - const y = num < 0 ? (num - offset) / denom : (num + offset) / denom; - - return { x: x, y: y }; - } - - function sameSign(r1: number, r2: number) { - return r1 * r2 > 0; - } - const diamondIntersection = ( - bounds: { x: any; y: any; width: any; height: any }, - outsidePoint: { x: number; y: number }, - insidePoint: any - ) => { - const x1 = bounds.x; - const y1 = bounds.y; - - const w = bounds.width; //+ bounds.padding; - const h = bounds.height; // + bounds.padding; - - const polyPoints = [ - { x: x1, y: y1 - h / 2 }, - { x: x1 + w / 2, y: y1 }, - { x: x1, y: y1 + h / 2 }, - { x: x1 - w / 2, y: y1 }, - ]; - log.debug( - `APA16 diamondIntersection calc abc89: - outsidePoint: ${JSON.stringify(outsidePoint)} - insidePoint : ${JSON.stringify(insidePoint)} - node-bounds : x:${bounds.x} y:${bounds.y} w:${bounds.width} h:${bounds.height}`, - JSON.stringify(polyPoints) - ); - - const intersections = []; - - let minX = Number.POSITIVE_INFINITY; - let minY = Number.POSITIVE_INFINITY; - - polyPoints.forEach(function (entry) { - minX = Math.min(minX, entry.x); - minY = Math.min(minY, entry.y); - }); - - const left = x1 - w / 2 - minX; - const top = y1 - h / 2 - minY; - - for (let i = 0; i < polyPoints.length; i++) { - const p1 = polyPoints[i]; - const p2 = polyPoints[i < polyPoints.length - 1 ? i + 1 : 0]; - const intersect = intersectLine( - bounds, - outsidePoint, - { x: left + p1.x, y: top + p1.y }, - { x: left + p2.x, y: top + p2.y } - ); - - if (intersect) { - intersections.push(intersect); - } - } - - if (!intersections.length) { - return bounds; - } - - log.debug('UIO intersections', intersections); - - if (intersections.length > 1) { - // More intersections, find the one nearest to edge end point - intersections.sort(function (p, q) { - const pdx = p.x - outsidePoint.x; - const pdy = p.y - outsidePoint.y; - const distp = Math.sqrt(pdx * pdx + pdy * pdy); - - const qdx = q.x - outsidePoint.x; - const qdy = q.y - outsidePoint.y; - const distq = Math.sqrt(qdx * qdx + qdy * qdy); - - return distp < distq ? -1 : distp === distq ? 0 : 1; - }); - } - - return intersections[0]; - }; - - const intersection = ( - node: { x: any; y: any; width: number; height: number }, - outsidePoint: { x: number; y: number }, - insidePoint: { x: number; y: number } - ) => { - log.debug(`intersection calc abc89: - outsidePoint: ${JSON.stringify(outsidePoint)} - insidePoint : ${JSON.stringify(insidePoint)} - node : x:${node.x} y:${node.y} w:${node.width} h:${node.height}`); - const x = node.x; - const y = node.y; - - const dx = Math.abs(x - insidePoint.x); - // const dy = Math.abs(y - insidePoint.y); - const w = node.width / 2; - let r = insidePoint.x < outsidePoint.x ? w - dx : w + dx; - const h = node.height / 2; - - const Q = Math.abs(outsidePoint.y - insidePoint.y); - const R = Math.abs(outsidePoint.x - insidePoint.x); - - if (Math.abs(y - outsidePoint.y) * w > Math.abs(x - outsidePoint.x) * h) { - // Intersection is top or bottom of rect. - const q = insidePoint.y < outsidePoint.y ? outsidePoint.y - h - y : y - h - outsidePoint.y; - r = (R * q) / Q; - const res = { - x: insidePoint.x < outsidePoint.x ? insidePoint.x + r : insidePoint.x - R + r, - y: insidePoint.y < outsidePoint.y ? insidePoint.y + Q - q : insidePoint.y - Q + q, - }; - - if (r === 0) { - res.x = outsidePoint.x; - res.y = outsidePoint.y; - } - if (R === 0) { - res.x = outsidePoint.x; - } - if (Q === 0) { - res.y = outsidePoint.y; - } - - log.debug(`abc89 topp/bott calc, Q ${Q}, q ${q}, R ${R}, r ${r}`, res); // cspell: disable-line - - return res; - } else { - // Intersection on sides of rect - if (insidePoint.x < outsidePoint.x) { - r = outsidePoint.x - w - x; - } else { - // r = outsidePoint.x - w - x; - r = x - w - outsidePoint.x; - } - const q = (Q * r) / R; - // OK let _x = insidePoint.x < outsidePoint.x ? insidePoint.x + R - r : insidePoint.x + dx - w; - // OK let _x = insidePoint.x < outsidePoint.x ? insidePoint.x + R - r : outsidePoint.x + r; - let _x = insidePoint.x < outsidePoint.x ? insidePoint.x + R - r : insidePoint.x - R + r; - // let _x = insidePoint.x < outsidePoint.x ? insidePoint.x + R - r : outsidePoint.x + r; - let _y = insidePoint.y < outsidePoint.y ? insidePoint.y + q : insidePoint.y - q; - log.debug(`sides calc abc89, Q ${Q}, q ${q}, R ${R}, r ${r}`, { _x, _y }); - if (r === 0) { - _x = outsidePoint.x; - _y = outsidePoint.y; - } - if (R === 0) { - _x = outsidePoint.x; - } - if (Q === 0) { - _y = outsidePoint.y; - } - - return { x: _x, y: _y }; - } - }; - const outsideNode = ( - node: { x: any; y: any; width: number; height: number }, - point: { x: number; y: number } - ) => { - const x = node.x; - const y = node.y; - const dx = Math.abs(point.x - x); - const dy = Math.abs(point.y - y); - const w = node.width / 2; - const h = node.height / 2; - if (dx >= w || dy >= h) { - return true; - } - return false; - }; - /** - * This function will page a path and node where the last point(s) in the path is inside the node - * and return an update path ending by the border of the node. - */ - const cutPathAtIntersect = ( - _points: any[], - bounds: { x: any; y: any; width: any; height: any; padding: any }, - isDiamond: boolean - ) => { - log.debug('APA18 cutPathAtIntersect Points:', _points, 'node:', bounds, 'isDiamond', isDiamond); - const points: any[] = []; - let lastPointOutside = _points[0]; - let isInside = false; - _points.forEach((point: any) => { - // check if point is inside the boundary rect - if (!outsideNode(bounds, point) && !isInside) { - // First point inside the rect found - // Calc the intersection coord between the point and the last point outside the rect - let inter; - - if (isDiamond) { - const inter2 = diamondIntersection(bounds, lastPointOutside, point); - const distance = Math.sqrt( - (lastPointOutside.x - inter2.x) ** 2 + (lastPointOutside.y - inter2.y) ** 2 - ); - if (distance > 1) { - inter = inter2; - } - } - if (!inter) { - inter = intersection(bounds, lastPointOutside, point); - } - - // Check case where the intersection is the same as the last point - let pointPresent = false; - points.forEach((p) => { - pointPresent = pointPresent || (p.x === inter.x && p.y === inter.y); - }); - // if (!pointPresent) { - if (!points.some((e) => e.x === inter.x && e.y === inter.y)) { - points.push(inter); - } else { - log.debug('abc88 no intersect', inter, points); - } - // points.push(inter); - isInside = true; - } else { - // Outside - log.debug('abc88 outside', point, lastPointOutside, points); - lastPointOutside = point; - // points.push(point); - if (!isInside) { - points.push(point); - } - } - }); - return points; - }; - // @ts-ignore - ELK is not typed const elk = new ELK(); const element = svg.select('g'); @@ -766,7 +495,10 @@ export const render = async ( id: 'root', layoutOptions: { 'elk.hierarchyHandling': 'INCLUDE_CHILDREN', - 'elk.layered.crossingMinimization.forceNodeModelOrder': true, + 'elk.layered.crossingMinimization.forceNodeModelOrder': + data4Layout.config.elk?.forceNodeModelOrder, + 'elk.layered.considerModelOrder.strategy': data4Layout.config.elk?.considerModelOrder, + 'elk.algorithm': algorithm, 'nodePlacement.strategy': data4Layout.config.elk?.nodePlacementStrategy, 'elk.layered.mergeEdges': data4Layout.config.elk?.mergeEdges, @@ -866,11 +598,16 @@ export const render = async ( delete node.height; } }); - elkGraph.edges.forEach((edge: any) => { + log.debug('APA01 processing edges, count:', elkGraph.edges.length); + elkGraph.edges.forEach((edge: any, index: number) => { + log.debug('APA01 processing edge', index, ':', edge); const source = edge.sources[0]; const target = edge.targets[0]; + log.debug('APA01 source:', source, 'target:', target); + log.debug('APA01 nodeDb[source]:', nodeDb[source]); + log.debug('APA01 nodeDb[target]:', nodeDb[target]); - if (nodeDb[source].parentId !== nodeDb[target].parentId) { + if (nodeDb[source] && nodeDb[target] && nodeDb[source].parentId !== nodeDb[target].parentId) { const ancestorId = findCommonAncestor(source, target, parentLookupDb); // an edge that breaks a subgraph has been identified, set configuration accordingly setIncludeChildrenPolicy(source, ancestorId); @@ -878,7 +615,37 @@ export const render = async ( } }); - const g = await elk.layout(elkGraph); + log.debug('APA01 before'); + log.debug('APA01 elkGraph structure:', JSON.stringify(elkGraph, null, 2)); + log.debug('APA01 elkGraph.children length:', elkGraph.children?.length); + log.debug('APA01 elkGraph.edges length:', elkGraph.edges?.length); + + // Validate that all edge references exist as nodes + elkGraph.edges?.forEach((edge: any, index: number) => { + log.debug(`APA01 validating edge ${index}:`, edge); + if (edge.sources) { + edge.sources.forEach((sourceId: any) => { + const sourceExists = elkGraph.children?.some((child: any) => child.id === sourceId); + log.debug(`APA01 source ${sourceId} exists:`, sourceExists); + }); + } + if (edge.targets) { + edge.targets.forEach((targetId: any) => { + const targetExists = elkGraph.children?.some((child: any) => child.id === targetId); + log.debug(`APA01 target ${targetId} exists:`, targetExists); + }); + } + }); + + let g; + try { + g = await elk.layout(elkGraph); + log.debug('APA01 after - success'); + log.debug('APA01 layout result:', JSON.stringify(g, null, 2)); + } catch (error) { + log.error('APA01 ELK layout error:', error); + throw error; + } // debugger; await drawNodes(0, 0, g.children, svg, subGraphsEl, 0); @@ -966,42 +733,37 @@ export const render = async ( startNode.innerHTML ); } - if (startNode.shape === 'diamond' || startNode.shape === 'diam') { - edge.points.unshift({ - x: startNode.offset.posX + startNode.width / 2, - y: startNode.offset.posY + startNode.height / 2, - }); - } - if (endNode.shape === 'diamond' || endNode.shape === 'diam') { - edge.points.push({ - x: endNode.offset.posX + endNode.width / 2, - y: endNode.offset.posY + endNode.height / 2, - }); - } - edge.points = cutPathAtIntersect( - edge.points.reverse(), - { - x: startNode.offset.posX + startNode.width / 2, - y: startNode.offset.posY + startNode.height / 2, - width: sw, - height: startNode.height, - padding: startNode.padding, - }, - startNode.shape === 'diamond' || startNode.shape === 'diam' - ).reverse(); + if (startNode.calcIntersect) { + const intersection = startNode.calcIntersect( + { + x: startNode.offset.posX + startNode.width / 2, + y: startNode.offset.posY + startNode.height / 2, + width: startNode.width, + height: startNode.height, + }, + edge.points[0] + ); - edge.points = cutPathAtIntersect( - edge.points, - { - x: endNode.offset.posX + endNode.width / 2, - y: endNode.offset.posY + endNode.height / 2, - width: ew, - height: endNode.height, - padding: endNode.padding, - }, - endNode.shape === 'diamond' || endNode.shape === 'diam' - ); + if (distance(intersection, edge.points[0]) > epsilon) { + edge.points.unshift(intersection); + } + } + if (endNode.calcIntersect) { + const intersection = endNode.calcIntersect( + { + x: endNode.offset.posX + endNode.width / 2, + y: endNode.offset.posY + endNode.height / 2, + width: endNode.width, + height: endNode.height, + }, + edge.points[edge.points.length - 1] + ); + + if (distance(intersection, edge.points[edge.points.length - 1]) > epsilon) { + edge.points.push(intersection); + } + } const paths = insertEdge( edgesEl, @@ -1012,7 +774,6 @@ export const render = async ( endNode, data4Layout.diagramId ); - log.info('APA12 edge points after insert', JSON.stringify(edge.points)); edge.x = edge.labels[0].x + offset.x + edge.labels[0].width / 2; edge.y = edge.labels[0].y + offset.y + edge.labels[0].height / 2; diff --git a/packages/mermaid-layout-elk/tsconfig.json b/packages/mermaid-layout-elk/tsconfig.json index 0d701cede..8f83e2bad 100644 --- a/packages/mermaid-layout-elk/tsconfig.json +++ b/packages/mermaid-layout-elk/tsconfig.json @@ -5,6 +5,6 @@ "outDir": "./dist", "types": ["vitest/importMeta", "vitest/globals"] }, - "include": ["./src/**/*.ts"], + "include": ["./src/**/*.ts", "./src/**/*.d.ts"], "typeRoots": ["./src/types"] } diff --git a/packages/mermaid-layout-tidy-tree/README.md b/packages/mermaid-layout-tidy-tree/README.md new file mode 100644 index 000000000..e8ae05f4c --- /dev/null +++ b/packages/mermaid-layout-tidy-tree/README.md @@ -0,0 +1,59 @@ +# @mermaid-js/layout-tidy-tree + +This package provides a bidirectional tidy tree layout engine for Mermaid based on the non-layered-tidy-tree-layout algorithm. + +> [!NOTE] +> The Tidy Tree Layout engine will not be available in all providers that support mermaid by default. +> The websites will have to install the @mermaid-js/layout-tidy-tree package to use the Tidy Tree layout engine. + +## Usage + +``` +--- +config: + layout: tidy-tree +--- +mindmap +root((mindmap)) + A + B +``` + +### With bundlers + +```sh +npm install @mermaid-js/layout-tidy-tree +``` + +```ts +import mermaid from 'mermaid'; +import tidyTreeLayouts from '@mermaid-js/layout-tidy-tree'; + +mermaid.registerLayoutLoaders(tidyTreeLayouts); +``` + +### With CDN + +```html + +``` + +## Tidy Tree Layout Overview + +tidy-tree: The bidirectional tidy tree layout + +The bidirectional tidy tree layout algorithm creates two separate trees that grow horizontally in opposite directions from a central root node: +Left tree: grows horizontally to the left (children alternate: 1st, 3rd, 5th...) +Right tree: grows horizontally to the right (children alternate: 2nd, 4th, 6th...) + +This creates a balanced, symmetric layout that is ideal for mindmaps, organizational charts, and other tree-based diagrams. + +Layout Structure: +[Child 3] ← [Child 1] ← [Root] → [Child 2] → [Child 4] +↓ ↓ ↓ ↓ +[GrandChild] [GrandChild] [GrandChild] [GrandChild] diff --git a/packages/mermaid-layout-tidy-tree/package.json b/packages/mermaid-layout-tidy-tree/package.json new file mode 100644 index 000000000..d8c3ed965 --- /dev/null +++ b/packages/mermaid-layout-tidy-tree/package.json @@ -0,0 +1,46 @@ +{ + "name": "@mermaid-js/layout-tidy-tree", + "version": "0.1.0", + "description": "Tidy-tree layout engine for mermaid", + "module": "dist/mermaid-layout-tidy-tree.core.mjs", + "types": "dist/layouts.d.ts", + "type": "module", + "exports": { + ".": { + "import": "./dist/mermaid-layout-tidy-tree.core.mjs", + "types": "./dist/layouts.d.ts" + }, + "./": "./" + }, + "keywords": [ + "diagram", + "markdown", + "tidy-tree", + "mermaid", + "layout" + ], + "scripts": {}, + "repository": { + "type": "git", + "url": "https://github.com/mermaid-js/mermaid" + }, + "contributors": [ + "Knut Sveidqvist", + "Sidharth Vinod" + ], + "license": "MIT", + "dependencies": { + "d3": "^7.9.0", + "non-layered-tidy-tree-layout": "^2.0.2" + }, + "devDependencies": { + "@types/d3": "^7.4.3", + "mermaid": "workspace:^" + }, + "peerDependencies": { + "mermaid": "^11.0.2" + }, + "files": [ + "dist" + ] +} diff --git a/packages/mermaid-layout-tidy-tree/src/index.ts b/packages/mermaid-layout-tidy-tree/src/index.ts new file mode 100644 index 000000000..2be1b59e6 --- /dev/null +++ b/packages/mermaid-layout-tidy-tree/src/index.ts @@ -0,0 +1,50 @@ +/** + * Bidirectional Tidy-Tree Layout Algorithm for Generic Diagrams + * + * This module provides a layout algorithm implementation using the + * non-layered-tidy-tree-layout algorithm for positioning nodes and edges + * in tree structures with a bidirectional approach. + * + * The algorithm creates two separate trees that grow horizontally in opposite + * directions from a central root node: + * - Left tree: grows horizontally to the left (children alternate: 1st, 3rd, 5th...) + * - Right tree: grows horizontally to the right (children alternate: 2nd, 4th, 6th...) + * + * This creates a balanced, symmetric layout that is ideal for mindmaps, + * organizational charts, and other tree-based diagrams. + * + * The algorithm follows the unified rendering pattern and can be used + * by any diagram type that provides compatible LayoutData. + */ + +/** + * Render function for the bidirectional tidy-tree layout algorithm + * + * This function follows the unified rendering pattern used by all layout algorithms. + * It takes LayoutData, inserts nodes into DOM, runs the bidirectional tidy-tree layout algorithm, + * and renders the positioned elements to the SVG. + * + * Features: + * - Alternates root children between left and right trees + * - Left tree grows horizontally to the left (rotated 90° counterclockwise) + * - Right tree grows horizontally to the right (rotated 90° clockwise) + * - Uses tidy-tree algorithm for optimal spacing within each tree + * - Creates symmetric, balanced layouts + * - Maintains proper edge connections between all nodes + * + * Layout Structure: + * ``` + * [Child 3] ← [Child 1] ← [Root] → [Child 2] → [Child 4] + * ↓ ↓ ↓ ↓ + * [GrandChild] [GrandChild] [GrandChild] [GrandChild] + * ``` + * + * @param layoutData - Layout data containing nodes, edges, and configuration + * @param svg - SVG element to render to + * @param helpers - Internal helper functions for rendering + * @param options - Rendering options + */ +export { default } from './layouts.js'; +export * from './types.js'; +export * from './layout.js'; +export { render } from './render.js'; diff --git a/packages/mermaid-layout-tidy-tree/src/layout.test.ts b/packages/mermaid-layout-tidy-tree/src/layout.test.ts new file mode 100644 index 000000000..2b3b79b37 --- /dev/null +++ b/packages/mermaid-layout-tidy-tree/src/layout.test.ts @@ -0,0 +1,409 @@ +import { describe, it, expect, beforeEach, vi } from 'vitest'; +import { executeTidyTreeLayout, validateLayoutData } from './layout.js'; +import type { LayoutResult } from './types.js'; +import type { LayoutData, MermaidConfig } from 'mermaid'; + +// Mock non-layered-tidy-tree-layout +vi.mock('non-layered-tidy-tree-layout', () => ({ + BoundingBox: vi.fn().mockImplementation(() => ({})), + Layout: vi.fn().mockImplementation(() => ({ + layout: vi.fn().mockImplementation((treeData) => { + const result = { ...treeData }; + + if (result.id?.toString().startsWith('virtual-root')) { + result.x = 0; + result.y = 0; + } else { + result.x = 100; + result.y = 50; + } + + if (result.children) { + result.children.forEach((child: any, index: number) => { + child.x = 50 + index * 100; + child.y = 100; + + if (child.children) { + child.children.forEach((grandchild: any, gIndex: number) => { + grandchild.x = 25 + gIndex * 50; + grandchild.y = 200; + }); + } + }); + } + + return { + result, + boundingBox: { + left: 0, + right: 200, + top: 0, + bottom: 250, + }, + }; + }), + })), +})); + +describe('Tidy-Tree Layout Algorithm', () => { + let mockConfig: MermaidConfig; + let mockLayoutData: LayoutData; + + beforeEach(() => { + mockConfig = { + theme: 'default', + } as MermaidConfig; + + mockLayoutData = { + nodes: [ + { + id: 'root', + label: 'Root', + isGroup: false, + shape: 'rect', + width: 100, + height: 50, + padding: 10, + x: 0, + y: 0, + cssClasses: '', + cssStyles: [], + look: 'default', + }, + { + id: 'child1', + label: 'Child 1', + isGroup: false, + shape: 'rect', + width: 80, + height: 40, + padding: 10, + x: 0, + y: 0, + cssClasses: '', + cssStyles: [], + look: 'default', + }, + { + id: 'child2', + label: 'Child 2', + isGroup: false, + shape: 'rect', + width: 80, + height: 40, + padding: 10, + x: 0, + y: 0, + cssClasses: '', + cssStyles: [], + look: 'default', + }, + { + id: 'child3', + label: 'Child 3', + isGroup: false, + shape: 'rect', + width: 80, + height: 40, + padding: 10, + x: 0, + y: 0, + cssClasses: '', + cssStyles: [], + look: 'default', + }, + { + id: 'child4', + label: 'Child 4', + isGroup: false, + shape: 'rect', + width: 80, + height: 40, + padding: 10, + x: 0, + y: 0, + cssClasses: '', + cssStyles: [], + look: 'default', + }, + ], + edges: [ + { + id: 'root_child1', + start: 'root', + end: 'child1', + type: 'edge', + classes: '', + style: [], + animate: false, + arrowTypeEnd: 'arrow_point', + arrowTypeStart: 'none', + }, + { + id: 'root_child2', + start: 'root', + end: 'child2', + type: 'edge', + classes: '', + style: [], + animate: false, + arrowTypeEnd: 'arrow_point', + arrowTypeStart: 'none', + }, + { + id: 'root_child3', + start: 'root', + end: 'child3', + type: 'edge', + classes: '', + style: [], + animate: false, + arrowTypeEnd: 'arrow_point', + arrowTypeStart: 'none', + }, + { + id: 'root_child4', + start: 'root', + end: 'child4', + type: 'edge', + classes: '', + style: [], + animate: false, + arrowTypeEnd: 'arrow_point', + arrowTypeStart: 'none', + }, + ], + config: mockConfig, + direction: 'TB', + type: 'test', + diagramId: 'test-diagram', + markers: [], + }; + }); + + describe('validateLayoutData', () => { + it('should validate correct layout data', () => { + expect(() => validateLayoutData(mockLayoutData)).not.toThrow(); + }); + + it('should throw error for missing data', () => { + expect(() => validateLayoutData(null as any)).toThrow('Layout data is required'); + }); + + it('should throw error for missing config', () => { + const invalidData = { ...mockLayoutData, config: null as any }; + expect(() => validateLayoutData(invalidData)).toThrow('Configuration is required'); + }); + + it('should throw error for invalid nodes array', () => { + const invalidData = { ...mockLayoutData, nodes: null as any }; + expect(() => validateLayoutData(invalidData)).toThrow('Nodes array is required'); + }); + + it('should throw error for invalid edges array', () => { + const invalidData = { ...mockLayoutData, edges: null as any }; + expect(() => validateLayoutData(invalidData)).toThrow('Edges array is required'); + }); + }); + + describe('executeTidyTreeLayout function', () => { + it('should execute layout algorithm successfully', async () => { + const result: LayoutResult = await executeTidyTreeLayout(mockLayoutData); + + expect(result).toBeDefined(); + expect(result.nodes).toBeDefined(); + expect(result.edges).toBeDefined(); + expect(Array.isArray(result.nodes)).toBe(true); + expect(Array.isArray(result.edges)).toBe(true); + }); + + it('should return positioned nodes with coordinates', async () => { + const result: LayoutResult = await executeTidyTreeLayout(mockLayoutData); + + expect(result.nodes.length).toBeGreaterThan(0); + result.nodes.forEach((node) => { + expect(node.x).toBeDefined(); + expect(node.y).toBeDefined(); + expect(typeof node.x).toBe('number'); + expect(typeof node.y).toBe('number'); + }); + }); + + it('should return positioned edges with coordinates', async () => { + const result: LayoutResult = await executeTidyTreeLayout(mockLayoutData); + + expect(result.edges.length).toBeGreaterThan(0); + result.edges.forEach((edge) => { + expect(edge.startX).toBeDefined(); + expect(edge.startY).toBeDefined(); + expect(edge.midX).toBeDefined(); + expect(edge.midY).toBeDefined(); + expect(edge.endX).toBeDefined(); + expect(edge.endY).toBeDefined(); + }); + }); + + it('should handle empty layout data gracefully', async () => { + const emptyData: LayoutData = { + ...mockLayoutData, + nodes: [], + edges: [], + }; + + await expect(executeTidyTreeLayout(emptyData)).rejects.toThrow( + 'No nodes found in layout data' + ); + }); + + it('should throw error for missing nodes', async () => { + const invalidData = { ...mockLayoutData, nodes: [] }; + + await expect(executeTidyTreeLayout(invalidData)).rejects.toThrow( + 'No nodes found in layout data' + ); + }); + + it('should handle empty edges (single node tree)', async () => { + const singleNodeData = { + ...mockLayoutData, + edges: [], + nodes: [mockLayoutData.nodes[0]], + }; + + const result = await executeTidyTreeLayout(singleNodeData); + expect(result).toBeDefined(); + expect(result.nodes).toHaveLength(1); + expect(result.edges).toHaveLength(0); + }); + + it('should create bidirectional dual-tree layout with alternating left/right children', async () => { + const result = await executeTidyTreeLayout(mockLayoutData); + + expect(result).toBeDefined(); + expect(result.nodes).toHaveLength(5); + + const rootNode = result.nodes.find((node) => node.id === 'root'); + expect(rootNode).toBeDefined(); + expect(rootNode!.x).toBe(0); + expect(rootNode!.y).toBe(20); + + const child1 = result.nodes.find((node) => node.id === 'child1'); + const child2 = result.nodes.find((node) => node.id === 'child2'); + const child3 = result.nodes.find((node) => node.id === 'child3'); + const child4 = result.nodes.find((node) => node.id === 'child4'); + + expect(child1).toBeDefined(); + expect(child2).toBeDefined(); + expect(child3).toBeDefined(); + expect(child4).toBeDefined(); + + expect(child1!.x).toBeLessThan(rootNode!.x); + expect(child2!.x).toBeGreaterThan(rootNode!.x); + expect(child3!.x).toBeLessThan(rootNode!.x); + expect(child4!.x).toBeGreaterThan(rootNode!.x); + + expect(child1!.x).toBeLessThan(-100); + expect(child3!.x).toBeLessThan(-100); + + expect(child2!.x).toBeGreaterThan(100); + expect(child4!.x).toBeGreaterThan(100); + }); + + it('should correctly transpose coordinates to prevent high nodes from covering nodes above them', async () => { + const testData = { + ...mockLayoutData, + nodes: [ + { + id: 'root', + label: 'Root', + isGroup: false, + shape: 'rect' as const, + width: 100, + height: 50, + padding: 10, + x: 0, + y: 0, + cssClasses: '', + cssStyles: [], + look: 'default', + }, + { + id: 'tall-child', + label: 'Tall Child', + isGroup: false, + shape: 'rect' as const, + width: 80, + height: 120, + padding: 10, + x: 0, + y: 0, + cssClasses: '', + cssStyles: [], + look: 'default', + }, + { + id: 'short-child', + label: 'Short Child', + isGroup: false, + shape: 'rect' as const, + width: 80, + height: 30, + padding: 10, + x: 0, + y: 0, + cssClasses: '', + cssStyles: [], + look: 'default', + }, + ], + edges: [ + { + id: 'root_tall', + start: 'root', + end: 'tall-child', + type: 'edge', + classes: '', + style: [], + animate: false, + arrowTypeEnd: 'arrow_point', + arrowTypeStart: 'none', + }, + { + id: 'root_short', + start: 'root', + end: 'short-child', + type: 'edge', + classes: '', + style: [], + animate: false, + arrowTypeEnd: 'arrow_point', + arrowTypeStart: 'none', + }, + ], + }; + + const result = await executeTidyTreeLayout(testData); + + expect(result).toBeDefined(); + expect(result.nodes).toHaveLength(3); + + const rootNode = result.nodes.find((node) => node.id === 'root'); + const tallChild = result.nodes.find((node) => node.id === 'tall-child'); + const shortChild = result.nodes.find((node) => node.id === 'short-child'); + + expect(rootNode).toBeDefined(); + expect(tallChild).toBeDefined(); + expect(shortChild).toBeDefined(); + + expect(tallChild!.x).not.toBe(shortChild!.x); + + expect(tallChild!.width).toBe(80); + expect(tallChild!.height).toBe(120); + expect(shortChild!.width).toBe(80); + expect(shortChild!.height).toBe(30); + + const yDifference = Math.abs(tallChild!.y - shortChild!.y); + expect(yDifference).toBeGreaterThanOrEqual(0); + }); + }); +}); diff --git a/packages/mermaid-layout-tidy-tree/src/layout.ts b/packages/mermaid-layout-tidy-tree/src/layout.ts new file mode 100644 index 000000000..6cc06a9ab --- /dev/null +++ b/packages/mermaid-layout-tidy-tree/src/layout.ts @@ -0,0 +1,629 @@ +import type { LayoutData } from 'mermaid'; +import type { Bounds, Point } from 'mermaid/src/types.js'; +import { BoundingBox, Layout } from 'non-layered-tidy-tree-layout'; +import type { + Edge, + LayoutResult, + Node, + PositionedEdge, + PositionedNode, + TidyTreeNode, +} from './types.js'; + +/** + * Execute the tidy-tree layout algorithm on generic layout data + * + * This function takes layout data and uses the non-layered-tidy-tree-layout + * algorithm to calculate optimal node positions for tree structures. + * + * @param data - The layout data containing nodes, edges, and configuration + * @param config - Mermaid configuration object + * @returns Promise resolving to layout result with positioned nodes and edges + */ +export function executeTidyTreeLayout(data: LayoutData): Promise { + let intersectionShift = 50; + + return new Promise((resolve, reject) => { + try { + if (!data.nodes || !Array.isArray(data.nodes) || data.nodes.length === 0) { + throw new Error('No nodes found in layout data'); + } + + if (!data.edges || !Array.isArray(data.edges)) { + data.edges = []; + } + + const { leftTree, rightTree, rootNode } = convertToDualTreeFormat(data); + + const gap = 20; + const bottomPadding = 40; + intersectionShift = 30; + + const bb = new BoundingBox(gap, bottomPadding); + const layout = new Layout(bb); + + let leftResult = null; + let rightResult = null; + + if (leftTree) { + const leftLayoutResult = layout.layout(leftTree); + leftResult = leftLayoutResult.result; + } + + if (rightTree) { + const rightLayoutResult = layout.layout(rightTree); + rightResult = rightLayoutResult.result; + } + + const positionedNodes = combineAndPositionTrees(rootNode, leftResult, rightResult); + const positionedEdges = calculateEdgePositions( + data.edges, + positionedNodes, + intersectionShift + ); + resolve({ + nodes: positionedNodes, + edges: positionedEdges, + }); + } catch (error) { + reject(error); + } + }); +} + +/** + * Convert LayoutData to dual-tree format (left and right trees) + * + * This function builds two separate tree structures from the nodes and edges, + * alternating children between left and right trees. + */ +function convertToDualTreeFormat(data: LayoutData): { + leftTree: TidyTreeNode | null; + rightTree: TidyTreeNode | null; + rootNode: TidyTreeNode; +} { + const { nodes, edges } = data; + + const nodeMap = new Map(); + nodes.forEach((node) => nodeMap.set(node.id, node)); + + const children = new Map(); + const parents = new Map(); + + edges.forEach((edge) => { + const parentId = edge.start; + const childId = edge.end; + + if (parentId && childId) { + if (!children.has(parentId)) { + children.set(parentId, []); + } + children.get(parentId)!.push(childId); + parents.set(childId, parentId); + } + }); + + const rootNodeData = nodes.find((node) => !parents.has(node.id)); + if (!rootNodeData && nodes.length === 0) { + throw new Error('No nodes available to create tree'); + } + + const actualRoot = rootNodeData ?? nodes[0]; + + const rootNode: TidyTreeNode = { + id: actualRoot.id, + width: actualRoot.width ?? 100, + height: actualRoot.height ?? 50, + _originalNode: actualRoot, + }; + + const rootChildren = children.get(actualRoot.id) ?? []; + const leftChildren: string[] = []; + const rightChildren: string[] = []; + + rootChildren.forEach((childId, index) => { + if (index % 2 === 0) { + leftChildren.push(childId); + } else { + rightChildren.push(childId); + } + }); + + const leftTree = leftChildren.length > 0 ? buildSubTree(leftChildren, children, nodeMap) : null; + + const rightTree = + rightChildren.length > 0 ? buildSubTree(rightChildren, children, nodeMap) : null; + + return { leftTree, rightTree, rootNode }; +} + +/** + * Build a subtree from a list of root children + * For horizontal trees, we need to transpose width/height since the tree will be rotated 90° + */ +function buildSubTree( + rootChildren: string[], + children: Map, + nodeMap: Map +): TidyTreeNode { + const virtualRoot: TidyTreeNode = { + id: `virtual-root-${Math.random()}`, + width: 1, + height: 1, + children: rootChildren + .map((childId) => nodeMap.get(childId)) + .filter((child): child is Node => child !== undefined) + .map((child) => convertNodeToTidyTreeTransposed(child, children, nodeMap)), + }; + + return virtualRoot; +} + +/** + * Recursively convert a node and its children to tidy-tree format + * This version transposes width/height for horizontal tree layout + */ +function convertNodeToTidyTreeTransposed( + node: Node, + children: Map, + nodeMap: Map +): TidyTreeNode { + const childIds = children.get(node.id) ?? []; + const childNodes = childIds + .map((childId) => nodeMap.get(childId)) + .filter((child): child is Node => child !== undefined) + .map((child) => convertNodeToTidyTreeTransposed(child, children, nodeMap)); + + return { + id: node.id, + width: node.height ?? 50, + height: node.width ?? 100, + children: childNodes.length > 0 ? childNodes : undefined, + _originalNode: node, + }; +} +/** + * Combine and position the left and right trees around the root node + * Creates a bidirectional layout where left tree grows left and right tree grows right + */ +function combineAndPositionTrees( + rootNode: TidyTreeNode, + leftResult: TidyTreeNode | null, + rightResult: TidyTreeNode | null +): PositionedNode[] { + const positionedNodes: PositionedNode[] = []; + + const rootX = 0; + const rootY = 0; + + const treeSpacing = rootNode.width / 2 + 30; + const leftTreeNodes: PositionedNode[] = []; + const rightTreeNodes: PositionedNode[] = []; + + if (leftResult?.children) { + positionLeftTreeBidirectional(leftResult.children, leftTreeNodes, rootX - treeSpacing, rootY); + } + + if (rightResult?.children) { + positionRightTreeBidirectional( + rightResult.children, + rightTreeNodes, + rootX + treeSpacing, + rootY + ); + } + + let leftTreeCenterY = 0; + let rightTreeCenterY = 0; + + if (leftTreeNodes.length > 0) { + const leftTreeXPositions = [...new Set(leftTreeNodes.map((node) => node.x))].sort( + (a, b) => b - a + ); + const firstLevelLeftX = leftTreeXPositions[0]; + const firstLevelLeftNodes = leftTreeNodes.filter((node) => node.x === firstLevelLeftX); + + if (firstLevelLeftNodes.length > 0) { + const leftMinY = Math.min( + ...firstLevelLeftNodes.map((node) => node.y - (node.height ?? 50) / 2) + ); + const leftMaxY = Math.max( + ...firstLevelLeftNodes.map((node) => node.y + (node.height ?? 50) / 2) + ); + leftTreeCenterY = (leftMinY + leftMaxY) / 2; + } + } + + if (rightTreeNodes.length > 0) { + const rightTreeXPositions = [...new Set(rightTreeNodes.map((node) => node.x))].sort( + (a, b) => a - b + ); + const firstLevelRightX = rightTreeXPositions[0]; + const firstLevelRightNodes = rightTreeNodes.filter((node) => node.x === firstLevelRightX); + + if (firstLevelRightNodes.length > 0) { + const rightMinY = Math.min( + ...firstLevelRightNodes.map((node) => node.y - (node.height ?? 50) / 2) + ); + const rightMaxY = Math.max( + ...firstLevelRightNodes.map((node) => node.y + (node.height ?? 50) / 2) + ); + rightTreeCenterY = (rightMinY + rightMaxY) / 2; + } + } + + const leftTreeOffset = -leftTreeCenterY; + const rightTreeOffset = -rightTreeCenterY; + + positionedNodes.push({ + id: String(rootNode.id), + x: rootX, + y: rootY + 20, + section: 'root', + width: rootNode._originalNode?.width ?? rootNode.width, + height: rootNode._originalNode?.height ?? rootNode.height, + originalNode: rootNode._originalNode, + }); + + const leftTreeNodesWithOffset = leftTreeNodes.map((node) => ({ + id: node.id, + x: node.x - (node.width ?? 0) / 2, + y: node.y + leftTreeOffset + (node.height ?? 0) / 2, + section: 'left' as const, + width: node.width, + height: node.height, + originalNode: node.originalNode, + })); + + const rightTreeNodesWithOffset = rightTreeNodes.map((node) => ({ + id: node.id, + x: node.x + (node.width ?? 0) / 2, + y: node.y + rightTreeOffset + (node.height ?? 0) / 2, + section: 'right' as const, + width: node.width, + height: node.height, + originalNode: node.originalNode, + })); + + positionedNodes.push(...leftTreeNodesWithOffset); + positionedNodes.push(...rightTreeNodesWithOffset); + + return positionedNodes; +} + +/** + * Position nodes from the left tree in a bidirectional layout (grows to the left) + * Rotates the tree 90 degrees counterclockwise so it grows horizontally to the left + */ +function positionLeftTreeBidirectional( + nodes: TidyTreeNode[], + positionedNodes: PositionedNode[], + offsetX: number, + offsetY: number +): void { + nodes.forEach((node) => { + const distanceFromRoot = node.y ?? 0; + const verticalPosition = node.x ?? 0; + + const originalWidth = node._originalNode?.width ?? 100; + const originalHeight = node._originalNode?.height ?? 50; + + const adjustedY = offsetY + verticalPosition; + + positionedNodes.push({ + id: String(node.id), + x: offsetX - distanceFromRoot, + y: adjustedY, + width: originalWidth, + height: originalHeight, + originalNode: node._originalNode, + }); + + if (node.children) { + positionLeftTreeBidirectional(node.children, positionedNodes, offsetX, offsetY); + } + }); +} + +/** + * Position nodes from the right tree in a bidirectional layout (grows to the right) + * Rotates the tree 90 degrees clockwise so it grows horizontally to the right + */ +function positionRightTreeBidirectional( + nodes: TidyTreeNode[], + positionedNodes: PositionedNode[], + offsetX: number, + offsetY: number +): void { + nodes.forEach((node) => { + const distanceFromRoot = node.y ?? 0; + const verticalPosition = node.x ?? 0; + + const originalWidth = node._originalNode?.width ?? 100; + const originalHeight = node._originalNode?.height ?? 50; + + const adjustedY = offsetY + verticalPosition; + + positionedNodes.push({ + id: String(node.id), + x: offsetX + distanceFromRoot, + y: adjustedY, + width: originalWidth, + height: originalHeight, + originalNode: node._originalNode, + }); + + if (node.children) { + positionRightTreeBidirectional(node.children, positionedNodes, offsetX, offsetY); + } + }); +} + +/** + * Calculate the intersection point of a line with a circle + * @param circle - Circle coordinates and radius + * @param lineStart - Starting point of the line + * @param lineEnd - Ending point of the line + * @returns The intersection point + */ +function computeCircleEdgeIntersection(circle: Bounds, lineStart: Point, lineEnd: Point): Point { + const radius = Math.min(circle.width, circle.height) / 2; + + const dx = lineEnd.x - lineStart.x; + const dy = lineEnd.y - lineStart.y; + const length = Math.sqrt(dx * dx + dy * dy); + + if (length === 0) { + return lineStart; + } + + const nx = dx / length; + const ny = dy / length; + + return { + x: circle.x - nx * radius, + y: circle.y - ny * radius, + }; +} + +function intersection(node: PositionedNode, outsidePoint: Point, insidePoint: Point): Point { + const x = node.x; + const y = node.y; + + if (!node.width || !node.height) { + return { x: outsidePoint.x, y: outsidePoint.y }; + } + const dx = Math.abs(x - insidePoint.x); + const w = node?.width / 2; + let r = insidePoint.x < outsidePoint.x ? w - dx : w + dx; + const h = node.height / 2; + + const Q = Math.abs(outsidePoint.y - insidePoint.y); + const R = Math.abs(outsidePoint.x - insidePoint.x); + + if (Math.abs(y - outsidePoint.y) * w > Math.abs(x - outsidePoint.x) * h) { + // Intersection is top or bottom of rect. + const q = insidePoint.y < outsidePoint.y ? outsidePoint.y - h - y : y - h - outsidePoint.y; + r = (R * q) / Q; + const res = { + x: insidePoint.x < outsidePoint.x ? insidePoint.x + r : insidePoint.x - R + r, + y: insidePoint.y < outsidePoint.y ? insidePoint.y + Q - q : insidePoint.y - Q + q, + }; + + if (r === 0) { + res.x = outsidePoint.x; + res.y = outsidePoint.y; + } + if (R === 0) { + res.x = outsidePoint.x; + } + if (Q === 0) { + res.y = outsidePoint.y; + } + + return res; + } else { + if (insidePoint.x < outsidePoint.x) { + r = outsidePoint.x - w - x; + } else { + r = x - w - outsidePoint.x; + } + const q = (Q * r) / R; + let _x = insidePoint.x < outsidePoint.x ? insidePoint.x + R - r : insidePoint.x - R + r; + let _y = insidePoint.y < outsidePoint.y ? insidePoint.y + q : insidePoint.y - q; + + if (r === 0) { + _x = outsidePoint.x; + _y = outsidePoint.y; + } + if (R === 0) { + _x = outsidePoint.x; + } + if (Q === 0) { + _y = outsidePoint.y; + } + + return { x: _x, y: _y }; + } +} + +/** + * Calculate edge positions based on positioned nodes + * Now includes tree membership and node dimensions for precise edge calculations + * Edges now stop at shape boundaries instead of extending to centers + */ +function calculateEdgePositions( + edges: Edge[], + positionedNodes: PositionedNode[], + intersectionShift: number +): PositionedEdge[] { + const nodeInfo = new Map(); + positionedNodes.forEach((node) => { + nodeInfo.set(node.id, node); + }); + + return edges.map((edge) => { + const sourceNode = nodeInfo.get(edge.start ?? ''); + const targetNode = nodeInfo.get(edge.end ?? ''); + + if (!sourceNode || !targetNode) { + return { + id: edge.id, + source: edge.start ?? '', + target: edge.end ?? '', + startX: 0, + startY: 0, + midX: 0, + midY: 0, + endX: 0, + endY: 0, + points: [{ x: 0, y: 0 }], + sourceSection: undefined, + targetSection: undefined, + sourceWidth: undefined, + sourceHeight: undefined, + targetWidth: undefined, + targetHeight: undefined, + }; + } + + const sourceCenter = { x: sourceNode.x, y: sourceNode.y }; + const targetCenter = { x: targetNode.x, y: targetNode.y }; + + const isSourceRound = ['circle', 'cloud', 'bang'].includes( + sourceNode.originalNode?.shape ?? '' + ); + const isTargetRound = ['circle', 'cloud', 'bang'].includes( + targetNode.originalNode?.shape ?? '' + ); + + let startPos = isSourceRound + ? computeCircleEdgeIntersection( + { + x: sourceNode.x, + y: sourceNode.y, + width: sourceNode.width ?? 100, + height: sourceNode.height ?? 100, + }, + targetCenter, + sourceCenter + ) + : intersection(sourceNode, sourceCenter, targetCenter); + + let endPos = isTargetRound + ? computeCircleEdgeIntersection( + { + x: targetNode.x, + y: targetNode.y, + width: targetNode.width ?? 100, + height: targetNode.height ?? 100, + }, + sourceCenter, + targetCenter + ) + : intersection(targetNode, targetCenter, sourceCenter); + + const midX = (startPos.x + endPos.x) / 2; + const midY = (startPos.y + endPos.y) / 2; + + const points = [startPos]; + if (sourceNode.section === 'left') { + points.push({ + x: sourceNode.x - (sourceNode.width ?? 0) / 2 - intersectionShift, + y: sourceNode.y, + }); + } else if (sourceNode.section === 'right') { + points.push({ + x: sourceNode.x + (sourceNode.width ?? 0) / 2 + intersectionShift, + y: sourceNode.y, + }); + } + if (targetNode.section === 'left') { + points.push({ + x: targetNode.x + (targetNode.width ?? 0) / 2 + intersectionShift, + y: targetNode.y, + }); + } else if (targetNode.section === 'right') { + points.push({ + x: targetNode.x - (targetNode.width ?? 0) / 2 - intersectionShift, + y: targetNode.y, + }); + } + + points.push(endPos); + + const secondPoint = points.length > 1 ? points[1] : targetCenter; + startPos = isSourceRound + ? computeCircleEdgeIntersection( + { + x: sourceNode.x, + y: sourceNode.y, + width: sourceNode.width ?? 100, + height: sourceNode.height ?? 100, + }, + secondPoint, + sourceCenter + ) + : intersection(sourceNode, secondPoint, sourceCenter); + points[0] = startPos; + + const secondLastPoint = points.length > 1 ? points[points.length - 2] : sourceCenter; + endPos = isTargetRound + ? computeCircleEdgeIntersection( + { + x: targetNode.x, + y: targetNode.y, + width: targetNode.width ?? 100, + height: targetNode.height ?? 100, + }, + secondLastPoint, + targetCenter + ) + : intersection(targetNode, secondLastPoint, targetCenter); + points[points.length - 1] = endPos; + + return { + id: edge.id, + source: edge.start ?? '', + target: edge.end ?? '', + startX: startPos.x, + startY: startPos.y, + midX, + midY, + endX: endPos.x, + endY: endPos.y, + points, + sourceSection: sourceNode?.section, + targetSection: targetNode?.section, + sourceWidth: sourceNode?.width, + sourceHeight: sourceNode?.height, + targetWidth: targetNode?.width, + targetHeight: targetNode?.height, + }; + }); +} + +/** + * Validate layout data structure + * @param data - The data to validate + * @returns True if data is valid, throws error otherwise + */ +export function validateLayoutData(data: LayoutData): boolean { + if (!data) { + throw new Error('Layout data is required'); + } + + if (!data.config) { + throw new Error('Configuration is required in layout data'); + } + + if (!Array.isArray(data.nodes)) { + throw new Error('Nodes array is required in layout data'); + } + + if (!Array.isArray(data.edges)) { + throw new Error('Edges array is required in layout data'); + } + + return true; +} diff --git a/packages/mermaid-layout-tidy-tree/src/layouts.ts b/packages/mermaid-layout-tidy-tree/src/layouts.ts new file mode 100644 index 000000000..d5eac8992 --- /dev/null +++ b/packages/mermaid-layout-tidy-tree/src/layouts.ts @@ -0,0 +1,13 @@ +import type { LayoutLoaderDefinition } from 'mermaid'; + +const loader = async () => await import(`./render.js`); + +const tidyTreeLayout: LayoutLoaderDefinition[] = [ + { + name: 'tidy-tree', + loader, + algorithm: 'tidy-tree', + }, +]; + +export default tidyTreeLayout; diff --git a/packages/mermaid-layout-tidy-tree/src/non-layered-tidy-tree-layout.d.ts b/packages/mermaid-layout-tidy-tree/src/non-layered-tidy-tree-layout.d.ts new file mode 100644 index 000000000..248b5c05f --- /dev/null +++ b/packages/mermaid-layout-tidy-tree/src/non-layered-tidy-tree-layout.d.ts @@ -0,0 +1,18 @@ +declare module 'non-layered-tidy-tree-layout' { + export class BoundingBox { + constructor(gap: number, bottomPadding: number); + } + + export class Layout { + constructor(boundingBox: BoundingBox); + layout(data: any): { + result: any; + boundingBox: { + left: number; + right: number; + top: number; + bottom: number; + }; + }; + } +} diff --git a/packages/mermaid-layout-tidy-tree/src/render.ts b/packages/mermaid-layout-tidy-tree/src/render.ts new file mode 100644 index 000000000..4ce5e1deb --- /dev/null +++ b/packages/mermaid-layout-tidy-tree/src/render.ts @@ -0,0 +1,180 @@ +import type { InternalHelpers, LayoutData, RenderOptions, SVG } from 'mermaid'; +import { executeTidyTreeLayout } from './layout.js'; + +interface NodeWithPosition { + id: string; + x?: number; + y?: number; + width?: number; + height?: number; + domId?: any; + [key: string]: any; +} + +/** + * Render function for bidirectional tidy-tree layout algorithm + * + * This follows the same pattern as ELK and dagre renderers: + * 1. Insert nodes into DOM to get their actual dimensions + * 2. Run the bidirectional tidy-tree layout algorithm to calculate positions + * 3. Position the nodes and edges based on layout results + * + * The bidirectional layout creates two trees that grow horizontally in opposite + * directions from a central root node: + * - Left tree: grows horizontally to the left (children: 1st, 3rd, 5th...) + * - Right tree: grows horizontally to the right (children: 2nd, 4th, 6th...) + */ +export const render = async ( + data4Layout: LayoutData, + svg: SVG, + { + insertCluster, + insertEdge, + insertEdgeLabel, + insertMarkers, + insertNode, + log, + positionEdgeLabel, + }: InternalHelpers, + { algorithm: _algorithm }: RenderOptions +) => { + const nodeDb: Record = {}; + const clusterDb: Record = {}; + + const element = svg.select('g'); + insertMarkers(element, data4Layout.markers, data4Layout.type, data4Layout.diagramId); + + const subGraphsEl = element.insert('g').attr('class', 'subgraphs'); + const edgePaths = element.insert('g').attr('class', 'edgePaths'); + const edgeLabels = element.insert('g').attr('class', 'edgeLabels'); + const nodes = element.insert('g').attr('class', 'nodes'); + // Step 1: Insert nodes into DOM to get their actual dimensions + log.debug('Inserting nodes into DOM for dimension calculation'); + + await Promise.all( + data4Layout.nodes.map(async (node) => { + if (node.isGroup) { + const clusterNode: NodeWithPosition = { + ...node, + id: node.id, + width: node.width, + height: node.height, + }; + clusterDb[node.id] = clusterNode; + nodeDb[node.id] = clusterNode; + + await insertCluster(subGraphsEl, node); + } else { + const nodeWithPosition: NodeWithPosition = { + ...node, + id: node.id, + width: node.width, + height: node.height, + }; + nodeDb[node.id] = nodeWithPosition; + + const nodeEl = await insertNode(nodes, node, { + config: data4Layout.config, + dir: data4Layout.direction || 'TB', + }); + + const boundingBox = nodeEl.node()!.getBBox(); + nodeWithPosition.width = boundingBox.width; + nodeWithPosition.height = boundingBox.height; + nodeWithPosition.domId = nodeEl; + + log.debug(`Node ${node.id} dimensions: ${boundingBox.width}x${boundingBox.height}`); + } + }) + ); + // Step 2: Run the bidirectional tidy-tree layout algorithm + log.debug('Running bidirectional tidy-tree layout algorithm'); + + const updatedLayoutData = { + ...data4Layout, + nodes: data4Layout.nodes.map((node) => { + const nodeWithDimensions = nodeDb[node.id]; + return { + ...node, + width: nodeWithDimensions.width ?? node.width ?? 100, + height: nodeWithDimensions.height ?? node.height ?? 50, + }; + }), + }; + + const layoutResult = await executeTidyTreeLayout(updatedLayoutData); + // Step 3: Position the nodes based on bidirectional layout results + log.debug('Positioning nodes based on bidirectional layout results'); + + layoutResult.nodes.forEach((positionedNode) => { + const node = nodeDb[positionedNode.id]; + if (node?.domId) { + // Position the node at the calculated coordinates from bidirectional layout + // The layout algorithm has already calculated positions for: + // - Root node at center (0, 0) + // - Left tree nodes with negative x coordinates (growing left) + // - Right tree nodes with positive x coordinates (growing right) + node.domId.attr('transform', `translate(${positionedNode.x}, ${positionedNode.y})`); + // Store the final position + node.x = positionedNode.x; + node.y = positionedNode.y; + // Step 3: Position the nodes based on bidirectional layout results + log.debug(`Positioned node ${node.id} at (${positionedNode.x}, ${positionedNode.y})`); + } + }); + + log.debug('Inserting and positioning edges'); + + await Promise.all( + data4Layout.edges.map(async (edge) => { + await insertEdgeLabel(edgeLabels, edge); + + const startNode = nodeDb[edge.start ?? '']; + const endNode = nodeDb[edge.end ?? '']; + + if (startNode && endNode) { + const positionedEdge = layoutResult.edges.find((e) => e.id === edge.id); + + if (positionedEdge) { + log.debug('APA01 positionedEdge', positionedEdge); + const edgeWithPath = { + ...edge, + points: positionedEdge.points, + }; + const paths = insertEdge( + edgePaths, + edgeWithPath, + clusterDb, + data4Layout.type, + startNode, + endNode, + data4Layout.diagramId + ); + + positionEdgeLabel(edgeWithPath, paths); + } else { + const edgeWithPath = { + ...edge, + points: [ + { x: startNode.x ?? 0, y: startNode.y ?? 0 }, + { x: endNode.x ?? 0, y: endNode.y ?? 0 }, + ], + }; + + const paths = insertEdge( + edgePaths, + edgeWithPath, + clusterDb, + data4Layout.type, + startNode, + endNode, + data4Layout.diagramId + ); + positionEdgeLabel(edgeWithPath, paths); + } + } + }) + ); + + log.debug('Bidirectional tidy-tree rendering completed'); +}; diff --git a/packages/mermaid-layout-tidy-tree/src/types.ts b/packages/mermaid-layout-tidy-tree/src/types.ts new file mode 100644 index 000000000..2015a4909 --- /dev/null +++ b/packages/mermaid-layout-tidy-tree/src/types.ts @@ -0,0 +1,69 @@ +import type { LayoutData } from 'mermaid'; + +export type Node = LayoutData['nodes'][number]; +export type Edge = LayoutData['edges'][number]; + +/** + * Positioned node after layout calculation + */ +export interface PositionedNode { + id: string; + x: number; + y: number; + section?: 'root' | 'left' | 'right'; + width?: number; + height?: number; + originalNode?: Node; + [key: string]: unknown; +} + +/** + * Positioned edge after layout calculation + */ +export interface PositionedEdge { + id: string; + source: string; + target: string; + startX: number; + startY: number; + midX: number; + midY: number; + endX: number; + endY: number; + sourceSection?: 'root' | 'left' | 'right'; + targetSection?: 'root' | 'left' | 'right'; + sourceWidth?: number; + sourceHeight?: number; + targetWidth?: number; + targetHeight?: number; + [key: string]: unknown; +} + +/** + * Result of layout algorithm execution + */ +export interface LayoutResult { + nodes: PositionedNode[]; + edges: PositionedEdge[]; +} + +/** + * Tidy-tree node structure compatible with non-layered-tidy-tree-layout + */ +export interface TidyTreeNode { + id: string | number; + width: number; + height: number; + x?: number; + y?: number; + children?: TidyTreeNode[]; + _originalNode?: Node; +} + +/** + * Tidy-tree layout configuration + */ +export interface TidyTreeLayoutConfig { + gap: number; + bottomPadding: number; +} diff --git a/packages/mermaid-layout-tidy-tree/tsconfig.json b/packages/mermaid-layout-tidy-tree/tsconfig.json new file mode 100644 index 000000000..8f83e2bad --- /dev/null +++ b/packages/mermaid-layout-tidy-tree/tsconfig.json @@ -0,0 +1,10 @@ +{ + "extends": "../../tsconfig.json", + "compilerOptions": { + "rootDir": "./src", + "outDir": "./dist", + "types": ["vitest/importMeta", "vitest/globals"] + }, + "include": ["./src/**/*.ts", "./src/**/*.d.ts"], + "typeRoots": ["./src/types"] +} diff --git a/packages/mermaid-zenuml/CHANGELOG.md b/packages/mermaid-zenuml/CHANGELOG.md index 57e8795a4..a7fe35c78 100644 --- a/packages/mermaid-zenuml/CHANGELOG.md +++ b/packages/mermaid-zenuml/CHANGELOG.md @@ -1,5 +1,14 @@ # @mermaid-js/mermaid-zenuml +## 0.2.2 + +### Patch Changes + +- [#6798](https://github.com/mermaid-js/mermaid/pull/6798) [`3ffe961`](https://github.com/mermaid-js/mermaid/commit/3ffe9618aebc9ac96de6e3c826481f542f18c2a9) Thanks [@MrCoder](https://github.com/MrCoder)! - Fixed a critical bug that the ZenUML diagram is not rendered. + +- Updated dependencies [[`b9ef683`](https://github.com/mermaid-js/mermaid/commit/b9ef683fb67b8959abc455d6cc5266c37ba435f6), [`2c0931d`](https://github.com/mermaid-js/mermaid/commit/2c0931da46794b49d2523211e25f782900c34e94), [`33e08da`](https://github.com/mermaid-js/mermaid/commit/33e08daf175125295a06b1b80279437004a4e865), [`814b68b`](https://github.com/mermaid-js/mermaid/commit/814b68b4a94813f7c6b3d7fb4559532a7bab2652), [`fce7cab`](https://github.com/mermaid-js/mermaid/commit/fce7cabb71d68a20a66246fe23d066512126a412), [`fc07f0d`](https://github.com/mermaid-js/mermaid/commit/fc07f0d8abca49e4f887d7457b7b94fb07d1e3da), [`12e01bd`](https://github.com/mermaid-js/mermaid/commit/12e01bdb5cacf3569133979a5a4f1d8973e9aec1), [`01aaef3`](https://github.com/mermaid-js/mermaid/commit/01aaef39b4a1ec8bc5a0c6bfa3a20b712d67f4dc), [`daf8d8d`](https://github.com/mermaid-js/mermaid/commit/daf8d8d3befcd600618a629977b76463b38d0ad9), [`c36cd05`](https://github.com/mermaid-js/mermaid/commit/c36cd05c45ac3090181152b4dae41f8d7b569bd6), [`8bb29fc`](https://github.com/mermaid-js/mermaid/commit/8bb29fc879329ad109898e4025b4f4eba2ab0649), [`71b04f9`](https://github.com/mermaid-js/mermaid/commit/71b04f93b07f876df2b30656ef36036c1d0e4e4f), [`c99bce6`](https://github.com/mermaid-js/mermaid/commit/c99bce6bab4c7ce0b81b66d44f44853ce4aeb1c3), [`6cc1926`](https://github.com/mermaid-js/mermaid/commit/6cc192680a2531cab28f87a8061a53b786e010f3), [`9da6fb3`](https://github.com/mermaid-js/mermaid/commit/9da6fb39ae278401771943ac85d6d1b875f78cf1), [`e48b0ba`](https://github.com/mermaid-js/mermaid/commit/e48b0ba61dab7f95aa02da603b5b7d383b894932), [`4d62d59`](https://github.com/mermaid-js/mermaid/commit/4d62d5963238400270e9314c6e4d506f48147074), [`e9ce8cf`](https://github.com/mermaid-js/mermaid/commit/e9ce8cf4da9062d85098042044822100889bb0dd), [`9258b29`](https://github.com/mermaid-js/mermaid/commit/9258b2933bbe1ef41087345ffea3731673671c49), [`da90f67`](https://github.com/mermaid-js/mermaid/commit/da90f6760b6efb0da998bcb63b75eecc29e06c08), [`0133f1c`](https://github.com/mermaid-js/mermaid/commit/0133f1c0c5cff4fc4c8e0b99e9cf0b3d49dcbe71), [`895f9d4`](https://github.com/mermaid-js/mermaid/commit/895f9d43ff98ca05ebfba530789f677f31a011ff)]: + - mermaid@11.10.0 + ## 0.2.1 ### Patch Changes diff --git a/packages/mermaid-zenuml/README.md b/packages/mermaid-zenuml/README.md deleted file mode 120000 index 4300aecbe..000000000 --- a/packages/mermaid-zenuml/README.md +++ /dev/null @@ -1 +0,0 @@ -../mermaid/src/docs/syntax/zenuml.md diff --git a/packages/mermaid-zenuml/README.md b/packages/mermaid-zenuml/README.md new file mode 100644 index 000000000..b26295807 --- /dev/null +++ b/packages/mermaid-zenuml/README.md @@ -0,0 +1,384 @@ +# @mermaid-js/mermaid-zenuml + +MermaidJS plugin for ZenUML integration - A powerful sequence diagram rendering engine. + +> A Sequence diagram is an interaction diagram that shows how processes operate with one another and in what order. + +Mermaid can render sequence diagrams with [ZenUML](https://zenuml.com). Note that ZenUML uses a different +syntax than the original Sequence Diagram in mermaid. + +```mermaid +zenuml + BookLibService.Borrow(id) { + User = Session.GetUser() + if(User.isActive) { + try { + BookRepository.Update(id, onLoan, User) + receipt = new Receipt(id, dueDate) + } catch (BookNotFoundException) { + ErrorService.onException(BookNotFoundException) + } finally { + Connection.close() + } + } + return receipt + } +``` + +## Installation + +### With bundlers + +```sh +npm install @mermaid-js/mermaid-zenuml +``` + +```ts +import mermaid from 'mermaid'; +import zenuml from '@mermaid-js/mermaid-zenuml'; + +await mermaid.registerExternalDiagrams([zenuml]); +``` + +### With CDN + +```html + +``` + +> [!NOTE] +> ZenUML uses experimental lazy loading & async rendering features which could change in the future. + +## Basic Usage + +Once the plugin is registered, you can create ZenUML diagrams using the `zenuml` syntax: + +```mermaid +zenuml + Controller.Get(id) { + Service.Get(id) { + item = Repository.Get(id) + if(item) { + return item + } else { + return null + } + } + return result + } +``` + +## ZenUML Syntax Reference + +### Participants + +The participants can be defined implicitly as in the first example on this page. The participants or actors are +rendered in order of appearance in the diagram source text. Sometimes you might want to show the participants in a +different order than how they appear in the first message. It is possible to specify the actor's order of +appearance by doing the following: + +```mermaid +zenuml + title Declare participant (optional) + Bob + Alice + Alice->Bob: Hi Bob + Bob->Alice: Hi Alice +``` + +### Annotators + +If you specifically want to use symbols instead of just rectangles with text you can do so by using the annotator syntax to declare participants as per below. + +```mermaid +zenuml + title Annotators + @Actor Alice + @Database Bob + Alice->Bob: Hi Bob + Bob->Alice: Hi Alice +``` + +Available annotators include: + +- `@Actor` - Human figure +- `@Database` - Database symbol +- `@Boundary` - Boundary symbol +- `@Control` - Control symbol +- `@Entity` - Entity symbol +- `@Queue` - Queue symbol + +### Aliases + +The participants can have a convenient identifier and a descriptive label. + +```mermaid +zenuml + title Aliases + A as Alice + J as John + A->J: Hello John, how are you? + J->A: Great! +``` + +## Messages + +Messages can be one of: + +1. Sync message +2. Async message +3. Creation message +4. Reply message + +### Sync message + +You can think of a sync (blocking) method in a programming language. + +```mermaid +zenuml + title Sync message + A.SyncMessage + A.SyncMessage(with, parameters) { + B.nestedSyncMessage() + } +``` + +### Async message + +You can think of an async (non-blocking) method in a programming language. Fire an event and forget about it. + +```mermaid +zenuml + title Async message + Alice->Bob: How are you? +``` + +### Creation message + +We use `new` keyword to create an object. + +```mermaid +zenuml + new A1 + new A2(with, parameters) +``` + +### Reply message + +There are three ways to express a reply message: + +```mermaid +zenuml + // 1. assign a variable from a sync message. + a = A.SyncMessage() + + // 1.1. optionally give the variable a type + SomeType a = A.SyncMessage() + + // 2. use return keyword + A.SyncMessage() { + return result + } + + // 3. use @return or @reply annotator on an async message + @return + A->B: result +``` + +The third way `@return` is rarely used, but it is useful when you want to return to one level up. + +```mermaid +zenuml + title Reply message + Client->A.method() { + B.method() { + if(condition) { + return x1 + // return early + @return + A->Client: x11 + } + } + return x2 + } +``` + +## Advanced Features + +### Nesting + +Sync messages and Creation messages are naturally nestable with `{}`. + +```mermaid +zenuml + A.method() { + B.nested_sync_method() + B->C: nested async message + } +``` + +### Comments + +It is possible to add comments to a sequence diagram with `// comment` syntax. +Comments will be rendered above the messages or fragments. Comments on other places +are ignored. Markdown is supported. + +```mermaid +zenuml + // a comment on a participant will not be rendered + BookService + // a comment on a message. + // **Markdown** is supported. + BookService.getBook() +``` + +### Loops + +It is possible to express loops in a ZenUML diagram. This is done by any of the +following notations: + +1. while +2. for +3. forEach, foreach +4. loop + +```zenuml +while(condition) { + ...statements... +} +``` + +Example: + +```mermaid +zenuml + Alice->John: Hello John, how are you? + while(true) { + John->Alice: Great! + } +``` + +### Alt (Alternative paths) + +It is possible to express alternative paths in a sequence diagram. This is done by the notation + +```zenuml +if(condition1) { + ...statements... +} else if(condition2) { + ...statements... +} else { + ...statements... +} +``` + +Example: + +```mermaid +zenuml + Alice->Bob: Hello Bob, how are you? + if(is_sick) { + Bob->Alice: Not so good :( + } else { + Bob->Alice: Feeling fresh like a daisy + } +``` + +### Opt (Optional) + +It is possible to render an `opt` fragment. This is done by the notation + +```zenuml +opt { + ...statements... +} +``` + +Example: + +```mermaid +zenuml + Alice->Bob: Hello Bob, how are you? + Bob->Alice: Not so good :( + opt { + Bob->Alice: Thanks for asking + } +``` + +### Parallel + +It is possible to show actions that are happening in parallel. + +This is done by the notation + +```zenuml +par { + statement1 + statement2 + statement3 +} +``` + +Example: + +```mermaid +zenuml + par { + Alice->Bob: Hello guys! + Alice->John: Hello guys! + } +``` + +### Try/Catch/Finally (Break) + +It is possible to indicate a stop of the sequence within the flow (usually used to model exceptions). + +This is done by the notation + +``` +try { + ...statements... +} catch { + ...statements... +} finally { + ...statements... +} +``` + +Example: + +```mermaid +zenuml + try { + Consumer->API: Book something + API->BookingService: Start booking process + } catch { + API->Consumer: show failure + } finally { + API->BookingService: rollback status + } +``` + +## Contributing + +This package is part of the [Mermaid](https://github.com/mermaid-js/mermaid) project. See the main repository for contributing guidelines. + +## Contributors + +- [Peng Xiao](https://github.com/MrCoder) +- [Sidharth Vinod](https://sidharth.dev) +- [Dong Cai](https://github.com/dontry) + +## License + +MIT + +## Links + +- [ZenUML Official Website](https://zenuml.com) +- [Mermaid Documentation](https://mermaid.js.org) +- [GitHub Repository](https://github.com/mermaid-js/mermaid) diff --git a/packages/mermaid-zenuml/package.json b/packages/mermaid-zenuml/package.json index d3a76e797..cc9ce0d4a 100644 --- a/packages/mermaid-zenuml/package.json +++ b/packages/mermaid-zenuml/package.json @@ -1,6 +1,6 @@ { "name": "@mermaid-js/mermaid-zenuml", - "version": "0.2.1", + "version": "0.2.2", "description": "MermaidJS plugin for ZenUML integration", "module": "dist/mermaid-zenuml.core.mjs", "types": "dist/detector.d.ts", @@ -33,7 +33,7 @@ ], "license": "MIT", "dependencies": { - "@zenuml/core": "^3.31.1" + "@zenuml/core": "^3.35.2" }, "devDependencies": { "mermaid": "workspace:^" diff --git a/packages/mermaid-zenuml/src/zenuml.d.ts b/packages/mermaid-zenuml/src/zenuml.d.ts new file mode 100644 index 000000000..eac411bd2 --- /dev/null +++ b/packages/mermaid-zenuml/src/zenuml.d.ts @@ -0,0 +1,11 @@ +declare module '@zenuml/core' { + interface RenderOptions { + theme?: string; + mode?: string; + } + + export default class ZenUml { + constructor(container: Element); + render(text: string, options?: RenderOptions): Promise; + } +} diff --git a/packages/mermaid-zenuml/src/zenumlRenderer.ts b/packages/mermaid-zenuml/src/zenumlRenderer.ts index f9dd57996..42ec8fcb4 100644 --- a/packages/mermaid-zenuml/src/zenumlRenderer.ts +++ b/packages/mermaid-zenuml/src/zenumlRenderer.ts @@ -53,7 +53,6 @@ export const draw = async function (text: string, id: string) { const { foreignObject, container, app } = createForeignObject(id); svgContainer.appendChild(foreignObject); - // @ts-expect-error @zenuml/core@3.0.0 exports the wrong type for ZenUml const zenuml = new ZenUml(app); // default is a theme name. More themes to be added and will be configurable in the future await zenuml.render(text, { theme: 'default', mode: 'static' }); diff --git a/packages/mermaid/CHANGELOG.md b/packages/mermaid/CHANGELOG.md index c57e2a6db..fc2f97fdf 100644 --- a/packages/mermaid/CHANGELOG.md +++ b/packages/mermaid/CHANGELOG.md @@ -1,5 +1,95 @@ # mermaid +## 11.10.0 + +### Minor Changes + +- [#6744](https://github.com/mermaid-js/mermaid/pull/6744) [`daf8d8d`](https://github.com/mermaid-js/mermaid/commit/daf8d8d3befcd600618a629977b76463b38d0ad9) Thanks [@SpecularAura](https://github.com/SpecularAura)! - feat: Added support for per link curve styling in flowchart diagram using edge ids + +### Patch Changes + +- [#6857](https://github.com/mermaid-js/mermaid/pull/6857) [`b9ef683`](https://github.com/mermaid-js/mermaid/commit/b9ef683fb67b8959abc455d6cc5266c37ba435f6) Thanks [@knsv](https://github.com/knsv)! - feat: Exposing elk configuration forceNodeModelOrder and considerModelOrder to the mermaid configuration + +- [#6653](https://github.com/mermaid-js/mermaid/pull/6653) [`2c0931d`](https://github.com/mermaid-js/mermaid/commit/2c0931da46794b49d2523211e25f782900c34e94) Thanks [@darshanr0107](https://github.com/darshanr0107)! - chore: Remove the "-beta" suffix from the XYChart, Block, Sankey diagrams to reflect their stable status + +- [#6683](https://github.com/mermaid-js/mermaid/pull/6683) [`33e08da`](https://github.com/mermaid-js/mermaid/commit/33e08daf175125295a06b1b80279437004a4e865) Thanks [@darshanr0107](https://github.com/darshanr0107)! - fix: Position the edge label in state diagram correctly relative to the edge + +- [#6693](https://github.com/mermaid-js/mermaid/pull/6693) [`814b68b`](https://github.com/mermaid-js/mermaid/commit/814b68b4a94813f7c6b3d7fb4559532a7bab2652) Thanks [@darshanr0107](https://github.com/darshanr0107)! - fix: Apply correct dateFormat in Gantt chart to show only day when specified + +- [#6734](https://github.com/mermaid-js/mermaid/pull/6734) [`fce7cab`](https://github.com/mermaid-js/mermaid/commit/fce7cabb71d68a20a66246fe23d066512126a412) Thanks [@darshanr0107](https://github.com/darshanr0107)! - fix: handle exclude dates properly in Gantt charts when using dateFormat: 'YYYY-MM-DD HH:mm:ss' + +- [#6733](https://github.com/mermaid-js/mermaid/pull/6733) [`fc07f0d`](https://github.com/mermaid-js/mermaid/commit/fc07f0d8abca49e4f887d7457b7b94fb07d1e3da) Thanks [@omkarht](https://github.com/omkarht)! - fix: fixed connection gaps in flowchart for roundedRect, stadium and diamond shape + +- [#6876](https://github.com/mermaid-js/mermaid/pull/6876) [`12e01bd`](https://github.com/mermaid-js/mermaid/commit/12e01bdb5cacf3569133979a5a4f1d8973e9aec1) Thanks [@sidharthv96](https://github.com/sidharthv96)! - fix: sanitize icon labels and icon SVGs + + Resolves CVE-2025-54880 reported by @fourcube + +- [#6801](https://github.com/mermaid-js/mermaid/pull/6801) [`01aaef3`](https://github.com/mermaid-js/mermaid/commit/01aaef39b4a1ec8bc5a0c6bfa3a20b712d67f4dc) Thanks [@sidharthv96](https://github.com/sidharthv96)! - fix: Update casing of ID in requirement diagram + +- [#6796](https://github.com/mermaid-js/mermaid/pull/6796) [`c36cd05`](https://github.com/mermaid-js/mermaid/commit/c36cd05c45ac3090181152b4dae41f8d7b569bd6) Thanks [@HashanCP](https://github.com/HashanCP)! - fix: Make flowchart elk detector regex match less greedy + +- [#6702](https://github.com/mermaid-js/mermaid/pull/6702) [`8bb29fc`](https://github.com/mermaid-js/mermaid/commit/8bb29fc879329ad109898e4025b4f4eba2ab0649) Thanks [@qraqras](https://github.com/qraqras)! - fix(block): overflowing blocks no longer affect later lines + + This may change the layout of block diagrams that have overflowing lines + (i.e. block diagrams that use up more columns that the `columns` specifier). + +- [#6717](https://github.com/mermaid-js/mermaid/pull/6717) [`71b04f9`](https://github.com/mermaid-js/mermaid/commit/71b04f93b07f876df2b30656ef36036c1d0e4e4f) Thanks [@darshanr0107](https://github.com/darshanr0107)! - fix: log warning for blocks exceeding column width + + This update adds a validation check that logs a warning message when a block's width exceeds the defined column layout. + +- [#6820](https://github.com/mermaid-js/mermaid/pull/6820) [`c99bce6`](https://github.com/mermaid-js/mermaid/commit/c99bce6bab4c7ce0b81b66d44f44853ce4aeb1c3) Thanks [@kriss-u](https://github.com/kriss-u)! - fix: Add escaped class literal name on namespace + +- [#6332](https://github.com/mermaid-js/mermaid/pull/6332) [`6cc1926`](https://github.com/mermaid-js/mermaid/commit/6cc192680a2531cab28f87a8061a53b786e010f3) Thanks [@ajuckel](https://github.com/ajuckel)! - fix: Allow equals sign in sequenceDiagram labels + +- [#6651](https://github.com/mermaid-js/mermaid/pull/6651) [`9da6fb3`](https://github.com/mermaid-js/mermaid/commit/9da6fb39ae278401771943ac85d6d1b875f78cf1) Thanks [@darshanr0107](https://github.com/darshanr0107)! - Add validation for negative values in pie charts: + + Prevents crashes during parsing by validating values post-parsing. + + Provides clearer, user-friendly error messages for invalid negative inputs. + +- [#6803](https://github.com/mermaid-js/mermaid/pull/6803) [`e48b0ba`](https://github.com/mermaid-js/mermaid/commit/e48b0ba61dab7f95aa02da603b5b7d383b894932) Thanks [@omkarht](https://github.com/omkarht)! - chore: migrate to class-based ArchitectureDB implementation + +- [#6838](https://github.com/mermaid-js/mermaid/pull/6838) [`4d62d59`](https://github.com/mermaid-js/mermaid/commit/4d62d5963238400270e9314c6e4d506f48147074) Thanks [@saurabhg772244](https://github.com/saurabhg772244)! - fix: node border style for handdrawn shapes + +- [#6739](https://github.com/mermaid-js/mermaid/pull/6739) [`e9ce8cf`](https://github.com/mermaid-js/mermaid/commit/e9ce8cf4da9062d85098042044822100889bb0dd) Thanks [@kriss-u](https://github.com/kriss-u)! - fix: Update flowchart direction TD's behavior to be the same as TB + +- [#6833](https://github.com/mermaid-js/mermaid/pull/6833) [`9258b29`](https://github.com/mermaid-js/mermaid/commit/9258b2933bbe1ef41087345ffea3731673671c49) Thanks [@darshanr0107](https://github.com/darshanr0107)! - fix: correctly render non-directional lines for '---' in block diagrams + +- [#6855](https://github.com/mermaid-js/mermaid/pull/6855) [`da90f67`](https://github.com/mermaid-js/mermaid/commit/da90f6760b6efb0da998bcb63b75eecc29e06c08) Thanks [@sidharthv96](https://github.com/sidharthv96)! - fix: fallback to raw text instead of rendering _Unsupported markdown_ or empty blocks + + Instead of printing **Unsupported markdown: XXX**, or empty blocks when using a markdown feature + that Mermaid does not yet support when `htmlLabels: true`(default) or `htmlLabels: false`, + fallback to the raw markdown text. + +- [#6876](https://github.com/mermaid-js/mermaid/pull/6876) [`0133f1c`](https://github.com/mermaid-js/mermaid/commit/0133f1c0c5cff4fc4c8e0b99e9cf0b3d49dcbe71) Thanks [@sidharthv96](https://github.com/sidharthv96)! - fix: sanitize KATEX blocks + + Resolves CVE-2025-54881 reported by @fourcube + +- [#6804](https://github.com/mermaid-js/mermaid/pull/6804) [`895f9d4`](https://github.com/mermaid-js/mermaid/commit/895f9d43ff98ca05ebfba530789f677f31a011ff) Thanks [@omkarht](https://github.com/omkarht)! - chore: Update packet diagram to use new class-based database structure + +## 11.9.0 + +### Minor Changes + +- [#6453](https://github.com/mermaid-js/mermaid/pull/6453) [`5acbd7e`](https://github.com/mermaid-js/mermaid/commit/5acbd7e762469d9d89a9c77faf6617ee13367f3a) Thanks [@sidharthv96](https://github.com/sidharthv96)! - feat: Add `getRegisteredDiagramsMetadata` to `mermaid`, which returns all the registered diagram IDs in mermaid + +### Patch Changes + +- [#6738](https://github.com/mermaid-js/mermaid/pull/6738) [`d90634b`](https://github.com/mermaid-js/mermaid/commit/d90634bf2b09e586b055729e07e9a1a31b21827c) Thanks [@shubham-mermaid](https://github.com/shubham-mermaid)! - chore: Updated TreeMapDB to use class based approach + +- [#6510](https://github.com/mermaid-js/mermaid/pull/6510) [`7a38eb7`](https://github.com/mermaid-js/mermaid/commit/7a38eb715d795cd5c66cb59357d64ec197b432e6) Thanks [@sidharthv96](https://github.com/sidharthv96)! - chore: Move packet diagram out of beta + +- [#6747](https://github.com/mermaid-js/mermaid/pull/6747) [`3e3ae08`](https://github.com/mermaid-js/mermaid/commit/3e3ae089305e1c7b9948b9e149eba6854fe7f2d6) Thanks [@darshanr0107](https://github.com/darshanr0107)! - fix: adjust sequence diagram title positioning to prevent overlap with top border in Safari + +- [#6751](https://github.com/mermaid-js/mermaid/pull/6751) [`d3e2be3`](https://github.com/mermaid-js/mermaid/commit/d3e2be35be066adeb7fd502b4a24c223c3b53947) Thanks [@darshanr0107](https://github.com/darshanr0107)! - chore: Update MindmapDB to use class based approach + +- [#6715](https://github.com/mermaid-js/mermaid/pull/6715) [`637680d`](https://github.com/mermaid-js/mermaid/commit/637680d4d9e39b4f8cb6f05b4cb261e8f5693ac3) Thanks [@Syn3ugar](https://github.com/Syn3ugar)! - fix(timeline): fix loading `leftMargin` from config + + The `timeline.leftMargin` config value should now correctly control the size of the left margin, instead of being ignored. + +- Updated dependencies [[`7a38eb7`](https://github.com/mermaid-js/mermaid/commit/7a38eb715d795cd5c66cb59357d64ec197b432e6)]: + - @mermaid-js/parser@0.6.2 + ## 11.8.1 ### Patch Changes @@ -139,7 +229,6 @@ - [#5999](https://github.com/mermaid-js/mermaid/pull/5999) [`742ad7c`](https://github.com/mermaid-js/mermaid/commit/742ad7c130964df1fb5544e909d9556081285f68) Thanks [@knsv](https://github.com/knsv)! - Adding Kanban board, a new diagram type - [#5880](https://github.com/mermaid-js/mermaid/pull/5880) [`bdf145f`](https://github.com/mermaid-js/mermaid/commit/bdf145ffe362462176d9c1e68d5f3ff5c9d962b0) Thanks [@yari-dewalt](https://github.com/yari-dewalt)! - Class diagram changes: - - Updates the class diagram to the new unified way of rendering. - Includes a new "classBox" shape to be used in diagrams - Other updates such as: @@ -258,3 +347,1005 @@ - Updated dependencies [[`5013484`](https://github.com/mermaid-js/mermaid/commit/50134849246141ec400e33e08c12c10539b84de9)]: - @mermaid-js/parser@0.1.0 + +## [10.0.0](https://github.com/mermaid-js/mermaid/releases/tag/v10.0.0) + +### Mermaid is ESM only! + +We've dropped CJS support. So, you will have to update your import scripts as follows. + +```html + +``` + +You can keep using v9 by adding the `@9` in the CDN URL. + +```diff +- ++ +``` + +### mermaid.render is async and doesn't accept callbacks + +```js +// < v10 +mermaid.render('id', 'graph TD;\nA-->B', (svg, bindFunctions) => { + element.innerHTML = svg; + if (bindFunctions) { + bindFunctions(element); + } +}); + +// Shorter syntax +if (bindFunctions) { + bindFunctions(element); +} +// can be replaced with the `?.` shorthand +bindFunctions?.(element); + +// >= v10 with async/await +const { svg, bindFunctions } = await mermaid.render('id', 'graph TD;\nA-->B'); +element.innerHTML = svg; +bindFunctions?.(element); + +// >= v10 with promise.then +mermaid.render('id', 'graph TD;A-->B').then(({ svg, bindFunctions }) => { + element.innerHTML = svg; + bindFunctions?.(element); +}); +``` + +### mermaid.parse is async and ParseError is removed + +```js +// < v10 +mermaid.parse(text, parseError); + +//>= v10 +await mermaid.parse(text).catch(parseError); +// or +try { + await mermaid.parse(text); +} catch (err) { + parseError(err); +} +``` + +### Init deprecated and InitThrowsErrors removed + +The config passed to `init` was not being used earlier. +It will now be used. +The `init` function is deprecated and will be removed in the next major release. +init currently works as a wrapper to `initialize` and `run`. + +```js +// < v10 +mermaid.init(config, selector, cb); + +//>= v10 +mermaid.initialize(config); +mermaid.run({ + querySelector: selector, + postRenderCallback: cb, + suppressErrors: true, +}); +``` + +```js +// < v10 +mermaid.initThrowsErrors(config, selector, cb); + +//>= v10 +mermaid.initialize(config); +mermaid.run({ + querySelector: selector, + postRenderCallback: cb, + suppressErrors: false, +}); +``` + +// TODO: Populate changelog pre v10 + +- Config has a lot of changes +- globalReset resets to `defaultConfig` instead of current config. Use `reset` instead. + +## [Unreleased](https://github.com/knsv/mermaid/tree/HEAD) + +[Full Changelog](https://github.com/knsv/mermaid/compare/8.2.0...HEAD) + +**Closed issues:** + +- Cross-Site Scripting:DOM - Issue [\#847](https://github.com/knsv/mermaid/issues/847) + +## [8.2.0](https://github.com/knsv/mermaid/tree/8.2.0) (2019-07-17) + +[Full Changelog](https://github.com/knsv/mermaid/compare/8.1.0...8.2.0) + +**Closed issues:** + +- Create issue templates [\#871](https://github.com/knsv/mermaid/issues/871) +- cross site scripting in mermaid [\#869](https://github.com/knsv/mermaid/issues/869) +- Make Gantt chart date inclusive [\#868](https://github.com/knsv/mermaid/issues/868) +- CHANGELOG missing updates for all versions since 0.4.0 [\#865](https://github.com/knsv/mermaid/issues/865) +- please add tag for 8.0.0 release [\#863](https://github.com/knsv/mermaid/issues/863) +- classDiagram breaks on any edit [\#858](https://github.com/knsv/mermaid/issues/858) +- found 1 high severity vulnerability [\#839](https://github.com/knsv/mermaid/issues/839) +- Missing fontawesome icon support [\#830](https://github.com/knsv/mermaid/issues/830) +- Docs for integration with wiki.js? [\#829](https://github.com/knsv/mermaid/issues/829) +- Is this project still maintained? [\#826](https://github.com/knsv/mermaid/issues/826) +- typora [\#823](https://github.com/knsv/mermaid/issues/823) +- Maintain the order of the nodes in Flowchart [\#815](https://github.com/knsv/mermaid/issues/815) +- Overlap, Overflow and cut titles in flowchart [\#814](https://github.com/knsv/mermaid/issues/814) +- How load mermaidApi notejs electron [\#813](https://github.com/knsv/mermaid/issues/813) +- How to set the spacing between the text of the flowchart node and the border? [\#812](https://github.com/knsv/mermaid/issues/812) +- no triming participant name and the name following spaces is as another actor in sequence [\#809](https://github.com/knsv/mermaid/issues/809) +- uml Class as shape type [\#807](https://github.com/knsv/mermaid/issues/807) +- Force-directed graph Layout Style [\#806](https://github.com/knsv/mermaid/issues/806) +- how can I start a newLine in FlowChart [\#805](https://github.com/knsv/mermaid/issues/805) +- UOEProcessShow [\#801](https://github.com/knsv/mermaid/issues/801) +- Why the use of code blocks? [\#799](https://github.com/knsv/mermaid/issues/799) +- fixing class diagram [\#794](https://github.com/knsv/mermaid/issues/794) +- Autonumber support in sequence diagrams [\#782](https://github.com/knsv/mermaid/issues/782) +- MomentJS dependency [\#781](https://github.com/knsv/mermaid/issues/781) +- Feature : Can we color code the flow/arrows [\#766](https://github.com/knsv/mermaid/issues/766) +- Is there any way to convert flowchart.js code to mermaid code [\#726](https://github.com/knsv/mermaid/issues/726) +- Fixed width of nodes [\#653](https://github.com/knsv/mermaid/issues/653) +- Inline comment [\#650](https://github.com/knsv/mermaid/issues/650) +- alt attribute of img tag in HTML [\#619](https://github.com/knsv/mermaid/issues/619) +- Just wanted to say : THANKS ! [\#618](https://github.com/knsv/mermaid/issues/618) +- "animation" [\#446](https://github.com/knsv/mermaid/issues/446) + +**Merged pull requests:** + +- Trimming whitespace after participant id [\#882](https://github.com/knsv/mermaid/pull/882) ([IOrlandoni](https://github.com/IOrlandoni)) +- chore\(deps\): bump atob from 2.0.3 to 2.1.2 [\#881](https://github.com/knsv/mermaid/pull/881) ([dependabot[bot]](https://github.com/apps/dependabot)) +- chore\(deps\): bump fstream from 1.0.11 to 1.0.12 [\#880](https://github.com/knsv/mermaid/pull/880) ([dependabot[bot]](https://github.com/apps/dependabot)) +- chore\(deps\): bump js-yaml from 3.12.0 to 3.13.1 [\#879](https://github.com/knsv/mermaid/pull/879) ([dependabot[bot]](https://github.com/apps/dependabot)) +- I847 cross site scripting [\#878](https://github.com/knsv/mermaid/pull/878) ([knsv](https://github.com/knsv)) +- Bump lodash.mergewith from 4.6.1 to 4.6.2 [\#877](https://github.com/knsv/mermaid/pull/877) ([dependabot[bot]](https://github.com/apps/dependabot)) +- Adding docs into core repo again [\#876](https://github.com/knsv/mermaid/pull/876) ([knsv](https://github.com/knsv)) +- Bump lodash from 4.17.11 to 4.17.13 [\#875](https://github.com/knsv/mermaid/pull/875) ([dependabot[bot]](https://github.com/apps/dependabot)) +- feat\(stale.yml\): update issue label and bot comment [\#874](https://github.com/knsv/mermaid/pull/874) ([ThePenguin1140](https://github.com/ThePenguin1140)) +- Feature/allow inclusive enddates [\#872](https://github.com/knsv/mermaid/pull/872) ([ThePenguin1140](https://github.com/ThePenguin1140)) +- Adding trapezoid and inverse trapezoid vertex options. [\#741](https://github.com/knsv/mermaid/pull/741) ([adamwulf](https://github.com/adamwulf)) + +## [8.1.0](https://github.com/knsv/mermaid/tree/8.1.0) (2019-06-25) + +[Full Changelog](https://github.com/knsv/mermaid/compare/7.0.5...8.1.0) + +**Closed issues:** + +- Gantt and sequence diagram do not render [\#853](https://github.com/knsv/mermaid/issues/853) +- margins around flowchart are not balanced [\#852](https://github.com/knsv/mermaid/issues/852) +- Smaller bundles [\#843](https://github.com/knsv/mermaid/issues/843) +- unicode in labels [\#776](https://github.com/knsv/mermaid/issues/776) +- Hard-changing drawing of arrows per edge type [\#775](https://github.com/knsv/mermaid/issues/775) +- SequenceDiagram wrong [\#773](https://github.com/knsv/mermaid/issues/773) +- Render mermaid on github pages with simple code [\#772](https://github.com/knsv/mermaid/issues/772) +- FlowChart - large space between text and the image [\#754](https://github.com/knsv/mermaid/issues/754) +- Class Diagram Issues when using Mermaid in Stackedit [\#748](https://github.com/knsv/mermaid/issues/748) +- Multi-platform CI [\#744](https://github.com/knsv/mermaid/issues/744) +- gantt: sections can't have a colon [\#742](https://github.com/knsv/mermaid/issues/742) +- Yarn build does not add mermaid.min.css to dist [\#732](https://github.com/knsv/mermaid/issues/732) +- Is there a grammar / keyword / more than just the basic examples? [\#718](https://github.com/knsv/mermaid/issues/718) +- Click event and react component [\#717](https://github.com/knsv/mermaid/issues/717) +- Long text going outside the box [\#706](https://github.com/knsv/mermaid/issues/706) +- How to migrate from yUML to mermaid? [\#704](https://github.com/knsv/mermaid/issues/704) +- Issue on Dynamic Creation in PHP [\#690](https://github.com/knsv/mermaid/issues/690) +- `click "\#target"` and `click "http://url"` should create regular links [\#689](https://github.com/knsv/mermaid/issues/689) +- Support Chinese punctuation [\#687](https://github.com/knsv/mermaid/issues/687) +- \[Question\] Proper way to install on Mac? [\#681](https://github.com/knsv/mermaid/issues/681) +- Has Mermaid a graphical interface to make diagrams? [\#668](https://github.com/knsv/mermaid/issues/668) +- mermaid installation on debian [\#649](https://github.com/knsv/mermaid/issues/649) +- "Cannot activate" in sequenceDiagram [\#647](https://github.com/knsv/mermaid/issues/647) +- Link \("click" statement\) in flowchart does not work in exported SVG [\#646](https://github.com/knsv/mermaid/issues/646) +- How to pass styling [\#639](https://github.com/knsv/mermaid/issues/639) +- The live editor can't show seq diagram with notes for 8.0.0-alpha.3 [\#638](https://github.com/knsv/mermaid/issues/638) +- import mermaid.css with ES6 + NPM [\#634](https://github.com/knsv/mermaid/issues/634) +- Actor line cuts through other elements [\#633](https://github.com/knsv/mermaid/issues/633) +- Graph TD line out of the picture \(left side\) [\#630](https://github.com/knsv/mermaid/issues/630) +- Flowchart labels appear "cutoff" [\#628](https://github.com/knsv/mermaid/issues/628) +- Uncaught TypeError: \_.constant is not a function \(mermaid.js\) [\#626](https://github.com/knsv/mermaid/issues/626) +- Missing tags and releases for newer versions [\#623](https://github.com/knsv/mermaid/issues/623) +- Mermaid and Leo / Leo Vue [\#622](https://github.com/knsv/mermaid/issues/622) +- mermaidAPI gantt Vue.js [\#621](https://github.com/knsv/mermaid/issues/621) +- Gantt sections are not separated by colors - Fix: set numberSectionStyles to 4 instead of 3 [\#620](https://github.com/knsv/mermaid/issues/620) +- how to get mermaidAPI? [\#617](https://github.com/knsv/mermaid/issues/617) +- Error in startOnLoad documentation? [\#616](https://github.com/knsv/mermaid/issues/616) +- Example export to SVG generates error [\#614](https://github.com/knsv/mermaid/issues/614) +- The new online editor does not support previously generated links [\#613](https://github.com/knsv/mermaid/issues/613) +- Grammar / Syntax documentation for flowcharts [\#607](https://github.com/knsv/mermaid/issues/607) +- Mermaid does not work with d3.js [\#606](https://github.com/knsv/mermaid/issues/606) +- Why does this code's flowchart lines get cut-off on screen? [\#604](https://github.com/knsv/mermaid/issues/604) +- click keyword does not fire my callback \(on the demo Website too\) [\#603](https://github.com/knsv/mermaid/issues/603) +- Online Editor fails to show exported SVG [\#601](https://github.com/knsv/mermaid/issues/601) +- Just saying thanks! [\#597](https://github.com/knsv/mermaid/issues/597) +- stylesheet crashed with other library like abcjs [\#596](https://github.com/knsv/mermaid/issues/596) +- Missing connection [\#594](https://github.com/knsv/mermaid/issues/594) +- How to use mermaid on node.js restful api? [\#593](https://github.com/knsv/mermaid/issues/593) +- Remove status code [\#589](https://github.com/knsv/mermaid/issues/589) +- Golang based editor [\#588](https://github.com/knsv/mermaid/issues/588) +- sequenceDiagram -\> notetext css font is hardcoded [\#587](https://github.com/knsv/mermaid/issues/587) +- Multiple graph in the live editor [\#586](https://github.com/knsv/mermaid/issues/586) +- All \ elements in page are colored black [\#584](https://github.com/knsv/mermaid/issues/584) +- Styling: classes aren't applied to elements. [\#582](https://github.com/knsv/mermaid/issues/582) +- Rounded connections [\#580](https://github.com/knsv/mermaid/issues/580) +- Arrows are not being shown correctly in the dark theme [\#578](https://github.com/knsv/mermaid/issues/578) +- The documentation for CLI seems outdated. [\#572](https://github.com/knsv/mermaid/issues/572) +- No effect of click event:can not open link [\#571](https://github.com/knsv/mermaid/issues/571) +- Text colors are not correct in VSCODE [\#570](https://github.com/knsv/mermaid/issues/570) +- Nodes aren't aligned properly \(just need an explanation\) [\#568](https://github.com/knsv/mermaid/issues/568) +- setting margin around figure in R [\#567](https://github.com/knsv/mermaid/issues/567) +- Arrows should Come out in upward and Downward direction from decision Node [\#566](https://github.com/knsv/mermaid/issues/566) +- TypeError: Cannot read property 'select' of undefined [\#563](https://github.com/knsv/mermaid/issues/563) +- A little bug [\#557](https://github.com/knsv/mermaid/issues/557) +- Japanese text appears garbled [\#554](https://github.com/knsv/mermaid/issues/554) +- classdiagram not works in mermaid live_editor [\#553](https://github.com/knsv/mermaid/issues/553) +- font awesome in link text? [\#546](https://github.com/knsv/mermaid/issues/546) +- q: heard of the cosmogol standard? [\#545](https://github.com/knsv/mermaid/issues/545) +- Arrow heads missing \(cli, 7.0.3\) [\#544](https://github.com/knsv/mermaid/issues/544) +- No Edge Boxes if useHtmlLabels=false [\#541](https://github.com/knsv/mermaid/issues/541) +- how to change mermaid text color or line text block color? [\#534](https://github.com/knsv/mermaid/issues/534) +- FlowChart visualization broken when downloading from live editor [\#533](https://github.com/knsv/mermaid/issues/533) +- Can't get flowchart to render paths at the top of the diagram; I even tried the online editor and that shows the same issue. Thoughts? [\#532](https://github.com/knsv/mermaid/issues/532) +- live editor make browser\(safari on macOS&iOS\) not longer respond [\#531](https://github.com/knsv/mermaid/issues/531) +- css classes need a prefix/namespace [\#527](https://github.com/knsv/mermaid/issues/527) +- input activate/deactivate cause safari unresponding [\#521](https://github.com/knsv/mermaid/issues/521) +- Cannot Render the Mermaid Graph to PDF ? [\#520](https://github.com/knsv/mermaid/issues/520) +- clicking links works from inset in subgraph but not from nodes [\#516](https://github.com/knsv/mermaid/issues/516) +- Strange syntax error - when importing mermaid.js [\#515](https://github.com/knsv/mermaid/issues/515) +- gantt x-axis display [\#510](https://github.com/knsv/mermaid/issues/510) +- phantomjs renamed to phantomjs-prebuilt [\#508](https://github.com/knsv/mermaid/issues/508) +- issue when using sphinxcontrib-mermaid extension for sphinx [\#507](https://github.com/knsv/mermaid/issues/507) +- layout of docs page looks broken [\#504](https://github.com/knsv/mermaid/issues/504) +- Problem showing graph with php on localhost [\#502](https://github.com/knsv/mermaid/issues/502) +- logLevel's option doesnt work at 7.0.0 [\#501](https://github.com/knsv/mermaid/issues/501) +- How do I get the log for a render or parse attempt? [\#500](https://github.com/knsv/mermaid/issues/500) +- Mermaid neutral style to built in latest release [\#499](https://github.com/knsv/mermaid/issues/499) +- Any plans for adding a typescript definition file? [\#495](https://github.com/knsv/mermaid/issues/495) +- Gantt diagrams too narrow [\#493](https://github.com/knsv/mermaid/issues/493) +- Flowchart edge labels placement [\#490](https://github.com/knsv/mermaid/issues/490) +- Very different styles when rendering as png vs. svg [\#489](https://github.com/knsv/mermaid/issues/489) +- New editor that supports mermaid: Caret [\#488](https://github.com/knsv/mermaid/issues/488) +- Gant PNG margin [\#486](https://github.com/knsv/mermaid/issues/486) +- ReferenceError: window is not defined [\#485](https://github.com/knsv/mermaid/issues/485) +- Menu and layout bugs in docs [\#484](https://github.com/knsv/mermaid/issues/484) +- Mermaid resets some of the page CSS styles [\#482](https://github.com/knsv/mermaid/issues/482) +- Arrows rendering incorrectly in online editor [\#480](https://github.com/knsv/mermaid/issues/480) +- CSS stroke-dasharray ignored by browsers but not other viewers [\#474](https://github.com/knsv/mermaid/issues/474) +- mermaid - Browser Support issue [\#472](https://github.com/knsv/mermaid/issues/472) +- Totally love mermaid I might pop! [\#471](https://github.com/knsv/mermaid/issues/471) +- Sequence Diagram: Missing x on async arrows \(png\) [\#469](https://github.com/knsv/mermaid/issues/469) +- live editor: the svg file rendered from graph is not supported by browsers [\#468](https://github.com/knsv/mermaid/issues/468) +- Not found css [\#462](https://github.com/knsv/mermaid/issues/462) +- Phantomjs Dependency [\#461](https://github.com/knsv/mermaid/issues/461) +- Mermaid cli not working for subgraphs [\#459](https://github.com/knsv/mermaid/issues/459) +- Support for notes across multiple participants? [\#458](https://github.com/knsv/mermaid/issues/458) +- Related to Issue \#329: Phantomjs issues. [\#455](https://github.com/knsv/mermaid/issues/455) +- Add a click style [\#426](https://github.com/knsv/mermaid/issues/426) +- Add Parallel block \(par\) to sequence diagrams [\#425](https://github.com/knsv/mermaid/issues/425) +- updating shapes after the flow chart rendering complete [\#424](https://github.com/knsv/mermaid/issues/424) +- can't catch parse error Maximum call stack size exceeded on safari [\#421](https://github.com/knsv/mermaid/issues/421) +- Arrows endings are missing [\#419](https://github.com/knsv/mermaid/issues/419) +- shouldn't mermaid become more like Markdown ? [\#417](https://github.com/knsv/mermaid/issues/417) +- Live editor show rendered diagram if syntax invalid [\#415](https://github.com/knsv/mermaid/issues/415) +- Live editor sticky sidebar [\#414](https://github.com/knsv/mermaid/issues/414) +- Linkstyle stroke does not work [\#410](https://github.com/knsv/mermaid/issues/410) +- flowchart id's with dots in them .. break links [\#408](https://github.com/knsv/mermaid/issues/408) +- Flowchart: Link text beginning with lowercase 'o' causes flowchart to break [\#407](https://github.com/knsv/mermaid/issues/407) +- Some chinese character will case Safari no responding. [\#405](https://github.com/knsv/mermaid/issues/405) +- Cannot center-justify text in nodes? [\#397](https://github.com/knsv/mermaid/issues/397) +- Edge labels should have white background in live editor [\#396](https://github.com/knsv/mermaid/issues/396) +- Live editor does not support activate/deactivate [\#394](https://github.com/knsv/mermaid/issues/394) +- Styling subgraph? [\#391](https://github.com/knsv/mermaid/issues/391) +- Update live editor to version 6.0.0 [\#387](https://github.com/knsv/mermaid/issues/387) +- sequence diagram config issue [\#385](https://github.com/knsv/mermaid/issues/385) +- How to add newline in the text [\#384](https://github.com/knsv/mermaid/issues/384) +- PhantomJS crashes on a large graph [\#380](https://github.com/knsv/mermaid/issues/380) +- Finnish support for class diagrams using plantuml syntax [\#377](https://github.com/knsv/mermaid/issues/377) +- mermaidAPI.render generated different svg code from mermaid.int\(\) [\#374](https://github.com/knsv/mermaid/issues/374) +- Put your own action on the chart [\#372](https://github.com/knsv/mermaid/issues/372) +- when declaring participants the elements are generated twice [\#370](https://github.com/knsv/mermaid/issues/370) +- Example Flowchart is cut in display \(Chrome\). [\#368](https://github.com/knsv/mermaid/issues/368) +- Add shebang support to diagrams [\#365](https://github.com/knsv/mermaid/issues/365) +- Silencing CLI output [\#352](https://github.com/knsv/mermaid/issues/352) +- SequenceDiagram: 3+ Alternative Paths [\#348](https://github.com/knsv/mermaid/issues/348) +- Smaller height of actor boxes [\#342](https://github.com/knsv/mermaid/issues/342) +- Question: lib/phantomscript.js - foreignObjects in SVG - related to \#58 [\#340](https://github.com/knsv/mermaid/issues/340) +- npm test fails on osx being blocked at Can not load "PhantomJS", it is not registered! [\#337](https://github.com/knsv/mermaid/issues/337) +- Tabs & subgraphs cause rendering error [\#336](https://github.com/knsv/mermaid/issues/336) +- Display question: right angles [\#335](https://github.com/knsv/mermaid/issues/335) +- No Arrows rendered v0.5.8 [\#330](https://github.com/knsv/mermaid/issues/330) +- mermaid -v filename.mmd gives You must specify at least one source file. [\#328](https://github.com/knsv/mermaid/issues/328) +- You had errors in your syntax. Use --help for further information. [\#327](https://github.com/knsv/mermaid/issues/327) +- Allow alternate arrow syntax that doesn't close html comments [\#322](https://github.com/knsv/mermaid/issues/322) +- Comment in subgraph [\#319](https://github.com/knsv/mermaid/issues/319) +- Update graph [\#311](https://github.com/knsv/mermaid/issues/311) +- css conflicts with boostrap's css [\#308](https://github.com/knsv/mermaid/issues/308) +- Can not get click event to fire. [\#306](https://github.com/knsv/mermaid/issues/306) +- Fix phantomjs2 compatibility [\#304](https://github.com/knsv/mermaid/issues/304) +- Flowcharts do not work in native IE11 [\#303](https://github.com/knsv/mermaid/issues/303) +- Integration with remark.js - tutorial added [\#302](https://github.com/knsv/mermaid/issues/302) +- Theme for dark background [\#301](https://github.com/knsv/mermaid/issues/301) +- Sequence diagram Loops: changing boxMargin spoils the "loop" notation [\#299](https://github.com/knsv/mermaid/issues/299) +- src/mermaid.js generates bad code [\#297](https://github.com/knsv/mermaid/issues/297) +- Fresh fork: jasmine tests fail [\#294](https://github.com/knsv/mermaid/issues/294) +- CSS clash [\#292](https://github.com/knsv/mermaid/issues/292) +- Mermaid does not work in Chrome 48 [\#281](https://github.com/knsv/mermaid/issues/281) +- node click is not effective [\#272](https://github.com/knsv/mermaid/issues/272) +- circle and ellipse cannot change color by classDef [\#271](https://github.com/knsv/mermaid/issues/271) +- \[Feature request\] gantt diagram axis format [\#269](https://github.com/knsv/mermaid/issues/269) +- Not Able to See Labels even htmlLabels:false added [\#268](https://github.com/knsv/mermaid/issues/268) +- npm run watch doesn’t work due missing dependencies [\#266](https://github.com/knsv/mermaid/issues/266) +- label out of node [\#262](https://github.com/knsv/mermaid/issues/262) +- IE11 Support issue [\#261](https://github.com/knsv/mermaid/issues/261) +- mermaid without browser [\#260](https://github.com/knsv/mermaid/issues/260) +- Insufficient capacity of gantt diagrams [\#226](https://github.com/knsv/mermaid/issues/226) +- some WARN about installion [\#222](https://github.com/knsv/mermaid/issues/222) +- Live editor offline access [\#217](https://github.com/knsv/mermaid/issues/217) +- suggest: code highlight mode config for editors [\#212](https://github.com/knsv/mermaid/issues/212) +- Uncaught RangeError: Maximum call stack size exceeded [\#189](https://github.com/knsv/mermaid/issues/189) +- Implement render function for server side rendering using phantomjs [\#169](https://github.com/knsv/mermaid/issues/169) +- Styling label texts [\#50](https://github.com/knsv/mermaid/issues/50) +- Graphviz DOT syntax [\#5](https://github.com/knsv/mermaid/issues/5) + +**Merged pull requests:** + +- Remove console.log in classDB. [\#861](https://github.com/knsv/mermaid/pull/861) ([Arthaey](https://github.com/Arthaey)) +- Bump sshpk from 1.13.1 to 1.16.1 [\#851](https://github.com/knsv/mermaid/pull/851) ([dependabot[bot]](https://github.com/apps/dependabot)) +- Significantly smaller bundles [\#850](https://github.com/knsv/mermaid/pull/850) ([fabiospampinato](https://github.com/fabiospampinato)) +- Support styling of subgraphs [\#845](https://github.com/knsv/mermaid/pull/845) ([Qix-](https://github.com/Qix-)) +- fix dark theme loop labels not visible [\#837](https://github.com/knsv/mermaid/pull/837) ([jnnnnn](https://github.com/jnnnnn)) +- fix draw function can only call once [\#832](https://github.com/knsv/mermaid/pull/832) ([vaniship](https://github.com/vaniship)) +- Fix dotted lines not appearing in flowcharts when HTML labels disabled [\#828](https://github.com/knsv/mermaid/pull/828) ([stanhu](https://github.com/stanhu)) +- Fix issue with XML line breaks inside vertex labels [\#824](https://github.com/knsv/mermaid/pull/824) ([jsyang](https://github.com/jsyang)) +- fixed diagrams [\#810](https://github.com/knsv/mermaid/pull/810) ([0xflotus](https://github.com/0xflotus)) +- Clickable gantt tasks [\#804](https://github.com/knsv/mermaid/pull/804) ([abzicht](https://github.com/abzicht)) +- linkStyle now supports list of indexes with a few tests [\#798](https://github.com/knsv/mermaid/pull/798) ([ivan-danilov](https://github.com/ivan-danilov)) +- fix class diagram mermaid [\#795](https://github.com/knsv/mermaid/pull/795) ([DanShai](https://github.com/DanShai)) +- Added exclude weekdays to definition [\#792](https://github.com/knsv/mermaid/pull/792) ([jopapo](https://github.com/jopapo)) +- SVG link rendering [\#791](https://github.com/knsv/mermaid/pull/791) ([flying-sheep](https://github.com/flying-sheep)) +- Gantt milestones [\#788](https://github.com/knsv/mermaid/pull/788) ([gijswijs](https://github.com/gijswijs)) +- Remove duplicate code [\#768](https://github.com/knsv/mermaid/pull/768) ([znxkznxk1030](https://github.com/znxkznxk1030)) +- Render nodes as real links [\#765](https://github.com/knsv/mermaid/pull/765) ([flying-sheep](https://github.com/flying-sheep)) +- Support Multi-line Actor Descriptions [\#764](https://github.com/knsv/mermaid/pull/764) ([watsoncj](https://github.com/watsoncj)) +- Fix issue with marker-end. [\#757](https://github.com/knsv/mermaid/pull/757) ([gjlubbertsen](https://github.com/gjlubbertsen)) +- Make Class Diagrams usable in Stackedit and Live Editor [\#749](https://github.com/knsv/mermaid/pull/749) ([monsterkrampe](https://github.com/monsterkrampe)) +- Sequence numbers [\#722](https://github.com/knsv/mermaid/pull/722) ([paulbland](https://github.com/paulbland)) +- Add option for right angles [\#721](https://github.com/knsv/mermaid/pull/721) ([paulbland](https://github.com/paulbland)) +- Add nested activation classes [\#720](https://github.com/knsv/mermaid/pull/720) ([paulbland](https://github.com/paulbland)) +- wip: class diagram cardinality display [\#705](https://github.com/knsv/mermaid/pull/705) ([Vrixyz](https://github.com/Vrixyz)) +- add comments about CSS in config [\#688](https://github.com/knsv/mermaid/pull/688) ([imma90](https://github.com/imma90)) +- SequenceDiagram: Add support for multiple alt else statements [\#641](https://github.com/knsv/mermaid/pull/641) ([sechel](https://github.com/sechel)) +- fix \#426 - add class .clickable on nodes with click function or link [\#598](https://github.com/knsv/mermaid/pull/598) ([thomasleveil](https://github.com/thomasleveil)) +- Spec fix 1 [\#595](https://github.com/knsv/mermaid/pull/595) ([frankschmitt](https://github.com/frankschmitt)) + +## [7.0.5](https://github.com/knsv/mermaid/tree/7.0.5) (2017-09-01) + +[Full Changelog](https://github.com/knsv/mermaid/compare/7.0.3...7.0.5) + +**Closed issues:** + +- live editor latin error after update [\#560](https://github.com/knsv/mermaid/issues/560) +- Simple full example in online documentation is broken [\#558](https://github.com/knsv/mermaid/issues/558) +- Graph No Arrow Head v7.0.3 [\#543](https://github.com/knsv/mermaid/issues/543) +- Conflict while using mermaid along with core-js [\#512](https://github.com/knsv/mermaid/issues/512) +- Export to pdf on website [\#496](https://github.com/knsv/mermaid/issues/496) +- New downstream project: Mermaid Preview for VSCode [\#442](https://github.com/knsv/mermaid/issues/442) +- Can't Zoom the flowchart ? [\#399](https://github.com/knsv/mermaid/issues/399) +- line labels are not rendered correctly in live editor [\#366](https://github.com/knsv/mermaid/issues/366) +- mermaid-loader [\#361](https://github.com/knsv/mermaid/issues/361) +- Are there any documentation or examples for classDiagram and gitGraph? [\#359](https://github.com/knsv/mermaid/issues/359) +- \# character broken in 0.5.8 [\#347](https://github.com/knsv/mermaid/issues/347) +- Documentation issue: CSS example is not visible [\#345](https://github.com/knsv/mermaid/issues/345) +- Include documentation for command line usage [\#326](https://github.com/knsv/mermaid/issues/326) +- Fresh fork: can't build dist [\#296](https://github.com/knsv/mermaid/issues/296) +- Invalid value for \ attribute viewBox="0 0 -Infinity -Infinity" [\#291](https://github.com/knsv/mermaid/issues/291) +- Webpack require fails [\#277](https://github.com/knsv/mermaid/issues/277) +- New documentation - need improved logo [\#216](https://github.com/knsv/mermaid/issues/216) + +## [7.0.3](https://github.com/knsv/mermaid/tree/7.0.3) (2017-06-04) + +[Full Changelog](https://github.com/knsv/mermaid/compare/7.0.2...7.0.3) + +**Closed issues:** + +- the documentation website is down [\#539](https://github.com/knsv/mermaid/issues/539) +- Good example of interactivity with mermaidAPI [\#514](https://github.com/knsv/mermaid/issues/514) + +## [7.0.2](https://github.com/knsv/mermaid/tree/7.0.2) (2017-06-01) + +[Full Changelog](https://github.com/knsv/mermaid/compare/7.0.0...7.0.2) + +**Closed issues:** + +- CDN is not working [\#511](https://github.com/knsv/mermaid/issues/511) +- A sampe sequenceDiagram crashes mermaid-cli [\#492](https://github.com/knsv/mermaid/issues/492) +- Mermaid doesn't delete nodes when called multiple times [\#491](https://github.com/knsv/mermaid/issues/491) +- API crashes on 2nd render\(\) call [\#478](https://github.com/knsv/mermaid/issues/478) +- sequenceDiagram: dotted line for alt and empty bracket should be hidden [\#456](https://github.com/knsv/mermaid/issues/456) +- SVG output \(almost\) not correct [\#434](https://github.com/knsv/mermaid/issues/434) +- How to set axisFormatter of gantt in mermaid CLI? [\#428](https://github.com/knsv/mermaid/issues/428) +- customizing link style with any color sets `fill` property to `black` instead of `none` [\#416](https://github.com/knsv/mermaid/issues/416) +- New line at the end of SVG file [\#400](https://github.com/knsv/mermaid/issues/400) +- CLI doesn't work [\#389](https://github.com/knsv/mermaid/issues/389) +- Can't render subgraphs with htmlLabels: false [\#367](https://github.com/knsv/mermaid/issues/367) +- Color arrowhead [\#362](https://github.com/knsv/mermaid/issues/362) +- CLI: Invisible text, lines in SVG output [\#341](https://github.com/knsv/mermaid/issues/341) + +**Merged pull requests:** + +- Update Travis config [\#538](https://github.com/knsv/mermaid/pull/538) ([tylerlong](https://github.com/tylerlong)) +- Fix spelling of 'you' in sequenceDiagram docs [\#537](https://github.com/knsv/mermaid/pull/537) ([ctruelson](https://github.com/ctruelson)) +- Improve CLI output [\#536](https://github.com/knsv/mermaid/pull/536) ([gibson042](https://github.com/gibson042)) +- Modernize mermaid [\#524](https://github.com/knsv/mermaid/pull/524) ([tylerlong](https://github.com/tylerlong)) +- Modernize mermaid [\#519](https://github.com/knsv/mermaid/pull/519) ([tylerlong](https://github.com/tylerlong)) +- Update CLI instructions [\#509](https://github.com/knsv/mermaid/pull/509) ([filipedeschamps](https://github.com/filipedeschamps)) +- Add style for classDiagram to dark/default theme [\#503](https://github.com/knsv/mermaid/pull/503) ([yudenzel](https://github.com/yudenzel)) +- Fix documentation for git graph. [\#498](https://github.com/knsv/mermaid/pull/498) ([gomlgs](https://github.com/gomlgs)) +- Fix links in documentations [\#497](https://github.com/knsv/mermaid/pull/497) ([saveman71](https://github.com/saveman71)) +- Update README.md with git graph sample [\#481](https://github.com/knsv/mermaid/pull/481) ([raghur](https://github.com/raghur)) +- Fix misspelling of “another” [\#479](https://github.com/knsv/mermaid/pull/479) ([stevenschobert](https://github.com/stevenschobert)) +- Fixed \#456 sequenceDiagram: dotted line for alt and empty bracket sho… [\#477](https://github.com/knsv/mermaid/pull/477) ([brookhong](https://github.com/brookhong)) +- Add viewbox attr to class diagram [\#473](https://github.com/knsv/mermaid/pull/473) ([gnkm](https://github.com/gnkm)) +- add par statement to sequenceDiagram [\#470](https://github.com/knsv/mermaid/pull/470) ([u-minor](https://github.com/u-minor)) + +## [7.0.0](https://github.com/knsv/mermaid/tree/7.0.0) (2017-01-29) + +[Full Changelog](https://github.com/knsv/mermaid/compare/6.0.0...7.0.0) + +**Closed issues:** + +- demos on io site not working [\#466](https://github.com/knsv/mermaid/issues/466) +- Can not be generated PNG pictures through CLI with Chinese [\#451](https://github.com/knsv/mermaid/issues/451) +- Round nodes cannot be styled with CSS classes [\#443](https://github.com/knsv/mermaid/issues/443) +- webpack gulp UglifyJsPlugin error. [\#440](https://github.com/knsv/mermaid/issues/440) +- String concatenation isn't working [\#432](https://github.com/knsv/mermaid/issues/432) +- text flow/wrap in actor box of sequence diagram [\#422](https://github.com/knsv/mermaid/issues/422) +- Online live editor still use old version [\#402](https://github.com/knsv/mermaid/issues/402) +- uncaught TypeError: t.getTransformToElement is not a function [\#401](https://github.com/knsv/mermaid/issues/401) +- Only works when using browserify'd code [\#373](https://github.com/knsv/mermaid/issues/373) +- document the use of shebang line in mmd files [\#364](https://github.com/knsv/mermaid/issues/364) +- Diagrams are small and unreadable in IE 11 - since 0.5.1 [\#356](https://github.com/knsv/mermaid/issues/356) +- \[Feature Request\] ER-Diagram Support [\#354](https://github.com/knsv/mermaid/issues/354) +- npm install -g mermaid does not install phantomjs [\#329](https://github.com/knsv/mermaid/issues/329) +- activation boxes [\#313](https://github.com/knsv/mermaid/issues/313) +- The need for mermaid.css should be mentioned explicitly in the intro docs... [\#273](https://github.com/knsv/mermaid/issues/273) + +**Merged pull requests:** + +- Update index.html [\#465](https://github.com/knsv/mermaid/pull/465) ([bmsleight](https://github.com/bmsleight)) +- Fix for \#416, customizing link style with any color sets `fill` property to `black` instead of `none` [\#452](https://github.com/knsv/mermaid/pull/452) ([joshuacolvin](https://github.com/joshuacolvin)) +- Allow .node\>circle to receive css styles [\#449](https://github.com/knsv/mermaid/pull/449) ([bfriedz](https://github.com/bfriedz)) +- Fix spelling [\#447](https://github.com/knsv/mermaid/pull/447) ([jawn](https://github.com/jawn)) +- added tests and fix cli css style selector lowercase problem [\#445](https://github.com/knsv/mermaid/pull/445) ([whyzdev](https://github.com/whyzdev)) +- Update d3.js [\#441](https://github.com/knsv/mermaid/pull/441) ([hetz](https://github.com/hetz)) +- adde tests to reproduce \#434 in flowchart [\#439](https://github.com/knsv/mermaid/pull/439) ([whyzdev](https://github.com/whyzdev)) +- Code Climate config [\#437](https://github.com/knsv/mermaid/pull/437) ([larkinscott](https://github.com/larkinscott)) +- fix gantt and sequence digram cli cfg [\#435](https://github.com/knsv/mermaid/pull/435) ([whyzdev](https://github.com/whyzdev)) +- fix gantt chart cli configuration broken [\#433](https://github.com/knsv/mermaid/pull/433) ([whyzdev](https://github.com/whyzdev)) +- fix gantt chart cli configuration parsing including functions [\#430](https://github.com/knsv/mermaid/pull/430) ([whyzdev](https://github.com/whyzdev)) +- Uses an empty text node instead of a string for svg group labels [\#429](https://github.com/knsv/mermaid/pull/429) ([daveaglick](https://github.com/daveaglick)) +- use tspan via d3.textwrap to place actor text in sequence diagram [\#427](https://github.com/knsv/mermaid/pull/427) ([whyzdev](https://github.com/whyzdev)) +- \#422 use foreignObject/div to place actor label in sequence diagram [\#423](https://github.com/knsv/mermaid/pull/423) ([whyzdev](https://github.com/whyzdev)) +- Clarify the need for a CSS stylesheet [\#413](https://github.com/knsv/mermaid/pull/413) ([sifb](https://github.com/sifb)) +- Added hads downstream project [\#412](https://github.com/knsv/mermaid/pull/412) ([sinedied](https://github.com/sinedied)) +- update usage and fix \#273 [\#406](https://github.com/knsv/mermaid/pull/406) ([jinntrance](https://github.com/jinntrance)) +- Add https://github.com/raghur/mermaid-filter to downstream projects docs page [\#404](https://github.com/knsv/mermaid/pull/404) ([raghur](https://github.com/raghur)) +- New neutral theme [\#395](https://github.com/knsv/mermaid/pull/395) ([sinedied](https://github.com/sinedied)) +- fix cli issues [\#390](https://github.com/knsv/mermaid/pull/390) ([ben-page](https://github.com/ben-page)) +- Add missing space for 'Labels out of bounds' section [\#386](https://github.com/knsv/mermaid/pull/386) ([The-Alchemist](https://github.com/The-Alchemist)) +- Fix typo: `pats` -\> `paths` [\#382](https://github.com/knsv/mermaid/pull/382) ([swhgoon](https://github.com/swhgoon)) +- Added class diagram example to README.md [\#379](https://github.com/knsv/mermaid/pull/379) ([HustLion](https://github.com/HustLion)) +- override normal flowchart arrowhead to allow css styling [\#376](https://github.com/knsv/mermaid/pull/376) ([dodoinblue](https://github.com/dodoinblue)) +- added sphinx extension [\#371](https://github.com/knsv/mermaid/pull/371) ([mgaitan](https://github.com/mgaitan)) +- Fix typo in the sequence diagram documentation [\#369](https://github.com/knsv/mermaid/pull/369) ([ggpasqualino](https://github.com/ggpasqualino)) + +## [6.0.0](https://github.com/knsv/mermaid/tree/6.0.0) (2016-05-29) + +[Full Changelog](https://github.com/knsv/mermaid/compare/0.5.8...6.0.0) + +**Closed issues:** + +- Docs css: code hard to read [\#324](https://github.com/knsv/mermaid/issues/324) +- About Markpad integration [\#323](https://github.com/knsv/mermaid/issues/323) +- How to link backwards in flowchat? [\#321](https://github.com/knsv/mermaid/issues/321) +- Help with editor [\#310](https://github.com/knsv/mermaid/issues/310) +- +1 [\#293](https://github.com/knsv/mermaid/issues/293) +- Basic chart does not render on Chome, but does in Firefox [\#290](https://github.com/knsv/mermaid/issues/290) +- Live editor is broken [\#285](https://github.com/knsv/mermaid/issues/285) +- "No such file or directory" trying to run mermaid 0.5.7 on OS X [\#284](https://github.com/knsv/mermaid/issues/284) +- participant name as "Long Long Name" [\#283](https://github.com/knsv/mermaid/issues/283) +- Windows - cli - could not find phantomjs at the specified path [\#236](https://github.com/knsv/mermaid/issues/236) + +**Merged pull requests:** + +- The option of gantt for the spaces for the section names. [\#353](https://github.com/knsv/mermaid/pull/353) ([zeroyonichihachi](https://github.com/zeroyonichihachi)) +- Gitgraph: Make reset work with parent ref carets [\#350](https://github.com/knsv/mermaid/pull/350) ([raghur](https://github.com/raghur)) +- Remove the text-shadows that make the text look blurry [\#349](https://github.com/knsv/mermaid/pull/349) ([AsaAyers](https://github.com/AsaAyers)) +- add line interpolation to linkStyle in flowchart [\#346](https://github.com/knsv/mermaid/pull/346) ([AlanHohn](https://github.com/AlanHohn)) +- Support git graph diagrams in mermaid [\#344](https://github.com/knsv/mermaid/pull/344) ([raghur](https://github.com/raghur)) +- Build and test execution changes [\#338](https://github.com/knsv/mermaid/pull/338) ([ssbarnea](https://github.com/ssbarnea)) +- Reformatting of css files [\#331](https://github.com/knsv/mermaid/pull/331) ([Jmuccigr](https://github.com/Jmuccigr)) +- \(WIP\) Sequence Diagram Title Support [\#320](https://github.com/knsv/mermaid/pull/320) ([bronsoja](https://github.com/bronsoja)) +- activations doc + few fixes [\#318](https://github.com/knsv/mermaid/pull/318) ([ciekawy](https://github.com/ciekawy)) +- Dark theme for better contrast on darker backgrounds [\#317](https://github.com/knsv/mermaid/pull/317) ([crodriguez1a](https://github.com/crodriguez1a)) +- Activations [\#316](https://github.com/knsv/mermaid/pull/316) ([ciekawy](https://github.com/ciekawy)) +- Support leading comments for sequenceDiagrams [\#312](https://github.com/knsv/mermaid/pull/312) ([ashsearle](https://github.com/ashsearle)) +- Show a little lenience for white-space around names [\#309](https://github.com/knsv/mermaid/pull/309) ([ashsearle](https://github.com/ashsearle)) +- Update list of downstream projects [\#307](https://github.com/knsv/mermaid/pull/307) ([maxArturo](https://github.com/maxArturo)) +- Issue 299: Sequence diagram Loops: changing boxMargin spoils the "loop" notation [\#300](https://github.com/knsv/mermaid/pull/300) ([LarryKlugerDS](https://github.com/LarryKlugerDS)) +- Issue 297 - src/mermaid.js generates bad code [\#298](https://github.com/knsv/mermaid/pull/298) ([LarryKlugerDS](https://github.com/LarryKlugerDS)) +- Updated instructions for running tests [\#295](https://github.com/knsv/mermaid/pull/295) ([LarryKlugerDS](https://github.com/LarryKlugerDS)) +- Add Markdown Plus to Downstream projects [\#288](https://github.com/knsv/mermaid/pull/288) ([tylerlong](https://github.com/tylerlong)) +- Quote phantomPath so that it doesn't fail on window [\#286](https://github.com/knsv/mermaid/pull/286) ([raghur](https://github.com/raghur)) + +## [0.5.8](https://github.com/knsv/mermaid/tree/0.5.8) (2016-01-27) + +[Full Changelog](https://github.com/knsv/mermaid/compare/0.5.7...0.5.8) + +## [0.5.7](https://github.com/knsv/mermaid/tree/0.5.7) (2016-01-25) + +[Full Changelog](https://github.com/knsv/mermaid/compare/0.5.6...0.5.7) + +**Closed issues:** + +- Mermaid + LightPaper = ❤️ [\#280](https://github.com/knsv/mermaid/issues/280) +- Bower Integration [\#278](https://github.com/knsv/mermaid/issues/278) +- Mermaid breaks when variables end in 'v' [\#276](https://github.com/knsv/mermaid/issues/276) +- sequence diagrams don't support participant aliasing [\#263](https://github.com/knsv/mermaid/issues/263) +- One diagram that fails to render stops further execution on the page [\#259](https://github.com/knsv/mermaid/issues/259) +- Where to find line layout algorithm? [\#258](https://github.com/knsv/mermaid/issues/258) +- Compatibility with node.js [\#257](https://github.com/knsv/mermaid/issues/257) +- Label resizing with dynamically loaded fonts [\#255](https://github.com/knsv/mermaid/issues/255) +- SVG arrowheads are broken in the CLI [\#249](https://github.com/knsv/mermaid/issues/249) +- Cannot read property 'replace' of undefined [\#239](https://github.com/knsv/mermaid/issues/239) + +**Merged pull requests:** + +- gh-50 Allow styling of edge labels in css [\#267](https://github.com/knsv/mermaid/pull/267) ([Anoia](https://github.com/Anoia)) +- Allow sequenceDiagram participant aliasing [\#265](https://github.com/knsv/mermaid/pull/265) ([gibson042](https://github.com/gibson042)) + +## [0.5.6](https://github.com/knsv/mermaid/tree/0.5.6) (2015-11-22) + +[Full Changelog](https://github.com/knsv/mermaid/compare/0.5.5...0.5.6) + +**Closed issues:** + +- title doesn't work in sequenceDiagram [\#248](https://github.com/knsv/mermaid/issues/248) +- hypen-minus should be valid in sequence diagram alt/else/etc. descriptions [\#247](https://github.com/knsv/mermaid/issues/247) +- Broken in firefox? [\#245](https://github.com/knsv/mermaid/issues/245) +- When there is a Chinese symbol in the flowchart, it will crash。 [\#238](https://github.com/knsv/mermaid/issues/238) +- Non-alpha characters included in ALPHA token \(flow graph jison\) [\#232](https://github.com/knsv/mermaid/issues/232) +- subgraph not rendering with change to sample [\#231](https://github.com/knsv/mermaid/issues/231) +- sequence diagram requires a new line at the end? [\#229](https://github.com/knsv/mermaid/issues/229) +- Live Editor: Permalink address not being parsed [\#202](https://github.com/knsv/mermaid/issues/202) +- Add download SVG link to the live editor [\#144](https://github.com/knsv/mermaid/issues/144) + +**Merged pull requests:** + +- Make sequenceDiagram terminal newline optional [\#253](https://github.com/knsv/mermaid/pull/253) ([gibson042](https://github.com/gibson042)) +- Support sequenceDiagram "over" notes [\#252](https://github.com/knsv/mermaid/pull/252) ([gibson042](https://github.com/gibson042)) +- Properly handle "rest of line" statements [\#251](https://github.com/knsv/mermaid/pull/251) ([gibson042](https://github.com/gibson042)) +- CLI: Propagate exit code from lib \(i.e., phantomjs\) [\#250](https://github.com/knsv/mermaid/pull/250) ([gibson042](https://github.com/gibson042)) +- flowRender.js - Fix FontAwesome icon insert [\#244](https://github.com/knsv/mermaid/pull/244) ([ma-zal](https://github.com/ma-zal)) +- updated sequence diagram link in live editor [\#242](https://github.com/knsv/mermaid/pull/242) ([r-a-v-a-s](https://github.com/r-a-v-a-s)) +- updated links in README.md [\#240](https://github.com/knsv/mermaid/pull/240) ([r-a-v-a-s](https://github.com/r-a-v-a-s)) +- Ellipse syntax [\#237](https://github.com/knsv/mermaid/pull/237) ([spect88](https://github.com/spect88)) +- Allow keywords as suffixes of node ids [\#235](https://github.com/knsv/mermaid/pull/235) ([spect88](https://github.com/spect88)) +- Highlighted the editor in the nav [\#234](https://github.com/knsv/mermaid/pull/234) ([knsv](https://github.com/knsv)) +- Live editor tweaks [\#233](https://github.com/knsv/mermaid/pull/233) ([spect88](https://github.com/spect88)) +- Add a Gitter chat badge to README.md [\#230](https://github.com/knsv/mermaid/pull/230) ([gitter-badger](https://github.com/gitter-badger)) + +## [0.5.5](https://github.com/knsv/mermaid/tree/0.5.5) (2015-10-21) + +[Full Changelog](https://github.com/knsv/mermaid/compare/0.5.4...0.5.5) + +**Closed issues:** + +- sequence diagram, arrowhead instead of crosshead [\#227](https://github.com/knsv/mermaid/issues/227) + +**Merged pull requests:** + +- Fix a typo: crosshead --\> arrowhead [\#228](https://github.com/knsv/mermaid/pull/228) ([tylerlong](https://github.com/tylerlong)) + +## [0.5.4](https://github.com/knsv/mermaid/tree/0.5.4) (2015-10-19) + +[Full Changelog](https://github.com/knsv/mermaid/compare/0.5.3...0.5.4) + +**Closed issues:** + +- Weird bug in live editor when using words with substring `end` [\#184](https://github.com/knsv/mermaid/issues/184) +- Custom icons [\#15](https://github.com/knsv/mermaid/issues/15) +- Marker-end arrow cannot be shown for URL with query parameter [\#225](https://github.com/knsv/mermaid/issues/225) +- Please update bower's D3 version [\#221](https://github.com/knsv/mermaid/issues/221) +- Set log level from mermaid configuration [\#220](https://github.com/knsv/mermaid/issues/220) +- Width fixed to 400px [\#204](https://github.com/knsv/mermaid/issues/204) +- render to png from the cli does not display the marker-end arrow heads [\#181](https://github.com/knsv/mermaid/issues/181) +- Links in sequence diagrams [\#159](https://github.com/knsv/mermaid/issues/159) +- comment characters `%%` cause parse error [\#141](https://github.com/knsv/mermaid/issues/141) +- Add a reversed asymmetric shape [\#124](https://github.com/knsv/mermaid/issues/124) +- Add syntax for double headed arrows [\#123](https://github.com/knsv/mermaid/issues/123) +- Support for font-awesome [\#49](https://github.com/knsv/mermaid/issues/49) + +**Merged pull requests:** + +- Allow `end` as a substring of vertex id [\#224](https://github.com/knsv/mermaid/pull/224) ([spect88](https://github.com/spect88)) +- Remove duplicate npm dependencies: d3 and he [\#223](https://github.com/knsv/mermaid/pull/223) ([spect88](https://github.com/spect88)) + +## [0.5.3](https://github.com/knsv/mermaid/tree/0.5.3) (2015-10-04) + +[Full Changelog](https://github.com/knsv/mermaid/compare/0.5.2...0.5.3) + +## [0.5.2](https://github.com/knsv/mermaid/tree/0.5.2) (2015-10-04) + +[Full Changelog](https://github.com/knsv/mermaid/compare/0.5.1...0.5.2) + +**Closed issues:** + +- Installing “atom-mermaid@0.1.3” failed [\#218](https://github.com/knsv/mermaid/issues/218) +- Render mermaid code on websites? [\#215](https://github.com/knsv/mermaid/issues/215) +- Brackets in a node with text? [\#213](https://github.com/knsv/mermaid/issues/213) +- node feature request [\#211](https://github.com/knsv/mermaid/issues/211) +- Please add prefix for styles [\#208](https://github.com/knsv/mermaid/issues/208) +- Bad handling of block arguments [\#207](https://github.com/knsv/mermaid/issues/207) +- please consider port to mac osx [\#203](https://github.com/knsv/mermaid/issues/203) +- allow phantomjs \>=1.9.x [\#201](https://github.com/knsv/mermaid/issues/201) +- syntax for venn diagrams? [\#200](https://github.com/knsv/mermaid/issues/200) +- Broken CLI Graphs? \(v0.5.1\) [\#196](https://github.com/knsv/mermaid/issues/196) +- Static site does not render under HTTPS [\#194](https://github.com/knsv/mermaid/issues/194) +- Error on simple graph [\#192](https://github.com/knsv/mermaid/issues/192) +- Escape "~" [\#191](https://github.com/knsv/mermaid/issues/191) +- Trying to add link using 'click' to flowchart [\#188](https://github.com/knsv/mermaid/issues/188) +- cli: no lines and arrowheads rendered / only dotted lines [\#187](https://github.com/knsv/mermaid/issues/187) +- text of mermaid div displayed on page [\#186](https://github.com/knsv/mermaid/issues/186) +- using mermaid with laravel [\#185](https://github.com/knsv/mermaid/issues/185) +- Atom editor package [\#183](https://github.com/knsv/mermaid/issues/183) +- Auto linewrap for notes in sequence diagrams [\#178](https://github.com/knsv/mermaid/issues/178) +- Execute code after initialize [\#176](https://github.com/knsv/mermaid/issues/176) +- Autoscaling for all diagram types [\#175](https://github.com/knsv/mermaid/issues/175) +- Problem with click event callback [\#174](https://github.com/knsv/mermaid/issues/174) +- How to escape characters? [\#170](https://github.com/knsv/mermaid/issues/170) +- it can not work [\#167](https://github.com/knsv/mermaid/issues/167) +- UML Class diagram [\#154](https://github.com/knsv/mermaid/issues/154) +- Broken subgraph using the CLI [\#153](https://github.com/knsv/mermaid/issues/153) +- Support PlantUML syntax [\#149](https://github.com/knsv/mermaid/issues/149) +- IE Support issue [\#142](https://github.com/knsv/mermaid/issues/142) +- Flowchart truncated [\#140](https://github.com/knsv/mermaid/issues/140) +- Double Quote as text is not working [\#219](https://github.com/knsv/mermaid/issues/219) +- classDef / class not working with htmlLabels? [\#210](https://github.com/knsv/mermaid/issues/210) +- Links in graph missing [\#209](https://github.com/knsv/mermaid/issues/209) +- Last word in comment boxes getting cut off by word wrap library : \( [\#195](https://github.com/knsv/mermaid/issues/195) +- Escaping characters in sequence diagram [\#193](https://github.com/knsv/mermaid/issues/193) +- SVG foreignObject rendering [\#180](https://github.com/knsv/mermaid/issues/180) +- IE9 issue [\#179](https://github.com/knsv/mermaid/issues/179) +- inoperable in an AMD/requirejs environment: IPython Notebook [\#127](https://github.com/knsv/mermaid/issues/127) +- \[Parser\] Hyphen in participant name bring TypeError [\#74](https://github.com/knsv/mermaid/issues/74) +- Support for hyperlink and tooltip [\#34](https://github.com/knsv/mermaid/issues/34) + +**Merged pull requests:** + +- Update flowchart.md [\#214](https://github.com/knsv/mermaid/pull/214) ([orschiro](https://github.com/orschiro)) +- Default style when using the CLI [\#205](https://github.com/knsv/mermaid/pull/205) ([gillesdemey](https://github.com/gillesdemey)) +- Gantt chart - add minutes and seconds durations [\#198](https://github.com/knsv/mermaid/pull/198) ([dbrans](https://github.com/dbrans)) +- Using QUnit for AMD testing [\#190](https://github.com/knsv/mermaid/pull/190) ([bollwyvl](https://github.com/bollwyvl)) +- Update phantomscript.js [\#182](https://github.com/knsv/mermaid/pull/182) ([phairow](https://github.com/phairow)) + +## [0.5.1](https://github.com/knsv/mermaid/tree/0.5.1) (2015-06-21) + +[Full Changelog](https://github.com/knsv/mermaid/compare/0.5.0...0.5.1) + +**Closed issues:** + +- Live editor is broken [\#173](https://github.com/knsv/mermaid/issues/173) +- 0.5.0 no longer respects custom date definitions in Gantt diagrams [\#171](https://github.com/knsv/mermaid/issues/171) +- Drop label character restrictions [\#162](https://github.com/knsv/mermaid/issues/162) +- can't nest subgraphs in flowchart [\#161](https://github.com/knsv/mermaid/issues/161) +- Unable to generate gantt diagram with mermaid CLI [\#158](https://github.com/knsv/mermaid/issues/158) +- Inline css by "mermaid" [\#157](https://github.com/knsv/mermaid/issues/157) +- Finite State Machine Diagram [\#152](https://github.com/knsv/mermaid/issues/152) +- How to center align gantt diagram [\#150](https://github.com/knsv/mermaid/issues/150) +- Security concern regarding class definition [\#148](https://github.com/knsv/mermaid/issues/148) +- File Extension [\#147](https://github.com/knsv/mermaid/issues/147) +- To SVG Export [\#146](https://github.com/knsv/mermaid/issues/146) +- `setTimeout` with clusters problematic with programmatic edits and no callback [\#133](https://github.com/knsv/mermaid/issues/133) +- Possibility to set the width of the generated flowchart [\#129](https://github.com/knsv/mermaid/issues/129) +- flowchart - styling of edges via css overrides specific styles set in the graph definition [\#128](https://github.com/knsv/mermaid/issues/128) +- module.exports.cloneCssStyles\(\) in combination with Angularjs breaks display in Chrome and IE [\#126](https://github.com/knsv/mermaid/issues/126) +- Gantt - suitable xAxis for longer project [\#125](https://github.com/knsv/mermaid/issues/125) +- Mix horizontal and vertical graph [\#68](https://github.com/knsv/mermaid/issues/68) +- How to get started with this project ? [\#64](https://github.com/knsv/mermaid/issues/64) +- Special characters break parsing [\#54](https://github.com/knsv/mermaid/issues/54) +- Responsive graph layout for mobile viewers [\#51](https://github.com/knsv/mermaid/issues/51) +- Styling connector lines [\#31](https://github.com/knsv/mermaid/issues/31) + +**Merged pull requests:** + +- Remove moot `version` property from bower.json [\#172](https://github.com/knsv/mermaid/pull/172) ([kkirsche](https://github.com/kkirsche)) + +## [0.5.0](https://github.com/knsv/mermaid/tree/0.5.0) (2015-06-07) + +[Full Changelog](https://github.com/knsv/mermaid/compare/0.4.0...0.5.0) + +**Closed issues:** + +- it can not work where graph TD contains chinese character [\#166](https://github.com/knsv/mermaid/issues/166) +- Broken Examples [\#163](https://github.com/knsv/mermaid/issues/163) +- uglifyjs wanrings which means we can improve the code [\#156](https://github.com/knsv/mermaid/issues/156) +- New\(er\) features unavailable in downloadable js files? [\#151](https://github.com/knsv/mermaid/issues/151) +- Add gh-gapes link to description [\#143](https://github.com/knsv/mermaid/issues/143) +- Some examples not displayed on Firefox 36.0.1 [\#138](https://github.com/knsv/mermaid/issues/138) +- tags ending in a "v" don't render [\#132](https://github.com/knsv/mermaid/issues/132) +- Links in flowchart [\#131](https://github.com/knsv/mermaid/issues/131) +- Using the library for iOS development [\#130](https://github.com/knsv/mermaid/issues/130) +- Add a css file, mermaid.css, with default styling [\#122](https://github.com/knsv/mermaid/issues/122) +- Add capability for gantt diagrams [\#118](https://github.com/knsv/mermaid/issues/118) +- lower case v causes error in the parser [\#108](https://github.com/knsv/mermaid/issues/108) +- Label's css conflict with boostrap's .label [\#67](https://github.com/knsv/mermaid/issues/67) +- TypeError: Cannot read property 'layout' of undefined [\#37](https://github.com/knsv/mermaid/issues/37) +- software architecture diagram [\#36](https://github.com/knsv/mermaid/issues/36) +- Support for bar charts and pie diagrams [\#22](https://github.com/knsv/mermaid/issues/22) + +**Merged pull requests:** + +- Dev 0.5.0 [\#168](https://github.com/knsv/mermaid/pull/168) ([knsv](https://github.com/knsv)) +- Fix spacing [\#164](https://github.com/knsv/mermaid/pull/164) ([rhcarvalho](https://github.com/rhcarvalho)) +- Fixing typo: "Think" -\> "Thick" [\#160](https://github.com/knsv/mermaid/pull/160) ([it0a](https://github.com/it0a)) +- IE, local html, cssRules access is denied [\#155](https://github.com/knsv/mermaid/pull/155) ([tylerlong](https://github.com/tylerlong)) +- Add automatically generated change log file. [\#139](https://github.com/knsv/mermaid/pull/139) ([skywinder](https://github.com/skywinder)) +- Adding init argument to the global API [\#137](https://github.com/knsv/mermaid/pull/137) ([bollwyvl](https://github.com/bollwyvl)) +- Add description of manual calling of init [\#136](https://github.com/knsv/mermaid/pull/136) ([bollwyvl](https://github.com/bollwyvl)) +- Allow other forms of node selection for init\(\) [\#135](https://github.com/knsv/mermaid/pull/135) ([bollwyvl](https://github.com/bollwyvl)) +- Use a library-level variable for assigning ids [\#134](https://github.com/knsv/mermaid/pull/134) ([bollwyvl](https://github.com/bollwyvl)) + +## [0.4.0](https://github.com/knsv/mermaid/tree/0.4.0) (2015-03-01) + +[Full Changelog](https://github.com/knsv/mermaid/compare/0.3.5...0.4.0) + +**Closed issues:** + +- subgraph background is black in rendered flowchart PNG via CLI [\#121](https://github.com/knsv/mermaid/issues/121) +- Integrate editor at https://github.com/naseer/mermaid-webapp [\#110](https://github.com/knsv/mermaid/issues/110) +- Internet Explorer Support [\#99](https://github.com/knsv/mermaid/issues/99) +- Asymmetric shapes not documented [\#82](https://github.com/knsv/mermaid/issues/82) +- NoModificationAllowedError [\#23](https://github.com/knsv/mermaid/issues/23) +- Improve arrows [\#3](https://github.com/knsv/mermaid/issues/3) + +## [0.3.5](https://github.com/knsv/mermaid/tree/0.3.5) (2015-02-15) + +[Full Changelog](https://github.com/knsv/mermaid/compare/0.3.4...0.3.5) + +## [0.3.4](https://github.com/knsv/mermaid/tree/0.3.4) (2015-02-15) + +[Full Changelog](https://github.com/knsv/mermaid/compare/0.3.3...0.3.4) + +**Closed issues:** + +- Subgraph syntax bug? [\#120](https://github.com/knsv/mermaid/issues/120) +- Live editor [\#115](https://github.com/knsv/mermaid/issues/115) +- Error in "Basic Syntax" wiki page [\#113](https://github.com/knsv/mermaid/issues/113) +- semicolons, anyone? [\#111](https://github.com/knsv/mermaid/issues/111) +- undefined `sequenceConfig` fails [\#109](https://github.com/knsv/mermaid/issues/109) +- Sequence Diagrams: Show Actors below as well [\#106](https://github.com/knsv/mermaid/issues/106) +- Allow overriding sequence diagram configuration \(SVG properties\) [\#103](https://github.com/knsv/mermaid/issues/103) +- Error when rendering A-- This is the text -- B [\#102](https://github.com/knsv/mermaid/issues/102) +- Clipping in documentation [\#97](https://github.com/knsv/mermaid/issues/97) +- isolate class styling to the svg container [\#92](https://github.com/knsv/mermaid/issues/92) +- Apply styling from css when using the CLI utility [\#85](https://github.com/knsv/mermaid/issues/85) +- Generated SVG works poorly outside web browsers [\#58](https://github.com/knsv/mermaid/issues/58) +- Make the new graph declaration more visual [\#40](https://github.com/knsv/mermaid/issues/40) +- Generating SVG text blob for use in Node [\#2](https://github.com/knsv/mermaid/issues/2) + +**Merged pull requests:** + +- Add live editor [\#119](https://github.com/knsv/mermaid/pull/119) ([naseer](https://github.com/naseer)) +- Adds CSS option to the CLI [\#116](https://github.com/knsv/mermaid/pull/116) ([fardog](https://github.com/fardog)) +- Update flowchart.md in response Issue \#113 [\#114](https://github.com/knsv/mermaid/pull/114) ([vijay40](https://github.com/vijay40)) +- Ignore all files except the license and dist/ folder when installing with Bower. [\#112](https://github.com/knsv/mermaid/pull/112) ([jasonbellamy](https://github.com/jasonbellamy)) + +## [0.3.3](https://github.com/knsv/mermaid/tree/0.3.3) (2015-01-25) + +[Full Changelog](https://github.com/knsv/mermaid/compare/0.3.2...0.3.3) + +**Closed issues:** + +- Missing arrows in sequence diagram [\#98](https://github.com/knsv/mermaid/issues/98) +- Error with \>9 linkStyles [\#95](https://github.com/knsv/mermaid/issues/95) +- Support for dotted links [\#26](https://github.com/knsv/mermaid/issues/26) + +**Merged pull requests:** + +- Require d3 directly to better support Node usage [\#107](https://github.com/knsv/mermaid/pull/107) ([markdalgleish](https://github.com/markdalgleish)) +- update doc with -c option [\#105](https://github.com/knsv/mermaid/pull/105) ([jjmr](https://github.com/jjmr)) +- Add new parameter to the console client to override the svg configuration in sequence diagrams [\#104](https://github.com/knsv/mermaid/pull/104) ([jjmr](https://github.com/jjmr)) +- Text based labels, new shape [\#101](https://github.com/knsv/mermaid/pull/101) ([bjowes](https://github.com/bjowes)) +- fix html tags in example usage [\#100](https://github.com/knsv/mermaid/pull/100) ([deiwin](https://github.com/deiwin)) + +## [0.3.2](https://github.com/knsv/mermaid/tree/0.3.2) (2015-01-11) + +[Full Changelog](https://github.com/knsv/mermaid/compare/0.3.1...0.3.2) + +**Closed issues:** + +- disable auto render [\#91](https://github.com/knsv/mermaid/issues/91) +- Tidy breaks mermaid \(linebreaks in \\) [\#87](https://github.com/knsv/mermaid/issues/87) +- Bug: \ being rendered as text in node [\#73](https://github.com/knsv/mermaid/issues/73) +- Graph edges appear to render outside of the canvas [\#70](https://github.com/knsv/mermaid/issues/70) +- Make link text look like it is on the line [\#53](https://github.com/knsv/mermaid/issues/53) + +**Merged pull requests:** + +- Merge pull request \#1 from knsv/master [\#96](https://github.com/knsv/mermaid/pull/96) ([gkchic](https://github.com/gkchic)) +- Removed duplicated section in flowchart docs [\#94](https://github.com/knsv/mermaid/pull/94) ([kaime](https://github.com/kaime)) +- Grammar changes to sequence page [\#93](https://github.com/knsv/mermaid/pull/93) ([gkchic](https://github.com/gkchic)) +- GitHub buttons [\#89](https://github.com/knsv/mermaid/pull/89) ([gkchic](https://github.com/gkchic)) +- Template change [\#88](https://github.com/knsv/mermaid/pull/88) ([gkchic](https://github.com/gkchic)) + +## [0.3.1](https://github.com/knsv/mermaid/tree/0.3.1) (2015-01-05) + +[Full Changelog](https://github.com/knsv/mermaid/compare/0.3.0...0.3.1) + +**Closed issues:** + +- Non ASCII chars in labels [\#84](https://github.com/knsv/mermaid/issues/84) +- 'undefined' titles of Quicklinks on the usage page [\#80](https://github.com/knsv/mermaid/issues/80) +- \[cli\] Enhancement proposal: not fail --version / --help if phantomjs isn't installed [\#71](https://github.com/knsv/mermaid/issues/71) +- Neural Networks [\#39](https://github.com/knsv/mermaid/issues/39) +- Support for sequence diagrams [\#16](https://github.com/knsv/mermaid/issues/16) +- Client utility for mermaid [\#6](https://github.com/knsv/mermaid/issues/6) + +**Merged pull requests:** + +- Flowchart doc: Text in the circle now in a circle [\#81](https://github.com/knsv/mermaid/pull/81) ([Grahack](https://github.com/Grahack)) +- Fix for issue \#73 [\#79](https://github.com/knsv/mermaid/pull/79) ([it0a](https://github.com/it0a)) +- Ink template [\#78](https://github.com/knsv/mermaid/pull/78) ([gkchic](https://github.com/gkchic)) +- Show help and version even if phantom isn't present. Fixes \#71 [\#75](https://github.com/knsv/mermaid/pull/75) ([fardog](https://github.com/fardog)) +- Add apostrophe & 'and' [\#72](https://github.com/knsv/mermaid/pull/72) ([sudodoki](https://github.com/sudodoki)) + +## [0.3.0](https://github.com/knsv/mermaid/tree/0.3.0) (2014-12-22) + +[Full Changelog](https://github.com/knsv/mermaid/compare/0.2.16...0.3.0) + +**Closed issues:** + +- Consider shipping a standalone executable [\#65](https://github.com/knsv/mermaid/issues/65) +- Trailing whitespace at the end of lines is not ignored [\#55](https://github.com/knsv/mermaid/issues/55) +- How do I do comments? [\#47](https://github.com/knsv/mermaid/issues/47) +- This characters failed the lexical parsing [\#46](https://github.com/knsv/mermaid/issues/46) +- tutorial for creating new type of graph/layout [\#44](https://github.com/knsv/mermaid/issues/44) +- Improve readability with new line as terminator and whitespace [\#38](https://github.com/knsv/mermaid/issues/38) +- Use classes instead of inline style for easy styling [\#24](https://github.com/knsv/mermaid/issues/24) + +**Merged pull requests:** + +- Adds Command Line Interface for generating PNGs from mermaid description files [\#69](https://github.com/knsv/mermaid/pull/69) ([fardog](https://github.com/fardog)) +- Allow special symbols for direction along with acronyms [\#66](https://github.com/knsv/mermaid/pull/66) ([vijay40](https://github.com/vijay40)) + +## [0.2.16](https://github.com/knsv/mermaid/tree/0.2.16) (2014-12-15) + +[Full Changelog](https://github.com/knsv/mermaid/compare/0.2.15...0.2.16) + +**Closed issues:** + +- Mermaid not rendering properly on Wordpress pages [\#59](https://github.com/knsv/mermaid/issues/59) +- Improve example page with live demo [\#52](https://github.com/knsv/mermaid/issues/52) +- Create image file via CLI? [\#48](https://github.com/knsv/mermaid/issues/48) +- Does not render upon AngularJS Updates [\#45](https://github.com/knsv/mermaid/issues/45) +- Download link in README.MD doesn't work. [\#42](https://github.com/knsv/mermaid/issues/42) +- linkStyle usage is not obvious [\#41](https://github.com/knsv/mermaid/issues/41) +- Move \*.spec.js in src/ to test/ [\#35](https://github.com/knsv/mermaid/issues/35) +- Lines routed outside visible area [\#19](https://github.com/knsv/mermaid/issues/19) + +**Merged pull requests:** + +- New grammar will allow statements ending without semicolon as disccused in Issue \#38 [\#63](https://github.com/knsv/mermaid/pull/63) ([vijay40](https://github.com/vijay40)) +- Class based styling [\#62](https://github.com/knsv/mermaid/pull/62) ([bjowes](https://github.com/bjowes)) +- Fix typos [\#60](https://github.com/knsv/mermaid/pull/60) ([sublimino](https://github.com/sublimino)) +- Included .DS_Store in gitignore [\#57](https://github.com/knsv/mermaid/pull/57) ([alvynmcq](https://github.com/alvynmcq)) +- Improves readablity discussed in issue \#38 [\#56](https://github.com/knsv/mermaid/pull/56) ([vijay40](https://github.com/vijay40)) +- Added a linting task for gulp [\#43](https://github.com/knsv/mermaid/pull/43) ([serv](https://github.com/serv)) + +## [0.2.15](https://github.com/knsv/mermaid/tree/0.2.15) (2014-12-05) + +[Full Changelog](https://github.com/knsv/mermaid/compare/0.2.14...0.2.15) + +**Closed issues:** + +- Question marks don't render properly with /dist/mermaid.full.min.js [\#30](https://github.com/knsv/mermaid/issues/30) +- Error with some characters [\#25](https://github.com/knsv/mermaid/issues/25) +- Provide parse function in browser without `require`? [\#21](https://github.com/knsv/mermaid/issues/21) +- Better label text support [\#18](https://github.com/knsv/mermaid/issues/18) +- Cap-cased words break parser [\#8](https://github.com/knsv/mermaid/issues/8) + +**Merged pull requests:** + +- Include bower_components/ to .gitignore [\#33](https://github.com/knsv/mermaid/pull/33) ([serv](https://github.com/serv)) +- Fixed reference to Git repo. [\#32](https://github.com/knsv/mermaid/pull/32) ([guyellis](https://github.com/guyellis)) + +## [0.2.14](https://github.com/knsv/mermaid/tree/0.2.14) (2014-12-03) + +[Full Changelog](https://github.com/knsv/mermaid/compare/0.2.13...0.2.14) + +## [0.2.13](https://github.com/knsv/mermaid/tree/0.2.13) (2014-12-03) + +[Full Changelog](https://github.com/knsv/mermaid/compare/0.2.10...0.2.13) + +**Closed issues:** + +- modified init to be applied more than once [\#29](https://github.com/knsv/mermaid/issues/29) +- Wanted to know build process for the project. [\#28](https://github.com/knsv/mermaid/issues/28) +- Container support [\#27](https://github.com/knsv/mermaid/issues/27) +- can not support Chinese description [\#20](https://github.com/knsv/mermaid/issues/20) +- Node Label text mistaken for Direction [\#17](https://github.com/knsv/mermaid/issues/17) +- Support unicode chars in labels [\#9](https://github.com/knsv/mermaid/issues/9) +- Publish to NPM [\#7](https://github.com/knsv/mermaid/issues/7) + +## [0.2.10](https://github.com/knsv/mermaid/tree/0.2.10) (2014-12-01) + +[Full Changelog](https://github.com/knsv/mermaid/compare/0.2.9...0.2.10) + +## [0.2.9](https://github.com/knsv/mermaid/tree/0.2.9) (2014-12-01) + +[Full Changelog](https://github.com/knsv/mermaid/compare/0.2.8...0.2.9) + +**Closed issues:** + +- Add link to jsbin playground to README [\#11](https://github.com/knsv/mermaid/issues/11) +- What are the requirements ? [\#10](https://github.com/knsv/mermaid/issues/10) + +**Merged pull requests:** + +- Allow unicode chars in labels [\#13](https://github.com/knsv/mermaid/pull/13) ([codebeige](https://github.com/codebeige)) + +## [0.2.8](https://github.com/knsv/mermaid/tree/0.2.8) (2014-12-01) + +[Full Changelog](https://github.com/knsv/mermaid/compare/0.2.7...0.2.8) + +## [0.2.7](https://github.com/knsv/mermaid/tree/0.2.7) (2014-12-01) + +[Full Changelog](https://github.com/knsv/mermaid/compare/0.2.6...0.2.7) + +**Closed issues:** + +- Provide parser as separate module [\#4](https://github.com/knsv/mermaid/issues/4) + +## [0.2.6](https://github.com/knsv/mermaid/tree/0.2.6) (2014-11-27) + +[Full Changelog](https://github.com/knsv/mermaid/compare/0.2.5...0.2.6) + +## [0.2.5](https://github.com/knsv/mermaid/tree/0.2.5) (2014-11-27) + +[Full Changelog](https://github.com/knsv/mermaid/compare/0.2.4...0.2.5) + +**Merged pull requests:** + +- Added new shapes! [\#1](https://github.com/knsv/mermaid/pull/1) ([bjowes](https://github.com/bjowes)) + +## [0.2.4](https://github.com/knsv/mermaid/tree/0.2.4) (2014-11-25) + +[Full Changelog](https://github.com/knsv/mermaid/compare/0.2.3...0.2.4) + +## [0.2.3](https://github.com/knsv/mermaid/tree/0.2.3) (2014-11-24) + +[Full Changelog](https://github.com/knsv/mermaid/compare/0.2.2...0.2.3) + +## [0.2.2](https://github.com/knsv/mermaid/tree/0.2.2) (2014-11-22) + +[Full Changelog](https://github.com/knsv/mermaid/compare/0.2.1...0.2.2) + +## [0.2.1](https://github.com/knsv/mermaid/tree/0.2.1) (2014-11-22) + +[Full Changelog](https://github.com/knsv/mermaid/compare/0.2.0...0.2.1) + +## [0.2.0](https://github.com/knsv/mermaid/tree/0.2.0) (2014-11-22) + +[Full Changelog](https://github.com/knsv/mermaid/compare/0.1.1...0.2.0) + +## [0.1.1](https://github.com/knsv/mermaid/tree/0.1.1) (2014-11-17) + +[Full Changelog](https://github.com/knsv/mermaid/compare/0.1.0...0.1.1) + +## [0.1.0](https://github.com/knsv/mermaid/tree/0.1.0) (2014-11-16) diff --git a/packages/mermaid/package.json b/packages/mermaid/package.json index 2dd3248e4..43385ffe0 100644 --- a/packages/mermaid/package.json +++ b/packages/mermaid/package.json @@ -1,6 +1,6 @@ { "name": "mermaid", - "version": "11.8.1", + "version": "11.10.0", "description": "Markdown-ish syntax for generating flowcharts, mindmaps, sequence diagrams, class diagrams, gantt charts, git graphs and more.", "type": "module", "module": "./dist/mermaid.core.mjs", @@ -68,7 +68,7 @@ }, "dependencies": { "@braintree/sanitize-url": "^7.0.4", - "@iconify/utils": "^2.1.33", + "@iconify/utils": "^3.0.1", "@mermaid-js/parser": "workspace:^", "@types/d3": "^7.4.3", "cytoscape": "^3.29.3", @@ -123,8 +123,8 @@ "rimraf": "^6.0.1", "start-server-and-test": "^2.0.10", "type-fest": "^4.35.0", - "typedoc": "^0.27.8", - "typedoc-plugin-markdown": "^4.4.2", + "typedoc": "^0.28.9", + "typedoc-plugin-markdown": "^4.8.0", "typescript": "~5.7.3", "unist-util-flatmap": "^1.0.0", "unist-util-visit": "^5.0.0", diff --git a/packages/mermaid/scripts/docs.spec.ts b/packages/mermaid/scripts/docs.spec.ts index 68677d4c9..70923e226 100644 --- a/packages/mermaid/scripts/docs.spec.ts +++ b/packages/mermaid/scripts/docs.spec.ts @@ -171,7 +171,9 @@ This Markdown should be kept. expect(buildShapeDoc()).toMatchInlineSnapshot(` "| **Semantic Name** | **Shape Name** | **Short Name** | **Description** | **Alias Supported** | | --------------------------------- | ---------------------- | -------------- | ------------------------------ | ---------------------------------------------------------------- | + | Bang | Bang | \`bang\` | Bang | \`bang\` | | Card | Notched Rectangle | \`notch-rect\` | Represents a card | \`card\`, \`notched-rectangle\` | + | Cloud | Cloud | \`cloud\` | cloud | \`cloud\` | | Collate | Hourglass | \`hourglass\` | Represents a collate operation | \`collate\`, \`hourglass\` | | Com Link | Lightning Bolt | \`bolt\` | Communication link | \`com-link\`, \`lightning-bolt\` | | Comment | Curly Brace | \`brace\` | Adds a comment | \`brace-l\`, \`comment\` | diff --git a/packages/mermaid/src/config.spec.ts b/packages/mermaid/src/config.spec.ts index 000be1282..7fbae03af 100644 --- a/packages/mermaid/src/config.spec.ts +++ b/packages/mermaid/src/config.spec.ts @@ -78,3 +78,187 @@ describe('when working with site config', () => { expect(config_4.altFontFamily).toBeUndefined(); }); }); + +describe('getUserDefinedConfig', () => { + beforeEach(() => { + configApi.reset(); + }); + + it('should return empty object when no user config is defined', () => { + const userConfig = configApi.getUserDefinedConfig(); + expect(userConfig).toEqual({}); + }); + + it('should return config from initialize only', () => { + const initConfig: MermaidConfig = { theme: 'dark', fontFamily: 'Arial' }; + configApi.saveConfigFromInitialize(initConfig); + + const userConfig = configApi.getUserDefinedConfig(); + expect(userConfig).toEqual(initConfig); + }); + + it('should return config from directives only', () => { + const directive1: MermaidConfig = { layout: 'elk', fontSize: 14 }; + const directive2: MermaidConfig = { theme: 'forest' }; + + configApi.addDirective(directive1); + configApi.addDirective(directive2); + + expect(configApi.getUserDefinedConfig()).toMatchInlineSnapshot(` + { + "fontFamily": "Arial", + "fontSize": 14, + "layout": "elk", + "theme": "forest", + } + `); + }); + + it('should combine initialize config and directives', () => { + const initConfig: MermaidConfig = { theme: 'dark', fontFamily: 'Arial', layout: 'dagre' }; + const directive1: MermaidConfig = { layout: 'elk', fontSize: 14 }; + const directive2: MermaidConfig = { theme: 'forest' }; + + configApi.saveConfigFromInitialize(initConfig); + configApi.addDirective(directive1); + configApi.addDirective(directive2); + + const userConfig = configApi.getUserDefinedConfig(); + expect(userConfig).toMatchInlineSnapshot(` + { + "fontFamily": "Arial", + "fontSize": 14, + "layout": "elk", + "theme": "forest", + } + `); + }); + + it('should handle nested config objects properly', () => { + const initConfig: MermaidConfig = { + flowchart: { nodeSpacing: 50, rankSpacing: 100 }, + theme: 'default', + }; + const directive: MermaidConfig = { + flowchart: { nodeSpacing: 75, curve: 'basis' }, + mindmap: { padding: 20 }, + }; + + configApi.saveConfigFromInitialize(initConfig); + configApi.addDirective(directive); + + const userConfig = configApi.getUserDefinedConfig(); + expect(userConfig).toMatchInlineSnapshot(` + { + "flowchart": { + "curve": "basis", + "nodeSpacing": 75, + "rankSpacing": 100, + }, + "mindmap": { + "padding": 20, + }, + "theme": "default", + } + `); + }); + + it('should handle complex nested overrides', () => { + const initConfig: MermaidConfig = { + flowchart: { + nodeSpacing: 50, + rankSpacing: 100, + curve: 'linear', + }, + theme: 'default', + }; + const directive1: MermaidConfig = { + flowchart: { + nodeSpacing: 75, + }, + fontSize: 12, + }; + const directive2: MermaidConfig = { + flowchart: { + curve: 'basis', + nodeSpacing: 100, + }, + mindmap: { + padding: 15, + }, + }; + + configApi.saveConfigFromInitialize(initConfig); + configApi.addDirective(directive1); + configApi.addDirective(directive2); + + const userConfig = configApi.getUserDefinedConfig(); + expect(userConfig).toMatchInlineSnapshot(` + { + "flowchart": { + "curve": "basis", + "nodeSpacing": 100, + "rankSpacing": 100, + }, + "fontSize": 12, + "mindmap": { + "padding": 15, + }, + "theme": "default", + } + `); + }); + + it('should return independent copies (not references)', () => { + const initConfig: MermaidConfig = { theme: 'dark', flowchart: { nodeSpacing: 50 } }; + configApi.saveConfigFromInitialize(initConfig); + + const userConfig1 = configApi.getUserDefinedConfig(); + const userConfig2 = configApi.getUserDefinedConfig(); + + userConfig1.theme = 'neutral'; + userConfig1.flowchart!.nodeSpacing = 999; + + expect(userConfig2).toMatchInlineSnapshot(` + { + "flowchart": { + "nodeSpacing": 50, + }, + "theme": "dark", + } + `); + }); + + it('should handle edge cases with undefined values', () => { + const initConfig: MermaidConfig = { theme: 'dark', layout: undefined }; + const directive: MermaidConfig = { fontSize: 14, fontFamily: undefined }; + + configApi.saveConfigFromInitialize(initConfig); + configApi.addDirective(directive); + + expect(configApi.getUserDefinedConfig()).toMatchInlineSnapshot(` + { + "fontSize": 14, + "layout": undefined, + "theme": "dark", + } + `); + }); + + it('should retain config from initialize after reset', () => { + const initConfig: MermaidConfig = { theme: 'dark' }; + const directive: MermaidConfig = { layout: 'elk' }; + + configApi.saveConfigFromInitialize(initConfig); + configApi.addDirective(directive); + + expect(configApi.getUserDefinedConfig()).toMatchInlineSnapshot(` + { + "layout": "elk", + "theme": "dark", + } + `); + + configApi.reset(); + }); +}); diff --git a/packages/mermaid/src/config.ts b/packages/mermaid/src/config.ts index 9468a3e46..4fcb3224d 100644 --- a/packages/mermaid/src/config.ts +++ b/packages/mermaid/src/config.ts @@ -248,3 +248,17 @@ const checkConfig = (config: MermaidConfig) => { issueWarning('LAZY_LOAD_DEPRECATED'); } }; + +export const getUserDefinedConfig = (): MermaidConfig => { + let userConfig: MermaidConfig = {}; + + if (configFromInitialize) { + userConfig = assignWithDepth(userConfig, configFromInitialize); + } + + for (const d of directives) { + userConfig = assignWithDepth(userConfig, d); + } + + return userConfig; +}; diff --git a/packages/mermaid/src/config.type.ts b/packages/mermaid/src/config.type.ts index 8cd451c16..79fadd195 100644 --- a/packages/mermaid/src/config.type.ts +++ b/packages/mermaid/src/config.type.ts @@ -109,6 +109,16 @@ export interface MermaidConfig { | 'INTERACTIVE' | 'MODEL_ORDER' | 'GREEDY_MODEL_ORDER'; + /** + * The node order given by the model does not change to produce a better layout. E.g. if node A is before node B in the model this is not changed during crossing minimization. This assumes that the node model order is already respected before crossing minimization. This can be achieved by setting considerModelOrder.strategy to NODES_AND_EDGES. + * + */ + forceNodeModelOrder?: boolean; + /** + * Preserves the order of nodes and edges in the model file if this does not lead to additional edge crossings. Depending on the strategy this is not always possible since the node and edge order might be conflicting. + * + */ + considerModelOrder?: 'NONE' | 'NODES_AND_EDGES' | 'PREFER_EDGES' | 'PREFER_NODES'; }; darkMode?: boolean; htmlLabels?: boolean; @@ -1065,6 +1075,10 @@ export interface ArchitectureDiagramConfig extends BaseDiagramConfig { export interface MindmapDiagramConfig extends BaseDiagramConfig { padding?: number; maxNodeWidth?: number; + /** + * Layout algorithm to use for positioning mindmap nodes + */ + layoutAlgorithm?: string; } /** * The object containing configurations specific for kanban diagrams diff --git a/packages/mermaid/src/dagre-wrapper/createLabel.js b/packages/mermaid/src/dagre-wrapper/createLabel.js index 467eed260..fdab9a34e 100644 --- a/packages/mermaid/src/dagre-wrapper/createLabel.js +++ b/packages/mermaid/src/dagre-wrapper/createLabel.js @@ -1,9 +1,9 @@ import { select } from 'd3'; -import { log } from '../logger.js'; import { getConfig } from '../diagram-api/diagramAPI.js'; -import { evaluate } from '../diagrams/common/common.js'; -import { decodeEntities } from '../utils.js'; +import { evaluate, sanitizeText } from '../diagrams/common/common.js'; +import { log } from '../logger.js'; import { replaceIconSubstring } from '../rendering-util/createText.js'; +import { decodeEntities } from '../utils.js'; /** * @param dom @@ -19,14 +19,14 @@ function applyStyle(dom, styleFn) { * @param {any} node * @returns {SVGForeignObjectElement} Node */ -function addHtmlLabel(node) { +function addHtmlLabel(node, config) { const fo = select(document.createElementNS('http://www.w3.org/2000/svg', 'foreignObject')); const div = fo.append('xhtml:div'); const label = node.label; const labelClass = node.isNode ? 'nodeLabel' : 'edgeLabel'; const span = div.append('span'); - span.html(label); + span.html(sanitizeText(label, config)); applyStyle(span, node.labelStyle); span.attr('class', labelClass); @@ -49,7 +49,8 @@ const createLabel = async (_vertexText, style, isTitle, isNode) => { if (typeof vertexText === 'object') { vertexText = vertexText[0]; } - if (evaluate(getConfig().flowchart.htmlLabels)) { + const config = getConfig(); + if (evaluate(config.flowchart.htmlLabels)) { // TODO: addHtmlLabel accepts a labelStyle. Do we possibly have that? vertexText = vertexText.replace(/\\n|\n/g, '
'); log.debug('vertexText' + vertexText); @@ -59,7 +60,7 @@ const createLabel = async (_vertexText, style, isTitle, isNode) => { label, labelStyle: style.replace('fill:', 'color:'), }; - let vertexNode = addHtmlLabel(node); + let vertexNode = addHtmlLabel(node, config); // vertexNode.parentNode.removeChild(vertexNode); return vertexNode; } else { diff --git a/packages/mermaid/src/defaultConfig.ts b/packages/mermaid/src/defaultConfig.ts index 468f8e192..655bf3724 100644 --- a/packages/mermaid/src/defaultConfig.ts +++ b/packages/mermaid/src/defaultConfig.ts @@ -24,6 +24,8 @@ const config: RequiredDeep = { // mergeEdges is needed here to be considered mergeEdges: false, nodePlacementStrategy: 'BRANDES_KOEPF', + forceNodeModelOrder: false, + considerModelOrder: 'NODES_AND_EDGES', }, themeCSS: undefined, diff --git a/packages/mermaid/src/diagram-api/comments.spec.ts b/packages/mermaid/src/diagram-api/comments.spec.ts index 57a7d4a34..febca83e9 100644 --- a/packages/mermaid/src/diagram-api/comments.spec.ts +++ b/packages/mermaid/src/diagram-api/comments.spec.ts @@ -1,5 +1,3 @@ -// tests to check that comments are removed - import { cleanupComments } from './comments.js'; import { describe, it, expect } from 'vitest'; @@ -10,12 +8,12 @@ describe('comments', () => { %% This is a comment %% This is another comment graph TD - A-->B + A-->B %% This is a comment `; expect(cleanupComments(text)).toMatchInlineSnapshot(` "graph TD - A-->B + A-->B " `); }); @@ -29,9 +27,9 @@ graph TD %%{ init: {'theme': 'space before init'}}%% %%{init: {'theme': 'space after ending'}}%% graph TD - A-->B + A-->B - B-->C + B-->C %% This is a comment `; expect(cleanupComments(text)).toMatchInlineSnapshot(` @@ -39,9 +37,9 @@ graph TD %%{ init: {'theme': 'space before init'}}%% %%{init: {'theme': 'space after ending'}}%% graph TD - A-->B + A-->B - B-->C + B-->C " `); }); @@ -50,14 +48,14 @@ graph TD const text = ` %% This is a comment graph TD - A-->B - %% This is a comment - C-->D + A-->B + %% This is a comment + C-->D `; expect(cleanupComments(text)).toMatchInlineSnapshot(` "graph TD - A-->B - C-->D + A-->B + C-->D " `); }); @@ -70,11 +68,11 @@ graph TD %% This is a comment graph TD - A-->B + A-->B `; expect(cleanupComments(text)).toMatchInlineSnapshot(` "graph TD - A-->B + A-->B " `); }); @@ -82,12 +80,12 @@ graph TD it('should remove comments at end of text with no newline', () => { const text = ` graph TD - A-->B + A-->B %% This is a comment`; expect(cleanupComments(text)).toMatchInlineSnapshot(` "graph TD - A-->B + A-->B " `); }); diff --git a/packages/mermaid/src/diagram-api/diagram-orchestration.spec.ts b/packages/mermaid/src/diagram-api/diagram-orchestration.spec.ts index 3ec2d861f..f4f7c58bc 100644 --- a/packages/mermaid/src/diagram-api/diagram-orchestration.spec.ts +++ b/packages/mermaid/src/diagram-api/diagram-orchestration.spec.ts @@ -78,5 +78,41 @@ describe('diagram-orchestration', () => { flowchart: 1 "pie" pie: 2 "pie"`) ).toBe('pie'); }); + + it('should detect proper diagram when defaultRenderer is elk for flowchart', () => { + expect( + detectType('mindmap\n root\n Photograph\n Waterfall', { + flowchart: { defaultRenderer: 'elk' }, + }) + ).toBe('mindmap'); + expect( + detectType( + ` + classDiagram + class Person { + +String name + -Int id + #double age + +Text demographicProfile + } + `, + { flowchart: { defaultRenderer: 'elk' } } + ) + ).toBe('class'); + expect( + detectType( + ` + erDiagram + p[Photograph] { + varchar(12) jobId + date dateCreated + } + `, + { + flowchart: { defaultRenderer: 'elk' }, + } + ) + ).toBe('er'); + }); }); }); diff --git a/packages/mermaid/src/diagrams/architecture/architecture.spec.ts b/packages/mermaid/src/diagrams/architecture/architecture.spec.ts index d0405d025..49cc18a07 100644 --- a/packages/mermaid/src/diagrams/architecture/architecture.spec.ts +++ b/packages/mermaid/src/diagrams/architecture/architecture.spec.ts @@ -1,21 +1,12 @@ import { it, describe, expect } from 'vitest'; -import { db } from './architectureDb.js'; import { parser } from './architectureParser.js'; - -const { - clear, - getDiagramTitle, - getAccTitle, - getAccDescription, - getServices, - getGroups, - getEdges, - getJunctions, -} = db; - +import { ArchitectureDB } from './architectureDb.js'; describe('architecture diagrams', () => { + let db: ArchitectureDB; beforeEach(() => { - clear(); + db = new ArchitectureDB(); + // @ts-expect-error since type is set to undefined we will have error + parser.parser?.yy = db; }); describe('architecture diagram definitions', () => { @@ -36,7 +27,7 @@ describe('architecture diagrams', () => { it('should handle title on the first line', async () => { const str = `architecture-beta title Simple Architecture Diagram`; await expect(parser.parse(str)).resolves.not.toThrow(); - expect(getDiagramTitle()).toBe('Simple Architecture Diagram'); + expect(db.getDiagramTitle()).toBe('Simple Architecture Diagram'); }); it('should handle title on another line', async () => { @@ -44,7 +35,7 @@ describe('architecture diagrams', () => { title Simple Architecture Diagram `; await expect(parser.parse(str)).resolves.not.toThrow(); - expect(getDiagramTitle()).toBe('Simple Architecture Diagram'); + expect(db.getDiagramTitle()).toBe('Simple Architecture Diagram'); }); it('should handle accessibility title and description', async () => { @@ -53,8 +44,8 @@ describe('architecture diagrams', () => { accDescr: Accessibility Description `; await expect(parser.parse(str)).resolves.not.toThrow(); - expect(getAccTitle()).toBe('Accessibility Title'); - expect(getAccDescription()).toBe('Accessibility Description'); + expect(db.getAccTitle()).toBe('Accessibility Title'); + expect(db.getAccDescription()).toBe('Accessibility Description'); }); it('should handle multiline accessibility description', async () => { @@ -64,7 +55,7 @@ describe('architecture diagrams', () => { } `; await expect(parser.parse(str)).resolves.not.toThrow(); - expect(getAccDescription()).toBe('Accessibility Description'); + expect(db.getAccDescription()).toBe('Accessibility Description'); }); }); }); diff --git a/packages/mermaid/src/diagrams/architecture/architectureDb.ts b/packages/mermaid/src/diagrams/architecture/architectureDb.ts index c7bd64e21..4764671e8 100644 --- a/packages/mermaid/src/diagrams/architecture/architectureDb.ts +++ b/packages/mermaid/src/diagrams/architecture/architectureDb.ts @@ -1,8 +1,9 @@ +import { getConfig as commonGetConfig } from '../../config.js'; import type { ArchitectureDiagramConfig } from '../../config.type.js'; import DEFAULT_CONFIG from '../../defaultConfig.js'; -import { getConfig as commonGetConfig } from '../../config.js'; +import type { DiagramDB } from '../../diagram-api/types.js'; import type { D3Element } from '../../types.js'; -import { ImperativeState } from '../../utils/imperativeState.js'; +import { cleanAndMerge } from '../../utils.js'; import { clear as commonClear, getAccDescription, @@ -14,7 +15,6 @@ import { } from '../common/commonDb.js'; import type { ArchitectureAlignment, - ArchitectureDB, ArchitectureDirectionPair, ArchitectureDirectionPairMap, ArchitectureEdge, @@ -33,330 +33,333 @@ import { isArchitectureService, shiftPositionByArchitectureDirectionPair, } from './architectureTypes.js'; -import { cleanAndMerge } from '../../utils.js'; const DEFAULT_ARCHITECTURE_CONFIG: Required = DEFAULT_CONFIG.architecture; +export class ArchitectureDB implements DiagramDB { + private nodes: Record = {}; + private groups: Record = {}; + private edges: ArchitectureEdge[] = []; + private registeredIds: Record = {}; + private dataStructures?: ArchitectureState['dataStructures']; + private elements: Record = {}; -const state = new ImperativeState(() => ({ - nodes: {}, - groups: {}, - edges: [], - registeredIds: {}, - config: DEFAULT_ARCHITECTURE_CONFIG, - dataStructures: undefined, - elements: {}, -})); - -const clear = (): void => { - state.reset(); - commonClear(); -}; - -const addService = function ({ - id, - icon, - in: parent, - title, - iconText, -}: Omit) { - if (state.records.registeredIds[id] !== undefined) { - throw new Error( - `The service id [${id}] is already in use by another ${state.records.registeredIds[id]}` - ); - } - if (parent !== undefined) { - if (id === parent) { - throw new Error(`The service [${id}] cannot be placed within itself`); - } - if (state.records.registeredIds[parent] === undefined) { - throw new Error( - `The service [${id}]'s parent does not exist. Please make sure the parent is created before this service` - ); - } - if (state.records.registeredIds[parent] === 'node') { - throw new Error(`The service [${id}]'s parent is not a group`); - } + constructor() { + this.clear(); } - state.records.registeredIds[id] = 'node'; + public clear(): void { + this.nodes = {}; + this.groups = {}; + this.edges = []; + this.registeredIds = {}; + this.dataStructures = undefined; + this.elements = {}; + commonClear(); + } - state.records.nodes[id] = { + public addService({ id, - type: 'service', icon, + in: parent, + title, iconText, - title, - edges: [], - in: parent, - }; -}; - -const getServices = (): ArchitectureService[] => - Object.values(state.records.nodes).filter(isArchitectureService); - -const addJunction = function ({ id, in: parent }: Omit) { - state.records.registeredIds[id] = 'node'; - - state.records.nodes[id] = { - id, - type: 'junction', - edges: [], - in: parent, - }; -}; - -const getJunctions = (): ArchitectureJunction[] => - Object.values(state.records.nodes).filter(isArchitectureJunction); - -const getNodes = (): ArchitectureNode[] => Object.values(state.records.nodes); - -const getNode = (id: string): ArchitectureNode | null => state.records.nodes[id]; - -const addGroup = function ({ id, icon, in: parent, title }: ArchitectureGroup) { - if (state.records.registeredIds[id] !== undefined) { - throw new Error( - `The group id [${id}] is already in use by another ${state.records.registeredIds[id]}` - ); - } - if (parent !== undefined) { - if (id === parent) { - throw new Error(`The group [${id}] cannot be placed within itself`); - } - if (state.records.registeredIds[parent] === undefined) { + }: Omit): void { + if (this.registeredIds[id] !== undefined) { throw new Error( - `The group [${id}]'s parent does not exist. Please make sure the parent is created before this group` + `The service id [${id}] is already in use by another ${this.registeredIds[id]}` ); } - if (state.records.registeredIds[parent] === 'node') { - throw new Error(`The group [${id}]'s parent is not a group`); + if (parent !== undefined) { + if (id === parent) { + throw new Error(`The service [${id}] cannot be placed within itself`); + } + if (this.registeredIds[parent] === undefined) { + throw new Error( + `The service [${id}]'s parent does not exist. Please make sure the parent is created before this service` + ); + } + if (this.registeredIds[parent] === 'node') { + throw new Error(`The service [${id}]'s parent is not a group`); + } } + + this.registeredIds[id] = 'node'; + + this.nodes[id] = { + id, + type: 'service', + icon, + iconText, + title, + edges: [], + in: parent, + }; } - state.records.registeredIds[id] = 'group'; - - state.records.groups[id] = { - id, - icon, - title, - in: parent, - }; -}; -const getGroups = (): ArchitectureGroup[] => { - return Object.values(state.records.groups); -}; - -const addEdge = function ({ - lhsId, - rhsId, - lhsDir, - rhsDir, - lhsInto, - rhsInto, - lhsGroup, - rhsGroup, - title, -}: ArchitectureEdge) { - if (!isArchitectureDirection(lhsDir)) { - throw new Error( - `Invalid direction given for left hand side of edge ${lhsId}--${rhsId}. Expected (L,R,T,B) got ${lhsDir}` - ); - } - if (!isArchitectureDirection(rhsDir)) { - throw new Error( - `Invalid direction given for right hand side of edge ${lhsId}--${rhsId}. Expected (L,R,T,B) got ${rhsDir}` - ); + public getServices(): ArchitectureService[] { + return Object.values(this.nodes).filter(isArchitectureService); } - if (state.records.nodes[lhsId] === undefined && state.records.groups[lhsId] === undefined) { - throw new Error( - `The left-hand id [${lhsId}] does not yet exist. Please create the service/group before declaring an edge to it.` - ); - } - if (state.records.nodes[rhsId] === undefined && state.records.groups[lhsId] === undefined) { - throw new Error( - `The right-hand id [${rhsId}] does not yet exist. Please create the service/group before declaring an edge to it.` - ); + public addJunction({ id, in: parent }: Omit): void { + this.registeredIds[id] = 'node'; + + this.nodes[id] = { + id, + type: 'junction', + edges: [], + in: parent, + }; } - const lhsGroupId = state.records.nodes[lhsId].in; - const rhsGroupId = state.records.nodes[rhsId].in; - if (lhsGroup && lhsGroupId && rhsGroupId && lhsGroupId == rhsGroupId) { - throw new Error( - `The left-hand id [${lhsId}] is modified to traverse the group boundary, but the edge does not pass through two groups.` - ); - } - if (rhsGroup && lhsGroupId && rhsGroupId && lhsGroupId == rhsGroupId) { - throw new Error( - `The right-hand id [${rhsId}] is modified to traverse the group boundary, but the edge does not pass through two groups.` - ); + public getJunctions(): ArchitectureJunction[] { + return Object.values(this.nodes).filter(isArchitectureJunction); } - const edge = { + public getNodes(): ArchitectureNode[] { + return Object.values(this.nodes); + } + + public getNode(id: string): ArchitectureNode | null { + return this.nodes[id] ?? null; + } + + public addGroup({ id, icon, in: parent, title }: ArchitectureGroup): void { + if (this.registeredIds?.[id] !== undefined) { + throw new Error( + `The group id [${id}] is already in use by another ${this.registeredIds[id]}` + ); + } + if (parent !== undefined) { + if (id === parent) { + throw new Error(`The group [${id}] cannot be placed within itself`); + } + if (this.registeredIds?.[parent] === undefined) { + throw new Error( + `The group [${id}]'s parent does not exist. Please make sure the parent is created before this group` + ); + } + if (this.registeredIds?.[parent] === 'node') { + throw new Error(`The group [${id}]'s parent is not a group`); + } + } + + this.registeredIds[id] = 'group'; + + this.groups[id] = { + id, + icon, + title, + in: parent, + }; + } + public getGroups(): ArchitectureGroup[] { + return Object.values(this.groups); + } + public addEdge({ lhsId, - lhsDir, - lhsInto, - lhsGroup, rhsId, + lhsDir, rhsDir, + lhsInto, rhsInto, + lhsGroup, rhsGroup, title, - }; - - state.records.edges.push(edge); - if (state.records.nodes[lhsId] && state.records.nodes[rhsId]) { - state.records.nodes[lhsId].edges.push(state.records.edges[state.records.edges.length - 1]); - state.records.nodes[rhsId].edges.push(state.records.edges[state.records.edges.length - 1]); - } -}; - -const getEdges = (): ArchitectureEdge[] => state.records.edges; - -/** - * Returns the current diagram's adjacency list, spatial map, & group alignments. - * If they have not been created, run the algorithms to generate them. - * @returns - */ -const getDataStructures = () => { - if (state.records.dataStructures === undefined) { - // Tracks how groups are aligned with one another. Generated while creating the adj list - const groupAlignments: Record< - string, - Record> - > = {}; - - // Create an adjacency list of the diagram to perform BFS on - // Outer reduce applied on all services - // Inner reduce applied on the edges for a service - const adjList = Object.entries(state.records.nodes).reduce< - Record - >((prevOuter, [id, service]) => { - prevOuter[id] = service.edges.reduce((prevInner, edge) => { - // track the direction groups connect to one another - const lhsGroupId = getNode(edge.lhsId)?.in; - const rhsGroupId = getNode(edge.rhsId)?.in; - if (lhsGroupId && rhsGroupId && lhsGroupId !== rhsGroupId) { - const alignment = getArchitectureDirectionAlignment(edge.lhsDir, edge.rhsDir); - if (alignment !== 'bend') { - groupAlignments[lhsGroupId] ??= {}; - groupAlignments[lhsGroupId][rhsGroupId] = alignment; - groupAlignments[rhsGroupId] ??= {}; - groupAlignments[rhsGroupId][lhsGroupId] = alignment; - } - } - - if (edge.lhsId === id) { - // source is LHS - const pair = getArchitectureDirectionPair(edge.lhsDir, edge.rhsDir); - if (pair) { - prevInner[pair] = edge.rhsId; - } - } else { - // source is RHS - const pair = getArchitectureDirectionPair(edge.rhsDir, edge.lhsDir); - if (pair) { - prevInner[pair] = edge.lhsId; - } - } - return prevInner; - }, {}); - return prevOuter; - }, {}); - - // Configuration for the initial pass of BFS - const firstId = Object.keys(adjList)[0]; - const visited = { [firstId]: 1 }; - // If a key is present in this object, it has not been visited - const notVisited = Object.keys(adjList).reduce( - (prev, id) => (id === firstId ? prev : { ...prev, [id]: 1 }), - {} as Record - ); - - // Perform BFS on the adjacency list - const BFS = (startingId: string): ArchitectureSpatialMap => { - const spatialMap = { [startingId]: [0, 0] }; - const queue = [startingId]; - while (queue.length > 0) { - const id = queue.shift(); - if (id) { - visited[id] = 1; - delete notVisited[id]; - const adj = adjList[id]; - const [posX, posY] = spatialMap[id]; - Object.entries(adj).forEach(([dir, rhsId]) => { - if (!visited[rhsId]) { - spatialMap[rhsId] = shiftPositionByArchitectureDirectionPair( - [posX, posY], - dir as ArchitectureDirectionPair - ); - queue.push(rhsId); - } - }); - } - } - return spatialMap; - }; - const spatialMaps = [BFS(firstId)]; - - // If our diagram is disconnected, keep adding additional spatial maps until all disconnected graphs have been found - while (Object.keys(notVisited).length > 0) { - spatialMaps.push(BFS(Object.keys(notVisited)[0])); + }: ArchitectureEdge): void { + if (!isArchitectureDirection(lhsDir)) { + throw new Error( + `Invalid direction given for left hand side of edge ${lhsId}--${rhsId}. Expected (L,R,T,B) got ${String(lhsDir)}` + ); } - state.records.dataStructures = { - adjList, - spatialMaps, - groupAlignments, + if (!isArchitectureDirection(rhsDir)) { + throw new Error( + `Invalid direction given for right hand side of edge ${lhsId}--${rhsId}. Expected (L,R,T,B) got ${String(rhsDir)}` + ); + } + + if (this.nodes[lhsId] === undefined && this.groups[lhsId] === undefined) { + throw new Error( + `The left-hand id [${lhsId}] does not yet exist. Please create the service/group before declaring an edge to it.` + ); + } + if (this.nodes[rhsId] === undefined && this.groups[rhsId] === undefined) { + throw new Error( + `The right-hand id [${rhsId}] does not yet exist. Please create the service/group before declaring an edge to it.` + ); + } + + const lhsGroupId = this.nodes[lhsId].in; + const rhsGroupId = this.nodes[rhsId].in; + if (lhsGroup && lhsGroupId && rhsGroupId && lhsGroupId == rhsGroupId) { + throw new Error( + `The left-hand id [${lhsId}] is modified to traverse the group boundary, but the edge does not pass through two groups.` + ); + } + if (rhsGroup && lhsGroupId && rhsGroupId && lhsGroupId == rhsGroupId) { + throw new Error( + `The right-hand id [${rhsId}] is modified to traverse the group boundary, but the edge does not pass through two groups.` + ); + } + + const edge = { + lhsId, + lhsDir, + lhsInto, + lhsGroup, + rhsId, + rhsDir, + rhsInto, + rhsGroup, + title, }; + + this.edges.push(edge); + if (this.nodes[lhsId] && this.nodes[rhsId]) { + this.nodes[lhsId].edges.push(this.edges[this.edges.length - 1]); + this.nodes[rhsId].edges.push(this.edges[this.edges.length - 1]); + } } - return state.records.dataStructures; -}; -const setElementForId = (id: string, element: D3Element) => { - state.records.elements[id] = element; -}; -const getElementById = (id: string) => state.records.elements[id]; + public getEdges(): ArchitectureEdge[] { + return this.edges; + } -const getConfig = (): Required => { - const config = cleanAndMerge({ - ...DEFAULT_ARCHITECTURE_CONFIG, - ...commonGetConfig().architecture, - }); - return config; -}; + /** + * Returns the current diagram's adjacency list, spatial map, & group alignments. + * If they have not been created, run the algorithms to generate them. + * @returns + */ + public getDataStructures() { + if (this.dataStructures === undefined) { + // Tracks how groups are aligned with one another. Generated while creating the adj list + const groupAlignments: Record< + string, + Record> + > = {}; -export const db: ArchitectureDB = { - clear, - setDiagramTitle, - getDiagramTitle, - setAccTitle, - getAccTitle, - setAccDescription, - getAccDescription, - getConfig, + // Create an adjacency list of the diagram to perform BFS on + // Outer reduce applied on all services + // Inner reduce applied on the edges for a service + const adjList = Object.entries(this.nodes).reduce< + Record + >((prevOuter, [id, service]) => { + prevOuter[id] = service.edges.reduce((prevInner, edge) => { + // track the direction groups connect to one another + const lhsGroupId = this.getNode(edge.lhsId)?.in; + const rhsGroupId = this.getNode(edge.rhsId)?.in; + if (lhsGroupId && rhsGroupId && lhsGroupId !== rhsGroupId) { + const alignment = getArchitectureDirectionAlignment(edge.lhsDir, edge.rhsDir); + if (alignment !== 'bend') { + groupAlignments[lhsGroupId] ??= {}; + groupAlignments[lhsGroupId][rhsGroupId] = alignment; + groupAlignments[rhsGroupId] ??= {}; + groupAlignments[rhsGroupId][lhsGroupId] = alignment; + } + } - addService, - getServices, - addJunction, - getJunctions, - getNodes, - getNode, - addGroup, - getGroups, - addEdge, - getEdges, - setElementForId, - getElementById, - getDataStructures, -}; + if (edge.lhsId === id) { + // source is LHS + const pair = getArchitectureDirectionPair(edge.lhsDir, edge.rhsDir); + if (pair) { + prevInner[pair] = edge.rhsId; + } + } else { + // source is RHS + const pair = getArchitectureDirectionPair(edge.rhsDir, edge.lhsDir); + if (pair) { + prevInner[pair] = edge.lhsId; + } + } + return prevInner; + }, {}); + return prevOuter; + }, {}); + + // Configuration for the initial pass of BFS + const firstId = Object.keys(adjList)[0]; + const visited = { [firstId]: 1 }; + // If a key is present in this object, it has not been visited + const notVisited = Object.keys(adjList).reduce( + (prev, id) => (id === firstId ? prev : { ...prev, [id]: 1 }), + {} as Record + ); + + // Perform BFS on the adjacency list + const BFS = (startingId: string): ArchitectureSpatialMap => { + const spatialMap = { [startingId]: [0, 0] }; + const queue = [startingId]; + while (queue.length > 0) { + const id = queue.shift(); + if (id) { + visited[id] = 1; + delete notVisited[id]; + const adj = adjList[id]; + const [posX, posY] = spatialMap[id]; + Object.entries(adj).forEach(([dir, rhsId]) => { + if (!visited[rhsId]) { + spatialMap[rhsId] = shiftPositionByArchitectureDirectionPair( + [posX, posY], + dir as ArchitectureDirectionPair + ); + queue.push(rhsId); + } + }); + } + } + return spatialMap; + }; + const spatialMaps = [BFS(firstId)]; + + // If our diagram is disconnected, keep adding additional spatial maps until all disconnected graphs have been found + while (Object.keys(notVisited).length > 0) { + spatialMaps.push(BFS(Object.keys(notVisited)[0])); + } + this.dataStructures = { + adjList, + spatialMaps, + groupAlignments, + }; + } + return this.dataStructures; + } + + public setElementForId(id: string, element: D3Element): void { + this.elements[id] = element; + } + + public getElementById(id: string): D3Element { + return this.elements[id]; + } + + public getConfig(): Required { + return cleanAndMerge({ + ...DEFAULT_ARCHITECTURE_CONFIG, + ...commonGetConfig().architecture, + }); + } + + public getConfigField( + field: T + ): Required[T] { + return this.getConfig()[field]; + } + + public setAccTitle = setAccTitle; + public getAccTitle = getAccTitle; + public setDiagramTitle = setDiagramTitle; + public getDiagramTitle = getDiagramTitle; + public getAccDescription = getAccDescription; + public setAccDescription = setAccDescription; +} /** * Typed wrapper for resolving an architecture diagram's config fields. Returns the default value if undefined * @param field - the config field to access * @returns */ -export function getConfigField( - field: T -): Required[T] { - return getConfig()[field]; -} +// export function getConfigField( +// field: T +// ): Required[T] { +// return db.getConfig()[field]; +// } diff --git a/packages/mermaid/src/diagrams/architecture/architectureDiagram.ts b/packages/mermaid/src/diagrams/architecture/architectureDiagram.ts index 82dacd3e1..1d390a3ab 100644 --- a/packages/mermaid/src/diagrams/architecture/architectureDiagram.ts +++ b/packages/mermaid/src/diagrams/architecture/architectureDiagram.ts @@ -1,12 +1,14 @@ import type { DiagramDefinition } from '../../diagram-api/types.js'; import { parser } from './architectureParser.js'; -import { db } from './architectureDb.js'; +import { ArchitectureDB } from './architectureDb.js'; import styles from './architectureStyles.js'; import { renderer } from './architectureRenderer.js'; export const diagram: DiagramDefinition = { parser, - db, + get db() { + return new ArchitectureDB(); + }, renderer, styles, }; diff --git a/packages/mermaid/src/diagrams/architecture/architectureParser.ts b/packages/mermaid/src/diagrams/architecture/architectureParser.ts index a7159d907..58820dad4 100644 --- a/packages/mermaid/src/diagrams/architecture/architectureParser.ts +++ b/packages/mermaid/src/diagrams/architecture/architectureParser.ts @@ -1,24 +1,33 @@ import type { Architecture } from '@mermaid-js/parser'; import { parse } from '@mermaid-js/parser'; -import { log } from '../../logger.js'; import type { ParserDefinition } from '../../diagram-api/types.js'; +import { log } from '../../logger.js'; import { populateCommonDb } from '../common/populateCommonDb.js'; -import type { ArchitectureDB } from './architectureTypes.js'; -import { db } from './architectureDb.js'; +import { ArchitectureDB } from './architectureDb.js'; const populateDb = (ast: Architecture, db: ArchitectureDB) => { populateCommonDb(ast, db); - ast.groups.map(db.addGroup); + ast.groups.map((group) => db.addGroup(group)); ast.services.map((service) => db.addService({ ...service, type: 'service' })); ast.junctions.map((service) => db.addJunction({ ...service, type: 'junction' })); // @ts-ignore TODO our parser guarantees the type is L/R/T/B and not string. How to change to union type? - ast.edges.map(db.addEdge); + ast.edges.map((edge) => db.addEdge(edge)); }; export const parser: ParserDefinition = { + parser: { + // @ts-expect-error - ArchitectureDB is not assignable to DiagramDB + yy: undefined, + }, parse: async (input: string): Promise => { const ast: Architecture = await parse('architecture', input); log.debug(ast); + const db = parser.parser?.yy; + if (!(db instanceof ArchitectureDB)) { + throw new Error( + 'parser.parser?.yy was not a ArchitectureDB. This is due to a bug within Mermaid, please report this issue at https://github.com/mermaid-js/mermaid/issues.' + ); + } populateDb(ast, db); }, }; diff --git a/packages/mermaid/src/diagrams/architecture/architectureRenderer.ts b/packages/mermaid/src/diagrams/architecture/architectureRenderer.ts index 1505b1950..608b11816 100644 --- a/packages/mermaid/src/diagrams/architecture/architectureRenderer.ts +++ b/packages/mermaid/src/diagrams/architecture/architectureRenderer.ts @@ -1,15 +1,14 @@ -import { registerIconPacks } from '../../rendering-util/icons.js'; -import type { Position } from 'cytoscape'; +import type { LayoutOptions, Position } from 'cytoscape'; import cytoscape from 'cytoscape'; -import type { FcoseLayoutOptions } from 'cytoscape-fcose'; import fcose from 'cytoscape-fcose'; import { select } from 'd3'; import type { DrawDefinition, SVG } from '../../diagram-api/types.js'; import type { Diagram } from '../../Diagram.js'; import { log } from '../../logger.js'; +import { registerIconPacks } from '../../rendering-util/icons.js'; import { selectSvgElement } from '../../rendering-util/selectSvgElement.js'; import { setupGraphViewbox } from '../../setupGraphViewbox.js'; -import { getConfigField } from './architectureDb.js'; +import type { ArchitectureDB } from './architectureDb.js'; import { architectureIcons } from './architectureIcons.js'; import type { ArchitectureAlignment, @@ -22,7 +21,6 @@ import type { NodeSingularData, } from './architectureTypes.js'; import { - type ArchitectureDB, type ArchitectureDirection, type ArchitectureEdge, type ArchitectureGroup, @@ -42,9 +40,9 @@ registerIconPacks([ icons: architectureIcons, }, ]); -cytoscape.use(fcose); +cytoscape.use(fcose as any); -function addServices(services: ArchitectureService[], cy: cytoscape.Core) { +function addServices(services: ArchitectureService[], cy: cytoscape.Core, db: ArchitectureDB) { services.forEach((service) => { cy.add({ group: 'nodes', @@ -54,15 +52,15 @@ function addServices(services: ArchitectureService[], cy: cytoscape.Core) { icon: service.icon, label: service.title, parent: service.in, - width: getConfigField('iconSize'), - height: getConfigField('iconSize'), + width: db.getConfigField('iconSize'), + height: db.getConfigField('iconSize'), } as NodeSingularData, classes: 'node-service', }); }); } -function addJunctions(junctions: ArchitectureJunction[], cy: cytoscape.Core) { +function addJunctions(junctions: ArchitectureJunction[], cy: cytoscape.Core, db: ArchitectureDB) { junctions.forEach((junction) => { cy.add({ group: 'nodes', @@ -70,8 +68,8 @@ function addJunctions(junctions: ArchitectureJunction[], cy: cytoscape.Core) { type: 'junction', id: junction.id, parent: junction.in, - width: getConfigField('iconSize'), - height: getConfigField('iconSize'), + width: db.getConfigField('iconSize'), + height: db.getConfigField('iconSize'), } as NodeSingularData, classes: 'node-junction', }); @@ -257,7 +255,8 @@ function getAlignments( } function getRelativeConstraints( - spatialMaps: ArchitectureSpatialMap[] + spatialMaps: ArchitectureSpatialMap[], + db: ArchitectureDB ): fcose.FcoseRelativePlacementConstraint[] { const relativeConstraints: fcose.FcoseRelativePlacementConstraint[] = []; const posToStr = (pos: number[]) => `${pos[0]},${pos[1]}`; @@ -296,7 +295,7 @@ function getRelativeConstraints( [ArchitectureDirectionName[ getOppositeArchitectureDirection(dir as ArchitectureDirection) ]]: currId, - gap: 1.5 * getConfigField('iconSize'), + gap: 1.5 * db.getConfigField('iconSize'), }); } }); @@ -353,7 +352,7 @@ function layoutArchitecture( style: { 'text-valign': 'bottom', 'text-halign': 'center', - 'font-size': `${getConfigField('fontSize')}px`, + 'font-size': `${db.getConfigField('fontSize')}px`, }, }, { @@ -375,7 +374,7 @@ function layoutArchitecture( selector: '.node-group', style: { // @ts-ignore Incorrect library types - padding: `${getConfigField('padding')}px`, + padding: `${db.getConfigField('padding')}px`, }, }, ], @@ -393,14 +392,14 @@ function layoutArchitecture( renderEl.remove(); addGroups(groups, cy); - addServices(services, cy); - addJunctions(junctions, cy); + addServices(services, cy, db); + addJunctions(junctions, cy, db); addEdges(edges, cy); // Use the spatial map to create alignment arrays for fcose const alignmentConstraint = getAlignments(db, spatialMaps, groupAlignments); // Create the relative constraints for fcose by using an inverse of the spatial map and performing BFS on it - const relativePlacementConstraint = getRelativeConstraints(spatialMaps); + const relativePlacementConstraint = getRelativeConstraints(spatialMaps, db); const layout = cy.layout({ name: 'fcose', @@ -415,7 +414,9 @@ function layoutArchitecture( const { parent: parentA } = nodeData(nodeA); const { parent: parentB } = nodeData(nodeB); const elasticity = - parentA === parentB ? 1.5 * getConfigField('iconSize') : 0.5 * getConfigField('iconSize'); + parentA === parentB + ? 1.5 * db.getConfigField('iconSize') + : 0.5 * db.getConfigField('iconSize'); return elasticity; }, edgeElasticity(edge: EdgeSingular) { @@ -427,7 +428,7 @@ function layoutArchitecture( }, alignmentConstraint, relativePlacementConstraint, - } as FcoseLayoutOptions); + } as LayoutOptions); // Once the diagram has been generated and the service's position cords are set, adjust the XY edges to have a 90deg bend layout.one('layoutstop', () => { @@ -535,11 +536,11 @@ export const draw: DrawDefinition = async (text, id, _version, diagObj: Diagram) const cy = await layoutArchitecture(services, junctions, groups, edges, db, ds); - await drawEdges(edgesElem, cy); - await drawGroups(groupElem, cy); + await drawEdges(edgesElem, cy, db); + await drawGroups(groupElem, cy, db); positionNodes(db, cy); - setupGraphViewbox(undefined, svg, getConfigField('padding'), getConfigField('useMaxWidth')); + setupGraphViewbox(undefined, svg, db.getConfigField('padding'), db.getConfigField('useMaxWidth')); }; export const renderer = { draw }; diff --git a/packages/mermaid/src/diagrams/architecture/svgDraw.ts b/packages/mermaid/src/diagrams/architecture/svgDraw.ts index b10a451fe..6e470caa2 100644 --- a/packages/mermaid/src/diagrams/architecture/svgDraw.ts +++ b/packages/mermaid/src/diagrams/architecture/svgDraw.ts @@ -1,9 +1,10 @@ -import { getIconSVG } from '../../rendering-util/icons.js'; import type cytoscape from 'cytoscape'; import { getConfig } from '../../diagram-api/diagramAPI.js'; import { createText } from '../../rendering-util/createText.js'; +import { getIconSVG } from '../../rendering-util/icons.js'; import type { D3Element } from '../../types.js'; -import { db, getConfigField } from './architectureDb.js'; +import { sanitizeText } from '../common/common.js'; +import type { ArchitectureDB } from './architectureDb.js'; import { architectureIcons } from './architectureIcons.js'; import { ArchitectureDirectionArrow, @@ -16,14 +17,17 @@ import { isArchitectureDirectionY, isArchitecturePairXY, nodeData, - type ArchitectureDB, type ArchitectureJunction, type ArchitectureService, } from './architectureTypes.js'; -export const drawEdges = async function (edgesEl: D3Element, cy: cytoscape.Core) { - const padding = getConfigField('padding'); - const iconSize = getConfigField('iconSize'); +export const drawEdges = async function ( + edgesEl: D3Element, + cy: cytoscape.Core, + db: ArchitectureDB +) { + const padding = db.getConfigField('padding'); + const iconSize = db.getConfigField('iconSize'); const halfIconSize = iconSize / 2; const arrowSize = iconSize / 6; const halfArrowSize = arrowSize / 2; @@ -183,13 +187,17 @@ export const drawEdges = async function (edgesEl: D3Element, cy: cytoscape.Core) ); }; -export const drawGroups = async function (groupsEl: D3Element, cy: cytoscape.Core) { - const padding = getConfigField('padding'); +export const drawGroups = async function ( + groupsEl: D3Element, + cy: cytoscape.Core, + db: ArchitectureDB +) { + const padding = db.getConfigField('padding'); const groupIconSize = padding * 0.75; - const fontSize = getConfigField('fontSize'); + const fontSize = db.getConfigField('fontSize'); - const iconSize = getConfigField('iconSize'); + const iconSize = db.getConfigField('iconSize'); const halfIconSize = iconSize / 2; await Promise.all( @@ -264,9 +272,10 @@ export const drawServices = async function ( elem: D3Element, services: ArchitectureService[] ): Promise { + const config = getConfig(); for (const service of services) { const serviceElem = elem.append('g'); - const iconSize = getConfigField('iconSize'); + const iconSize = db.getConfigField('iconSize'); if (service.title) { const textElem = serviceElem.append('g'); @@ -278,7 +287,7 @@ export const drawServices = async function ( width: iconSize * 1.5, classes: 'architecture-service-label', }, - getConfig() + config ); textElem @@ -313,7 +322,7 @@ export const drawServices = async function ( .attr('class', 'node-icon-text') .attr('style', `height: ${iconSize}px;`) .append('div') - .html(service.iconText); + .html(sanitizeText(service.iconText, config)); const fontSize = parseInt( window @@ -350,7 +359,7 @@ export const drawJunctions = function ( ) { junctions.forEach((junction) => { const junctionElem = elem.append('g'); - const iconSize = getConfigField('iconSize'); + const iconSize = db.getConfigField('iconSize'); const bkgElem = junctionElem.append('g'); bkgElem diff --git a/packages/mermaid/src/diagrams/block/blockDB.ts b/packages/mermaid/src/diagrams/block/blockDB.ts index 854969012..b291be61e 100644 --- a/packages/mermaid/src/diagrams/block/blockDB.ts +++ b/packages/mermaid/src/diagrams/block/blockDB.ts @@ -92,7 +92,20 @@ export const setCssClass = function (itemIds: string, cssClassName: string) { const populateBlockDatabase = (_blockList: Block[], parent: Block): void => { const blockList = _blockList.flat(); const children = []; + const columnSettingBlock = blockList.find((b) => b?.type === 'column-setting'); + const column = columnSettingBlock?.columns ?? -1; for (const block of blockList) { + if ( + typeof column === 'number' && + column > 0 && + block.type !== 'column-setting' && + typeof block.widthInColumns === 'number' && + block.widthInColumns > column + ) { + log.warn( + `Block ${block.id} width ${block.widthInColumns} exceeds configured column width ${column}` + ); + } if (block.label) { block.label = sanitizeText(block.label); } @@ -225,13 +238,15 @@ export function edgeTypeStr2Type(typeStr: string): string { } export function edgeStrToEdgeData(typeStr: string): string { - switch (typeStr.trim()) { - case '--x': + switch (typeStr.replace(/^[\s-]+|[\s-]+$/g, '')) { + case 'x': return 'arrow_cross'; - case '--o': + case 'o': return 'arrow_circle'; - default: + case '>': return 'arrow_point'; + default: + return ''; } } diff --git a/packages/mermaid/src/diagrams/block/blockDetector.ts b/packages/mermaid/src/diagrams/block/blockDetector.ts index c4da643f0..6122221e8 100644 --- a/packages/mermaid/src/diagrams/block/blockDetector.ts +++ b/packages/mermaid/src/diagrams/block/blockDetector.ts @@ -3,7 +3,7 @@ import type { DiagramDetector, ExternalDiagramDefinition } from '../../diagram-a const id = 'block'; const detector: DiagramDetector = (txt) => { - return /^\s*block-beta/.test(txt); + return /^\s*block(-beta)?/.test(txt); }; const loader = async () => { diff --git a/packages/mermaid/src/diagrams/block/layout.ts b/packages/mermaid/src/diagrams/block/layout.ts index a00e935ac..ea0de6312 100644 --- a/packages/mermaid/src/diagrams/block/layout.ts +++ b/packages/mermaid/src/diagrams/block/layout.ts @@ -270,7 +270,12 @@ function layoutBlocks(block: Block, db: BlockDB) { if (child.children) { layoutBlocks(child, db); } - columnPos += child?.widthInColumns ?? 1; + let columnsFilled = child?.widthInColumns ?? 1; + if (columns > 0) { + // Make sure overflowing lines do not affect later lines + columnsFilled = Math.min(columnsFilled, columns - (columnPos % columns)); + } + columnPos += columnsFilled; log.debug('abc88 columnsPos', child, columnPos); } } diff --git a/packages/mermaid/src/diagrams/block/parser/block.jison b/packages/mermaid/src/diagrams/block/parser/block.jison index 88bdf729e..3aa2759a6 100644 --- a/packages/mermaid/src/diagrams/block/parser/block.jison +++ b/packages/mermaid/src/diagrams/block/parser/block.jison @@ -36,10 +36,10 @@ CRLF \u000D\u000A %% -"block-beta" { return 'BLOCK_DIAGRAM_KEY'; } -"block"\s+ { yy.getLogger().debug('Found space-block'); return 'block';} -"block"\n+ { yy.getLogger().debug('Found nl-block'); return 'block';} -"block:" { yy.getLogger().debug('Found space-block'); return 'id-block';} +"block-beta" { yy.getLogger().debug('Found block-beta'); return 'BLOCK_DIAGRAM_KEY'; } +"block:" { yy.getLogger().debug('Found id-block'); return 'id-block'; } +"block" { yy.getLogger().debug('Found block'); return 'BLOCK_DIAGRAM_KEY'; } + // \s*\%\%.* { yy.getLogger().debug('Found comment',yytext); } [\s]+ { yy.getLogger().debug('.', yytext); /* skip all whitespace */ } [\n]+ {yy.getLogger().debug('_', yytext); /* skip all whitespace */ } @@ -240,7 +240,7 @@ columnsStatement blockStatement : id-block nodeStatement document end { yy.getLogger().debug('Rule: id-block statement : ', $2, $3); const id2 = yy.generateId(); $$ = { ...$2, type:'composite', children: $3 }; } - | block document end { yy.getLogger().debug('Rule: blockStatement : ', $1, $2, $3); const id = yy.generateId(); $$ = { id, type:'composite', label:'', children: $2 }; } + | BLOCK_DIAGRAM_KEY document end { yy.getLogger().debug('Rule: blockStatement : ', $1, $2, $3); const id = yy.generateId(); $$ = { id, type:'composite', label:'', children: $2 }; } ; node diff --git a/packages/mermaid/src/diagrams/block/parser/block.spec.ts b/packages/mermaid/src/diagrams/block/parser/block.spec.ts index 4bf3290d8..e6ad90a65 100644 --- a/packages/mermaid/src/diagrams/block/parser/block.spec.ts +++ b/packages/mermaid/src/diagrams/block/parser/block.spec.ts @@ -1,6 +1,7 @@ // @ts-ignore: jison doesn't export types import block from './block.jison'; import db from '../blockDB.js'; +import { log } from '../../../logger.js'; describe('Block diagram', function () { describe('when parsing a block diagram graph it should handle > ', function () { @@ -22,7 +23,7 @@ describe('Block diagram', function () { expect(blocks[0].label).toBe('id'); }); it('a node with a square shape and a label', () => { - const str = `block-beta + const str = `block id["A label"] `; @@ -34,7 +35,7 @@ describe('Block diagram', function () { expect(blocks[0].type).toBe('square'); }); it('a diagram with multiple nodes', () => { - const str = `block-beta + const str = `block id1 id2 `; @@ -50,7 +51,7 @@ describe('Block diagram', function () { expect(blocks[1].type).toBe('na'); }); it('a diagram with multiple nodes', () => { - const str = `block-beta + const str = `block id1 id2 id3 @@ -71,7 +72,7 @@ describe('Block diagram', function () { }); it('a node with a square shape and a label', () => { - const str = `block-beta + const str = `block id["A label"] id2`; @@ -86,7 +87,7 @@ describe('Block diagram', function () { expect(blocks[1].type).toBe('na'); }); it('a diagram with multiple nodes with edges abc123', () => { - const str = `block-beta + const str = `block id1["first"] --> id2["second"] `; @@ -100,7 +101,7 @@ describe('Block diagram', function () { expect(edges[0].arrowTypeEnd).toBe('arrow_point'); }); it('a diagram with multiple nodes with edges abc123', () => { - const str = `block-beta + const str = `block id1["first"] -- "a label" --> id2["second"] `; @@ -115,7 +116,7 @@ describe('Block diagram', function () { expect(edges[0].label).toBe('a label'); }); it('a diagram with column statements', () => { - const str = `block-beta + const str = `block columns 2 block1["Block 1"] `; @@ -126,7 +127,7 @@ describe('Block diagram', function () { expect(blocks.length).toBe(1); }); it('a diagram without column statements', () => { - const str = `block-beta + const str = `block block1["Block 1"] `; @@ -136,7 +137,7 @@ describe('Block diagram', function () { expect(blocks.length).toBe(1); }); it('a diagram with auto column statements', () => { - const str = `block-beta + const str = `block columns auto block1["Block 1"] `; @@ -148,7 +149,7 @@ describe('Block diagram', function () { }); it('blocks next to each other', () => { - const str = `block-beta + const str = `block columns 2 block1["Block 1"] block2["Block 2"] @@ -162,7 +163,7 @@ describe('Block diagram', function () { }); it('blocks on top of each other', () => { - const str = `block-beta + const str = `block columns 1 block1["Block 1"] block2["Block 2"] @@ -176,7 +177,7 @@ describe('Block diagram', function () { }); it('compound blocks 2', () => { - const str = `block-beta + const str = `block block aBlock["ABlock"] bBlock["BBlock"] @@ -204,7 +205,7 @@ describe('Block diagram', function () { expect(bBlock.type).toBe('square'); }); it('compound blocks of compound blocks', () => { - const str = `block-beta + const str = `block block aBlock["ABlock"] block @@ -239,7 +240,7 @@ describe('Block diagram', function () { expect(bBlock.type).toBe('square'); }); it('compound blocks with title', () => { - const str = `block-beta + const str = `block block:compoundBlock["Compound block"] columns 1 block2["Block 2"] @@ -264,7 +265,7 @@ describe('Block diagram', function () { expect(block2.type).toBe('square'); }); it('blocks mixed with compound blocks', () => { - const str = `block-beta + const str = `block columns 1 block1["Block 1"] @@ -291,7 +292,7 @@ describe('Block diagram', function () { }); it('Arrow blocks', () => { - const str = `block-beta + const str = `block columns 3 block1["Block 1"] blockArrow<["   "]>(right) @@ -315,7 +316,7 @@ describe('Block diagram', function () { expect(blockArrow.directions).toContain('right'); }); it('Arrow blocks with multiple points', () => { - const str = `block-beta + const str = `block columns 1 A blockArrow<["   "]>(up, down) @@ -338,7 +339,7 @@ describe('Block diagram', function () { expect(blockArrow.directions).not.toContain('right'); }); it('blocks with different widths', () => { - const str = `block-beta + const str = `block columns 3 one["One Slot"] two["Two slots"]:2 @@ -353,7 +354,7 @@ describe('Block diagram', function () { expect(two.widthInColumns).toBe(2); }); it('empty blocks', () => { - const str = `block-beta + const str = `block columns 3 space middle["In the middle"] @@ -372,7 +373,7 @@ describe('Block diagram', function () { expect(middle.label).toBe('In the middle'); }); it('classDef statements applied to a block', () => { - const str = `block-beta + const str = `block classDef black color:#ffffff, fill:#000000; mc["Memcache"] @@ -390,7 +391,7 @@ describe('Block diagram', function () { expect(black.styles[0]).toEqual('color:#ffffff'); }); it('style statements applied to a block', () => { - const str = `block-beta + const str = `block columns 1 B["A wide one in the middle"] style B fill:#f9F,stroke:#333,stroke-width:4px @@ -402,13 +403,32 @@ columns 1 const B = blocks[0]; expect(B.styles).toContain('fill:#f9F'); }); + it('should log a warning when block width exceeds column width', () => { + const str = `block-beta + columns 1 + A:1 + B:2 + C:3 + D:4 + E:3 + F:2 + G:1`; + + const logWarnSpy = vi.spyOn(log, 'warn').mockImplementation(() => undefined); + + block.parse(str); + + expect(logWarnSpy).toHaveBeenCalledWith('Block B width 2 exceeds configured column width 1'); + + logWarnSpy.mockRestore(); + }); }); describe('prototype properties', function () { function validateProperty(prop: string) { - expect(() => block.parse(`block-beta\n${prop}`)).not.toThrow(); + expect(() => block.parse(`block\n${prop}`)).not.toThrow(); expect(() => - block.parse(`block-beta\nA; classDef ${prop} color:#ffffff,fill:#000000; class A ${prop}`) + block.parse(`block\nA; classDef ${prop} color:#ffffff,fill:#000000; class A ${prop}`) ).not.toThrow(); } diff --git a/packages/mermaid/src/diagrams/class/classDiagram.spec.ts b/packages/mermaid/src/diagrams/class/classDiagram.spec.ts index 7c88f2e41..aa5e514e0 100644 --- a/packages/mermaid/src/diagrams/class/classDiagram.spec.ts +++ b/packages/mermaid/src/diagrams/class/classDiagram.spec.ts @@ -1070,6 +1070,14 @@ describe('given a class diagram with members and methods ', function () { parser.parse(str); }); + it('should handle an empty class body with {}', function () { + const str = 'classDiagram\nclass EmptyClass {}'; + parser.parse(str); + const actual = parser.yy.getClass('EmptyClass'); + expect(actual.label).toBe('EmptyClass'); + expect(actual.members.length).toBe(0); + expect(actual.methods.length).toBe(0); + }); }); }); diff --git a/packages/mermaid/src/diagrams/class/parser/class.spec.js b/packages/mermaid/src/diagrams/class/parser/class.spec.js index fe0077a29..7d4922561 100644 --- a/packages/mermaid/src/diagrams/class/parser/class.spec.js +++ b/packages/mermaid/src/diagrams/class/parser/class.spec.js @@ -15,4 +15,12 @@ describe('class diagram', function () { expect(() => parser.parse(`classDiagram\nnamespace ${prop} {\n\tclass A\n}`)).not.toThrow(); }); }); + + describe('backtick escaping', function () { + it('should handle backtick-quoted namespace names', function () { + expect(() => + parser.parse(`classDiagram\nnamespace \`A::B\` {\n\tclass \`IPC::Sender\`\n}`) + ).not.toThrow(); + }); + }); }); diff --git a/packages/mermaid/src/diagrams/class/parser/classDiagram.jison b/packages/mermaid/src/diagrams/class/parser/classDiagram.jison index 83d9bd48e..9a1f991a7 100644 --- a/packages/mermaid/src/diagrams/class/parser/classDiagram.jison +++ b/packages/mermaid/src/diagrams/class/parser/classDiagram.jison @@ -242,6 +242,7 @@ classLabel namespaceName : alphaNumToken { $$=$1; } + | classLiteralName { $$=$1; } | alphaNumToken DOT namespaceName { $$=$1+'.'+$3; } | alphaNumToken namespaceName { $$=$1+$2; } ; @@ -292,6 +293,7 @@ classStatement : classIdentifier | classIdentifier STYLE_SEPARATOR alphaNumToken {yy.setCssClass($1, $3);} | classIdentifier STRUCT_START members STRUCT_STOP {yy.addMembers($1,$3);} + | classIdentifier STRUCT_START STRUCT_STOP {} | classIdentifier STYLE_SEPARATOR alphaNumToken STRUCT_START members STRUCT_STOP {yy.setCssClass($1, $3);yy.addMembers($1,$5);} ; @@ -300,8 +302,15 @@ classIdentifier | CLASS className classLabel {$$=$2; yy.addClass($2);yy.setClassLabel($2, $3);} ; + +emptyBody + : + | SPACE emptyBody + | NEWLINE emptyBody + ; + annotationStatement - :ANNOTATION_START alphaNumToken ANNOTATION_END className { yy.addAnnotation($4,$2); } + : ANNOTATION_START alphaNumToken ANNOTATION_END className { yy.addAnnotation($4,$2); } ; members diff --git a/packages/mermaid/src/diagrams/common/common.ts b/packages/mermaid/src/diagrams/common/common.ts index 00c9b8313..045a729f7 100644 --- a/packages/mermaid/src/diagrams/common/common.ts +++ b/packages/mermaid/src/diagrams/common/common.ts @@ -33,13 +33,13 @@ function setupDompurifyHooks() { const TEMPORARY_ATTRIBUTE = 'data-temp-href-target'; DOMPurify.addHook('beforeSanitizeAttributes', (node) => { - if (node instanceof Element && node.tagName === 'A' && node.hasAttribute('target')) { + if (node.tagName === 'A' && node.hasAttribute('target')) { node.setAttribute(TEMPORARY_ATTRIBUTE, node.getAttribute('target') ?? ''); } }); DOMPurify.addHook('afterSanitizeAttributes', (node) => { - if (node instanceof Element && node.tagName === 'A' && node.hasAttribute(TEMPORARY_ATTRIBUTE)) { + if (node.tagName === 'A' && node.hasAttribute(TEMPORARY_ATTRIBUTE)) { node.setAttribute('target', node.getAttribute(TEMPORARY_ATTRIBUTE) ?? ''); node.removeAttribute(TEMPORARY_ATTRIBUTE); if (node.getAttribute('target') === '_blank') { @@ -311,9 +311,8 @@ export const hasKatex = (text: string): boolean => (text.match(katexRegex)?.leng * @returns Object containing \{width, height\} */ export const calculateMathMLDimensions = async (text: string, config: MermaidConfig) => { - text = await renderKatex(text, config); const divElem = document.createElement('div'); - divElem.innerHTML = text; + divElem.innerHTML = await renderKatexSanitized(text, config); divElem.id = 'katex-temp'; divElem.style.visibility = 'hidden'; divElem.style.position = 'absolute'; @@ -325,14 +324,7 @@ export const calculateMathMLDimensions = async (text: string, config: MermaidCon return dim; }; -/** - * Attempts to render and return the KaTeX portion of a string with MathML - * - * @param text - The text to test - * @param config - Configuration for Mermaid - * @returns String containing MathML if KaTeX is supported, or an error message if it is not and stylesheets aren't present - */ -export const renderKatex = async (text: string, config: MermaidConfig): Promise => { +const renderKatexUnsanitized = async (text: string, config: MermaidConfig): Promise => { if (!hasKatex(text)) { return text; } @@ -373,6 +365,20 @@ export const renderKatex = async (text: string, config: MermaidConfig): Promise< ); }; +/** + * Attempts to render and return the KaTeX portion of a string with MathML + * + * @param text - The text to test + * @param config - Configuration for Mermaid + * @returns String containing MathML if KaTeX is supported, or an error message if it is not and stylesheets aren't present + */ +export const renderKatexSanitized = async ( + text: string, + config: MermaidConfig +): Promise => { + return sanitizeText(await renderKatexUnsanitized(text, config), config); +}; + export default { getRows, sanitizeText, diff --git a/packages/mermaid/src/diagrams/flowchart/elk/detector.ts b/packages/mermaid/src/diagrams/flowchart/elk/detector.ts index 6688ffd8c..f0b2ac8ff 100644 --- a/packages/mermaid/src/diagrams/flowchart/elk/detector.ts +++ b/packages/mermaid/src/diagrams/flowchart/elk/detector.ts @@ -11,7 +11,7 @@ const detector: DiagramDetector = (txt, config = {}): boolean => { // If diagram explicitly states flowchart-elk /^\s*flowchart-elk/.test(txt) || // If a flowchart/graph diagram has their default renderer set to elk - (/^\s*flowchart|graph/.test(txt) && config?.flowchart?.defaultRenderer === 'elk') + (/^\s*(flowchart|graph)/.test(txt) && config?.flowchart?.defaultRenderer === 'elk') ) { config.layout = 'elk'; return true; diff --git a/packages/mermaid/src/diagrams/flowchart/flowDb.spec.ts b/packages/mermaid/src/diagrams/flowchart/flowDb.spec.ts index 8d12de00b..3e4034e3d 100644 --- a/packages/mermaid/src/diagrams/flowchart/flowDb.spec.ts +++ b/packages/mermaid/src/diagrams/flowchart/flowDb.spec.ts @@ -125,4 +125,60 @@ describe('flow db getData', () => { const { edges } = flowDb.getData(); expect(edges[0].curve).toBe('basis'); }); + + it('should support modifying interpolate using edge id syntax', () => { + flowDb.addVertex('A', { text: 'A', type: 'text' }, undefined, [], [], '', {}, undefined); + flowDb.addVertex('B', { text: 'B', type: 'text' }, undefined, [], [], '', {}, undefined); + flowDb.addVertex('C', { text: 'C', type: 'text' }, undefined, [], [], '', {}, undefined); + flowDb.addVertex('D', { text: 'D', type: 'text' }, undefined, [], [], '', {}, undefined); + flowDb.addLink(['A'], ['B'], {}); + flowDb.addLink(['A'], ['C'], { id: 'e2' }); + flowDb.addLink(['B'], ['D'], { id: 'e3' }); + flowDb.addLink(['C'], ['D'], {}); + flowDb.updateLinkInterpolate(['default'], 'stepBefore'); + flowDb.updateLinkInterpolate([0], 'basis'); + flowDb.addVertex( + 'e2', + { text: 'Shouldnt be used', type: 'text' }, + undefined, + [], + [], + '', + {}, + ' curve: monotoneX ' + ); + flowDb.addVertex( + 'e3', + { text: 'Shouldnt be used', type: 'text' }, + undefined, + [], + [], + '', + {}, + ' curve: catmullRom ' + ); + + const { edges } = flowDb.getData(); + expect(edges[0].curve).toBe('basis'); + expect(edges[1].curve).toBe('monotoneX'); + expect(edges[2].curve).toBe('catmullRom'); + expect(edges[3].curve).toBe('stepBefore'); + }); +}); + +describe('flow db direction', () => { + let flowDb: FlowDB; + beforeEach(() => { + flowDb = new FlowDB(); + }); + + it('should set direction to TB when TD is set', () => { + flowDb.setDirection('TD'); + expect(flowDb.getDirection()).toBe('TB'); + }); + + it('should correctly set direction irrespective of leading spaces', () => { + flowDb.setDirection(' TD'); + expect(flowDb.getDirection()).toBe('TB'); + }); }); diff --git a/packages/mermaid/src/diagrams/flowchart/flowDb.ts b/packages/mermaid/src/diagrams/flowchart/flowDb.ts index 65f8c4a05..632633730 100644 --- a/packages/mermaid/src/diagrams/flowchart/flowDb.ts +++ b/packages/mermaid/src/diagrams/flowchart/flowDb.ts @@ -139,6 +139,9 @@ export class FlowDB implements DiagramDB { if (edgeDoc?.animation !== undefined) { edge.animation = edgeDoc.animation; } + if (edgeDoc?.curve !== undefined) { + edge.interpolate = edgeDoc.curve; + } return; } @@ -403,7 +406,8 @@ You have to call mermaid.initialize.` * */ public setDirection(dir: string) { - this.direction = dir; + this.direction = dir.trim(); + if (/.* { expect(edges[1].interpolate).toBe('cardinal'); }); + it('should handle edge curve properties using edge ID', function () { + const res = flow.parser.parse( + 'graph TD\n' + + 'A e1@-->B\n' + + 'A uniqueName@-->C\n' + + 'e1@{curve: basis}\n' + + 'uniqueName@{curve: cardinal}' + ); + + const vert = flow.parser.yy.getVertices(); + const edges = flow.parser.yy.getEdges(); + + expect(edges[0].interpolate).toBe('basis'); + expect(edges[1].interpolate).toBe('cardinal'); + }); + + it('should handle edge curve properties using edge ID but without overriding default', function () { + const res = flow.parser.parse( + 'graph TD\n' + + 'A e1@-->B\n' + + 'A-->C\n' + + 'linkStyle default interpolate linear\n' + + 'e1@{curve: stepAfter}' + ); + + const vert = flow.parser.yy.getVertices(); + const edges = flow.parser.yy.getEdges(); + + expect(edges[0].interpolate).toBe('stepAfter'); + expect(edges.defaultInterpolate).toBe('linear'); + }); + + it('should handle edge curve properties using edge ID mixed with line interpolation', function () { + const res = flow.parser.parse( + 'graph TD\n' + + 'A e1@-->B-->D\n' + + 'A-->C e4@-->D-->E\n' + + 'linkStyle default interpolate linear\n' + + 'linkStyle 1 interpolate basis\n' + + 'e1@{curve: monotoneX}\n' + + 'e4@{curve: stepBefore}' + ); + + const vert = flow.parser.yy.getVertices(); + const edges = flow.parser.yy.getEdges(); + + expect(edges[0].interpolate).toBe('monotoneX'); + expect(edges[1].interpolate).toBe('basis'); + expect(edges.defaultInterpolate).toBe('linear'); + expect(edges[3].interpolate).toBe('stepBefore'); + expect(edges.defaultInterpolate).toBe('linear'); + }); + it('should handle line interpolation multi-numbered definitions', function () { const res = flow.parser.parse( 'graph TD\n' + 'A-->B\n' + 'A-->C\n' + 'linkStyle 0,1 interpolate basis' diff --git a/packages/mermaid/src/diagrams/gantt/ganttDb.js b/packages/mermaid/src/diagrams/gantt/ganttDb.js index 3ae55fb25..b2b5b0566 100644 --- a/packages/mermaid/src/diagrams/gantt/ganttDb.js +++ b/packages/mermaid/src/diagrams/gantt/ganttDb.js @@ -167,7 +167,10 @@ export const getTasks = function () { }; export const isInvalidDate = function (date, dateFormat, excludes, includes) { - if (includes.includes(date.format(dateFormat.trim()))) { + const formattedDate = date.format(dateFormat.trim()); + const dateOnly = date.format('YYYY-MM-DD'); + + if (includes.includes(formattedDate) || includes.includes(dateOnly)) { return false; } if ( @@ -180,7 +183,7 @@ export const isInvalidDate = function (date, dateFormat, excludes, includes) { if (excludes.includes(date.format('dddd').toLowerCase())) { return true; } - return excludes.includes(date.format(dateFormat.trim())); + return excludes.includes(formattedDate) || excludes.includes(dateOnly); }; export const setWeekday = function (txt) { diff --git a/packages/mermaid/src/diagrams/gantt/ganttRenderer.js b/packages/mermaid/src/diagrams/gantt/ganttRenderer.js index f5c8c2e38..9f899a40f 100644 --- a/packages/mermaid/src/diagrams/gantt/ganttRenderer.js +++ b/packages/mermaid/src/diagrams/gantt/ganttRenderer.js @@ -581,17 +581,11 @@ export const draw = function (text, id, version, diagObj) { rectangles .append('rect') - .attr('id', function (d) { - return 'exclude-' + d.start.format('YYYY-MM-DD'); - }) - .attr('x', function (d) { - return timeScale(d.start) + theSidePad; - }) + .attr('id', (d) => 'exclude-' + d.start.format('YYYY-MM-DD')) + .attr('x', (d) => timeScale(d.start.startOf('day')) + theSidePad) .attr('y', conf.gridLineStartPadding) - .attr('width', function (d) { - const renderEnd = d.end.add(1, 'day'); - return timeScale(renderEnd) - timeScale(d.start); - }) + .attr('width', (d) => timeScale(d.end.endOf('day')) - timeScale(d.start.startOf('day'))) + .attr('height', h - theTopPad - conf.gridLineStartPadding) .attr('transform-origin', function (d, i) { return ( @@ -615,9 +609,20 @@ export const draw = function (text, id, version, diagObj) { * @param h */ function makeGrid(theSidePad, theTopPad, w, h) { + const dateFormat = diagObj.db.getDateFormat(); + const userAxisFormat = diagObj.db.getAxisFormat(); + let axisFormat; + if (userAxisFormat) { + axisFormat = userAxisFormat; + } else if (dateFormat === 'D') { + axisFormat = '%d'; + } else { + axisFormat = conf.axisFormat ?? '%Y-%m-%d'; + } + let bottomXAxis = axisBottom(timeScale) .tickSize(-h + theTopPad + conf.gridLineStartPadding) - .tickFormat(timeFormat(diagObj.db.getAxisFormat() || conf.axisFormat || '%Y-%m-%d')); + .tickFormat(timeFormat(axisFormat)); const reTickInterval = /^([1-9]\d*)(millisecond|second|minute|hour|day|week|month)$/; const resultTickInterval = reTickInterval.exec( @@ -669,7 +674,7 @@ export const draw = function (text, id, version, diagObj) { if (diagObj.db.topAxisEnabled() || conf.topAxis) { let topXAxis = axisTop(timeScale) .tickSize(-h + theTopPad + conf.gridLineStartPadding) - .tickFormat(timeFormat(diagObj.db.getAxisFormat() || conf.axisFormat || '%Y-%m-%d')); + .tickFormat(timeFormat(axisFormat)); if (resultTickInterval !== null) { const every = resultTickInterval[1]; diff --git a/packages/mermaid/src/diagrams/mindmap/mindmapDb.getData.test.ts b/packages/mermaid/src/diagrams/mindmap/mindmapDb.getData.test.ts new file mode 100644 index 000000000..7c10c0104 --- /dev/null +++ b/packages/mermaid/src/diagrams/mindmap/mindmapDb.getData.test.ts @@ -0,0 +1,297 @@ +import { describe, it, expect, beforeEach, vi } from 'vitest'; +import { MindmapDB } from './mindmapDb.js'; +import type { MindmapLayoutNode, MindmapLayoutEdge } from './mindmapDb.js'; +import type { Edge } from '../../rendering-util/types.js'; + +// Mock the getConfig function +vi.mock('../../diagram-api/diagramAPI.js', () => ({ + getConfig: vi.fn(() => ({ + mindmap: { + layoutAlgorithm: 'cose-bilkent', + padding: 10, + maxNodeWidth: 200, + useMaxWidth: true, + }, + })), +})); + +describe('MindmapDb getData function', () => { + let db: MindmapDB; + + beforeEach(() => { + db = new MindmapDB(); + // Clear the database before each test + db.clear(); + }); + + describe('getData', () => { + it('should return empty data when no mindmap is set', () => { + const result = db.getData(); + + expect(result.nodes).toEqual([]); + expect(result.edges).toEqual([]); + expect(result.config).toBeDefined(); + expect(result.rootNode).toBeUndefined(); + }); + + it('should return structured data for simple mindmap', () => { + // Create a simple mindmap structure + db.addNode(0, 'root', 'Root Node', 0); + db.addNode(1, 'child1', 'Child 1', 0); + db.addNode(1, 'child2', 'Child 2', 0); + + const result = db.getData(); + + expect(result.nodes).toHaveLength(3); + expect(result.edges).toHaveLength(2); + expect(result.config).toBeDefined(); + expect(result.rootNode).toBeDefined(); + + // Check root node + const rootNode = (result.nodes as MindmapLayoutNode[]).find((n) => n.id === '0'); + expect(rootNode).toBeDefined(); + expect(rootNode?.label).toBe('Root Node'); + expect(rootNode?.level).toBe(0); + + // Check child nodes + const child1 = (result.nodes as MindmapLayoutNode[]).find((n) => n.id === '1'); + expect(child1).toBeDefined(); + expect(child1?.label).toBe('Child 1'); + expect(child1?.level).toBe(1); + + // Check edges + expect(result.edges).toContainEqual( + expect.objectContaining({ + start: '0', + end: '1', + depth: 0, + }) + ); + }); + + it('should return structured data for hierarchical mindmap', () => { + // Create a hierarchical mindmap structure + db.addNode(0, 'root', 'Root Node', 0); + db.addNode(1, 'child1', 'Child 1', 0); + db.addNode(2, 'grandchild1', 'Grandchild 1', 0); + db.addNode(2, 'grandchild2', 'Grandchild 2', 0); + db.addNode(1, 'child2', 'Child 2', 0); + + const result = db.getData(); + + expect(result.nodes).toHaveLength(5); + expect(result.edges).toHaveLength(4); + + // Check that all levels are represented + const levels = result.nodes.map((n) => (n as MindmapLayoutNode).level); + expect(levels).toContain(0); // root + expect(levels).toContain(1); // children + expect(levels).toContain(2); // grandchildren + + // Check edge relationships + const edgeRelations = result.edges.map( + (e) => `${(e as MindmapLayoutEdge).start}->${(e as MindmapLayoutEdge).end}` + ); + expect(edgeRelations).toContain('0->1'); // root to child1 + expect(edgeRelations).toContain('1->2'); // child1 to grandchild1 + expect(edgeRelations).toContain('1->3'); // child1 to grandchild2 + expect(edgeRelations).toContain('0->4'); // root to child2 + }); + + it('should preserve node properties in processed data', () => { + // Add a node with specific properties + db.addNode(0, 'root', 'Root Node', 2); // type 2 = rectangle + + // Set additional properties + const mindmap = db.getMindmap(); + if (mindmap) { + mindmap.width = 150; + mindmap.height = 75; + mindmap.padding = 15; + mindmap.section = 1; + mindmap.class = 'custom-class'; + mindmap.icon = 'star'; + } + + const result = db.getData(); + + expect(result.nodes).toHaveLength(1); + const node = result.nodes[0] as MindmapLayoutNode; + + expect(node.type).toBe(2); + expect(node.width).toBe(150); + expect(node.height).toBe(75); + expect(node.padding).toBe(15); + expect(node.section).toBeUndefined(); // Root node has undefined section + expect(node.cssClasses).toBe('mindmap-node section-root section--1 custom-class'); + expect(node.icon).toBe('star'); + }); + + it('should generate unique edge IDs', () => { + db.addNode(0, 'root', 'Root Node', 0); + db.addNode(1, 'child1', 'Child 1', 0); + db.addNode(1, 'child2', 'Child 2', 0); + db.addNode(1, 'child3', 'Child 3', 0); + + const result = db.getData(); + + const edgeIds = result.edges.map((e: Edge) => e.id); + const uniqueIds = new Set(edgeIds); + + expect(edgeIds).toHaveLength(3); + expect(uniqueIds.size).toBe(3); // All IDs should be unique + }); + + it('should handle nodes with missing optional properties', () => { + db.addNode(0, 'root', 'Root Node', 0); + + const result = db.getData(); + const node = result.nodes[0] as MindmapLayoutNode; + + // Should handle undefined/missing properties gracefully + expect(node.section).toBeUndefined(); // Root node has undefined section + expect(node.cssClasses).toBe('mindmap-node section-root section--1'); // Root node gets special classes + expect(node.icon).toBeUndefined(); + expect(node.x).toBeUndefined(); + expect(node.y).toBeUndefined(); + }); + + it('should assign correct section classes based on sibling position', () => { + // Create the example mindmap structure: + // A + // a0 + // aa0 + // a1 + // aaa + // a2 + db.addNode(0, 'A', 'A', 0); // Root + db.addNode(1, 'a0', 'a0', 0); // First child of root + db.addNode(2, 'aa0', 'aa0', 0); // Child of a0 + db.addNode(1, 'a1', 'a1', 0); // Second child of root + db.addNode(2, 'aaa', 'aaa', 0); // Child of a1 + db.addNode(1, 'a2', 'a2', 0); // Third child of root + + const result = db.getData(); + + // Find nodes by their labels + const nodeA = result.nodes.find((n) => n.label === 'A') as MindmapLayoutNode; + const nodeA0 = result.nodes.find((n) => n.label === 'a0') as MindmapLayoutNode; + const nodeAa0 = result.nodes.find((n) => n.label === 'aa0') as MindmapLayoutNode; + const nodeA1 = result.nodes.find((n) => n.label === 'a1') as MindmapLayoutNode; + const nodeAaa = result.nodes.find((n) => n.label === 'aaa') as MindmapLayoutNode; + const nodeA2 = result.nodes.find((n) => n.label === 'a2') as MindmapLayoutNode; + + // Check section assignments + expect(nodeA.section).toBeUndefined(); // Root has undefined section + expect(nodeA0.section).toBe(0); // First child of root + expect(nodeAa0.section).toBe(0); // Inherits from parent a0 + expect(nodeA1.section).toBe(1); // Second child of root + expect(nodeAaa.section).toBe(1); // Inherits from parent a1 + expect(nodeA2.section).toBe(2); // Third child of root + + // Check CSS classes + expect(nodeA.cssClasses).toBe('mindmap-node section-root section--1'); + expect(nodeA0.cssClasses).toBe('mindmap-node section-0'); + expect(nodeAa0.cssClasses).toBe('mindmap-node section-0'); + expect(nodeA1.cssClasses).toBe('mindmap-node section-1'); + expect(nodeAaa.cssClasses).toBe('mindmap-node section-1'); + expect(nodeA2.cssClasses).toBe('mindmap-node section-2'); + }); + + it('should preserve custom classes while adding section classes', () => { + db.addNode(0, 'root', 'Root Node', 0); + db.addNode(1, 'child', 'Child Node', 0); + + // Add custom classes to nodes + const mindmap = db.getMindmap(); + if (mindmap) { + mindmap.class = 'custom-root-class'; + if (mindmap.children?.[0]) { + mindmap.children[0].class = 'custom-child-class'; + } + } + + const result = db.getData(); + const rootNode = result.nodes.find((n) => n.label === 'Root Node') as MindmapLayoutNode; + const childNode = result.nodes.find((n) => n.label === 'Child Node') as MindmapLayoutNode; + + // Should include both section classes and custom classes + expect(rootNode.cssClasses).toBe('mindmap-node section-root section--1 custom-root-class'); + expect(childNode.cssClasses).toBe('mindmap-node section-0 custom-child-class'); + }); + + it('should not create any fake root nodes', () => { + // Create a simple mindmap + db.addNode(0, 'A', 'A', 0); + db.addNode(1, 'a0', 'a0', 0); + db.addNode(1, 'a1', 'a1', 0); + + const result = db.getData(); + + // Check that we only have the expected nodes + expect(result.nodes).toHaveLength(3); + expect(result.nodes.map((n) => n.label)).toEqual(['A', 'a0', 'a1']); + + // Check that there's no node with label "mindmap" or any other fake root + const mindmapNode = result.nodes.find((n) => n.label === 'mindmap'); + expect(mindmapNode).toBeUndefined(); + + // Verify the root node has the correct classes + const rootNode = result.nodes.find((n) => n.label === 'A') as MindmapLayoutNode; + expect(rootNode.cssClasses).toBe('mindmap-node section-root section--1'); + expect(rootNode.level).toBe(0); + }); + + it('should assign correct section classes to edges', () => { + // Create the example mindmap structure: + // A + // a0 + // aa0 + // a1 + // aaa + // a2 + db.addNode(0, 'A', 'A', 0); // Root + db.addNode(1, 'a0', 'a0', 0); // First child of root + db.addNode(2, 'aa0', 'aa0', 0); // Child of a0 + db.addNode(1, 'a1', 'a1', 0); // Second child of root + db.addNode(2, 'aaa', 'aaa', 0); // Child of a1 + db.addNode(1, 'a2', 'a2', 0); // Third child of root + + const result = db.getData(); + + // Should have 5 edges: A->a0, a0->aa0, A->a1, a1->aaa, A->a2 + expect(result.edges).toHaveLength(5); + + // Find edges by their start and end nodes + const edgeA_a0 = result.edges.find( + (e) => e.start === '0' && e.end === '1' + ) as MindmapLayoutEdge; + const edgeA0_aa0 = result.edges.find( + (e) => e.start === '1' && e.end === '2' + ) as MindmapLayoutEdge; + const edgeA_a1 = result.edges.find( + (e) => e.start === '0' && e.end === '3' + ) as MindmapLayoutEdge; + const edgeA1_aaa = result.edges.find( + (e) => e.start === '3' && e.end === '4' + ) as MindmapLayoutEdge; + const edgeA_a2 = result.edges.find( + (e) => e.start === '0' && e.end === '5' + ) as MindmapLayoutEdge; + + // Check edge classes + expect(edgeA_a0.classes).toBe('edge section-edge-0 edge-depth-1'); // A->a0: section-0, depth-1 + expect(edgeA0_aa0.classes).toBe('edge section-edge-0 edge-depth-2'); // a0->aa0: section-0, depth-2 + expect(edgeA_a1.classes).toBe('edge section-edge-1 edge-depth-1'); // A->a1: section-1, depth-1 + expect(edgeA1_aaa.classes).toBe('edge section-edge-1 edge-depth-2'); // a1->aaa: section-1, depth-2 + expect(edgeA_a2.classes).toBe('edge section-edge-2 edge-depth-1'); // A->a2: section-2, depth-1 + + // Check section assignments match the child nodes + expect(edgeA_a0.section).toBe(0); + expect(edgeA0_aa0.section).toBe(0); + expect(edgeA_a1.section).toBe(1); + expect(edgeA1_aaa.section).toBe(1); + expect(edgeA_a2.section).toBe(2); + }); + }); +}); diff --git a/packages/mermaid/src/diagrams/mindmap/mindmapDb.ts b/packages/mermaid/src/diagrams/mindmap/mindmapDb.ts index 703ba8434..aebdba71b 100644 --- a/packages/mermaid/src/diagrams/mindmap/mindmapDb.ts +++ b/packages/mermaid/src/diagrams/mindmap/mindmapDb.ts @@ -1,9 +1,26 @@ import { getConfig } from '../../diagram-api/diagramAPI.js'; +import { v4 } from 'uuid'; import type { D3Element } from '../../types.js'; import { sanitizeText } from '../../diagrams/common/common.js'; import { log } from '../../logger.js'; import type { MindmapNode } from './mindmapTypes.js'; import defaultConfig from '../../defaultConfig.js'; +import type { LayoutData, Node, Edge } from '../../rendering-util/types.js'; +import { getUserDefinedConfig } from '../../config.js'; + +// Extend Node type for mindmap-specific properties +export type MindmapLayoutNode = Node & { + level: number; + nodeId: string; + type: number; + section?: number; +}; + +// Extend Edge type for mindmap-specific properties +export type MindmapLayoutEdge = Edge & { + depth: number; + section?: number; +}; const nodeType = { DEFAULT: 0, @@ -27,7 +44,6 @@ export class MindmapDB { this.nodeType = nodeType; this.clear(); this.getType = this.getType.bind(this); - this.getMindmap = this.getMindmap.bind(this); this.getElementById = this.getElementById.bind(this); this.getParent = this.getParent.bind(this); this.getMindmap = this.getMindmap.bind(this); @@ -156,6 +172,223 @@ export class MindmapDB { } } + /** + * Assign section numbers to nodes based on their position relative to root + * @param node - The mindmap node to process + * @param sectionNumber - The section number to assign (undefined for root) + */ + public assignSections(node: MindmapNode, sectionNumber?: number): void { + // For root node, section should be undefined (not -1) + if (node.level === 0) { + node.section = undefined; + } else { + // For non-root nodes, assign the section number + node.section = sectionNumber; + } + // For root node's children, assign section numbers based on their index + // For other nodes, inherit parent's section number + if (node.children) { + for (const [index, child] of node.children.entries()) { + const childSectionNumber = node.level === 0 ? index : sectionNumber; + this.assignSections(child, childSectionNumber); + } + } + } + + /** + * Convert mindmap tree structure to flat array of nodes + * @param node - The mindmap node to process + * @param processedNodes - Array to collect processed nodes + */ + public flattenNodes(node: MindmapNode, processedNodes: MindmapLayoutNode[]): void { + // Build CSS classes for the node + const cssClasses = ['mindmap-node']; + + // Add section-specific classes + if (node.level === 0) { + // Root node gets special classes + cssClasses.push('section-root', 'section--1'); + } else if (node.section !== undefined) { + // Child nodes get section class based on their section number + cssClasses.push(`section-${node.section}`); + } + + // Add any custom classes from the node + if (node.class) { + cssClasses.push(node.class); + } + + const classes = cssClasses.join(' '); + + // Map mindmap node type to valid shape name + const getShapeFromType = (type: number) => { + switch (type) { + case nodeType.CIRCLE: + return 'mindmapCircle'; + case nodeType.RECT: + return 'rect'; + case nodeType.ROUNDED_RECT: + return 'rounded'; + case nodeType.CLOUD: + return 'cloud'; + case nodeType.BANG: + return 'bang'; + case nodeType.HEXAGON: + return 'hexagon'; + case nodeType.DEFAULT: + return 'defaultMindmapNode'; + case nodeType.NO_BORDER: + default: + return 'rect'; + } + }; + + const processedNode: MindmapLayoutNode = { + id: node.id.toString(), + domId: 'node_' + node.id.toString(), + label: node.descr, + isGroup: false, + shape: getShapeFromType(node.type), + width: node.width, + height: node.height ?? 0, + padding: node.padding, + cssClasses: classes, + cssStyles: [], + look: 'default', + icon: node.icon, + x: node.x, + y: node.y, + // Mindmap-specific properties + level: node.level, + nodeId: node.nodeId, + type: node.type, + section: node.section, + }; + + processedNodes.push(processedNode); + + // Recursively process children + if (node.children) { + for (const child of node.children) { + this.flattenNodes(child, processedNodes); + } + } + } + + /** + * Generate edges from parent-child relationships in mindmap tree + * @param node - The mindmap node to process + * @param edges - Array to collect edges + */ + public generateEdges(node: MindmapNode, edges: MindmapLayoutEdge[]): void { + if (!node.children) { + return; + } + for (const child of node.children) { + // Build CSS classes for the edge + let edgeClasses = 'edge'; + + // Add section-specific classes based on the child's section + if (child.section !== undefined) { + edgeClasses += ` section-edge-${child.section}`; + } + + // Add depth class based on the parent's level + 1 (depth of the edge) + const edgeDepth = node.level + 1; + edgeClasses += ` edge-depth-${edgeDepth}`; + + const edge: MindmapLayoutEdge = { + id: `edge_${node.id}_${child.id}`, + start: node.id.toString(), + end: child.id.toString(), + type: 'normal', + curve: 'basis', + thickness: 'normal', + look: 'default', + classes: edgeClasses, + // Store mindmap-specific data + depth: node.level, + section: child.section, + }; + + edges.push(edge); + + // Recursively process child edges + this.generateEdges(child, edges); + } + } + + /** + * Get structured data for layout algorithms + * Following the pattern established by ER diagrams + * @returns Structured data containing nodes, edges, and config + */ + public getData(): LayoutData { + const mindmapRoot = this.getMindmap(); + const config = getConfig(); + + const userDefinedConfig = getUserDefinedConfig(); + const hasUserDefinedLayout = userDefinedConfig.layout !== undefined; + + const finalConfig = config; + if (!hasUserDefinedLayout) { + finalConfig.layout = 'cose-bilkent'; + } + + if (!mindmapRoot) { + return { + nodes: [], + edges: [], + config: finalConfig, + }; + } + log.debug('getData: mindmapRoot', mindmapRoot, config); + + // Assign section numbers to all nodes based on their position relative to root + this.assignSections(mindmapRoot); + + // Convert tree structure to flat arrays + const processedNodes: MindmapLayoutNode[] = []; + const processedEdges: MindmapLayoutEdge[] = []; + + this.flattenNodes(mindmapRoot, processedNodes); + this.generateEdges(mindmapRoot, processedEdges); + + log.debug( + `getData: processed ${processedNodes.length} nodes and ${processedEdges.length} edges` + ); + + // Create shapes map for ELK compatibility + const shapes = new Map(); + for (const node of processedNodes) { + shapes.set(node.id, { + shape: node.shape, + width: node.width, + height: node.height, + padding: node.padding, + }); + } + + return { + nodes: processedNodes, + edges: processedEdges, + config: finalConfig, + // Store the root node for mindmap-specific layout algorithms + rootNode: mindmapRoot, + // Properties required by dagre layout algorithm + markers: ['point'], // Mindmaps don't use markers + direction: 'TB', // Top-to-bottom direction for mindmaps + nodeSpacing: 50, // Default spacing between nodes + rankSpacing: 50, // Default spacing between ranks + // Add shapes for ELK compatibility + shapes: Object.fromEntries(shapes), + // Additional properties that layout algorithms might expect + type: 'mindmap', + diagramId: 'mindmap-' + v4(), + }; + } + + // Expose logger to grammar public getLogger() { return log; } diff --git a/packages/mermaid/src/diagrams/mindmap/mindmapRenderer.ts b/packages/mermaid/src/diagrams/mindmap/mindmapRenderer.ts index ef9be0565..a962dc924 100644 --- a/packages/mermaid/src/diagrams/mindmap/mindmapRenderer.ts +++ b/packages/mermaid/src/diagrams/mindmap/mindmapRenderer.ts @@ -1,200 +1,83 @@ -import cytoscape from 'cytoscape'; -// @ts-expect-error No types available -import coseBilkent from 'cytoscape-cose-bilkent'; -import { select } from 'd3'; -import type { MermaidConfig } from '../../config.type.js'; -import { getConfig } from '../../diagram-api/diagramAPI.js'; import type { DrawDefinition } from '../../diagram-api/types.js'; import { log } from '../../logger.js'; -import type { D3Element } from '../../types.js'; -import { selectSvgElement } from '../../rendering-util/selectSvgElement.js'; -import { setupGraphViewbox } from '../../setupGraphViewbox.js'; -import type { FilledMindMapNode, MindmapNode } from './mindmapTypes.js'; -import { drawNode, positionNode } from './svgDraw.js'; +import { getDiagramElement } from '../../rendering-util/insertElementsForSize.js'; +import { getRegisteredLayoutAlgorithm, render } from '../../rendering-util/render.js'; +import { setupViewPortForSVG } from '../../rendering-util/setupViewPortForSVG.js'; +import type { LayoutData } from '../../rendering-util/types.js'; +import type { FilledMindMapNode } from './mindmapTypes.js'; import defaultConfig from '../../defaultConfig.js'; import type { MindmapDB } from './mindmapDb.js'; -// Inject the layout algorithm into cytoscape -cytoscape.use(coseBilkent); -async function drawNodes( - db: MindmapDB, - svg: D3Element, - mindmap: FilledMindMapNode, - section: number, - conf: MermaidConfig -) { - await drawNode(db, svg, mindmap, section, conf); - if (mindmap.children) { - await Promise.all( - mindmap.children.map((child, index) => - drawNodes(db, svg, child, section < 0 ? index : section, conf) - ) - ); - } -} - -declare module 'cytoscape' { - interface EdgeSingular { - _private: { - bodyBounds: unknown; - rscratch: { - startX: number; - startY: number; - midX: number; - midY: number; - endX: number; - endY: number; - }; - }; - } -} - -function drawEdges(edgesEl: D3Element, cy: cytoscape.Core) { - cy.edges().map((edge, id) => { - const data = edge.data(); - if (edge[0]._private.bodyBounds) { - const bounds = edge[0]._private.rscratch; - log.trace('Edge: ', id, data); - edgesEl - .insert('path') - .attr( - 'd', - `M ${bounds.startX},${bounds.startY} L ${bounds.midX},${bounds.midY} L${bounds.endX},${bounds.endY} ` - ) - .attr('class', 'edge section-edge-' + data.section + ' edge-depth-' + data.depth); +/** + * Update the layout data with actual node dimensions after drawing + */ +function _updateNodeDimensions(data4Layout: LayoutData, mindmapRoot: FilledMindMapNode) { + const updateNode = (node: FilledMindMapNode) => { + // Find the corresponding node in the layout data + const layoutNode = data4Layout.nodes.find((n) => n.id === node.id.toString()); + if (layoutNode) { + // Update with the actual dimensions calculated by drawNode + layoutNode.width = node.width; + layoutNode.height = node.height; + log.debug('Updated node dimensions:', node.id, 'width:', node.width, 'height:', node.height); } - }); -} -function addNodes(mindmap: MindmapNode, cy: cytoscape.Core, conf: MermaidConfig, level: number) { - cy.add({ - group: 'nodes', - data: { - id: mindmap.id.toString(), - labelText: mindmap.descr, - height: mindmap.height, - width: mindmap.width, - level: level, - nodeId: mindmap.id, - padding: mindmap.padding, - type: mindmap.type, - }, - position: { - x: mindmap.x!, - y: mindmap.y!, - }, - }); - if (mindmap.children) { - mindmap.children.forEach((child) => { - addNodes(child, cy, conf, level + 1); - cy.add({ - group: 'edges', - data: { - id: `${mindmap.id}_${child.id}`, - source: mindmap.id, - target: child.id, - depth: level, - section: child.section, - }, - }); - }); - } -} + // Recursively update children + node.children?.forEach(updateNode); + }; -function layoutMindmap(node: MindmapNode, conf: MermaidConfig): Promise { - return new Promise((resolve) => { - // Add temporary render element - const renderEl = select('body').append('div').attr('id', 'cy').attr('style', 'display:none'); - const cy = cytoscape({ - container: document.getElementById('cy'), // container to render in - style: [ - { - selector: 'edge', - style: { - 'curve-style': 'bezier', - }, - }, - ], - }); - // Remove element after layout - renderEl.remove(); - addNodes(node, cy, conf, 0); - - // Make cytoscape care about the dimensions of the nodes - cy.nodes().forEach(function (n) { - n.layoutDimensions = () => { - const data = n.data(); - return { w: data.width, h: data.height }; - }; - }); - - cy.layout({ - name: 'cose-bilkent', - // @ts-ignore Types for cose-bilkent are not correct? - quality: 'proof', - styleEnabled: false, - animate: false, - }).run(); - cy.ready((e) => { - log.info('Ready', e); - resolve(cy); - }); - }); -} - -function positionNodes(db: MindmapDB, cy: cytoscape.Core) { - cy.nodes().map((node, id) => { - const data = node.data(); - data.x = node.position().x; - data.y = node.position().y; - positionNode(db, data); - const el = db.getElementById(data.nodeId); - log.info('id:', id, 'Position: (', node.position().x, ', ', node.position().y, ')', data); - el.attr( - 'transform', - `translate(${node.position().x - data.width / 2}, ${node.position().y - data.height / 2})` - ); - el.attr('attr', `apa-${id})`); - }); + updateNode(mindmapRoot); } export const draw: DrawDefinition = async (text, id, _version, diagObj) => { log.debug('Rendering mindmap diagram\n' + text); + // Draw the nodes first to get their dimensions, then update the layout data const db = diagObj.db as MindmapDB; + + // The getData method provided in all supported diagrams is used to extract the data from the parsed structure + // into the Layout data format + const data4Layout = db.getData(); + + // Create the root SVG - the element is the div containing the SVG element + const svg = getDiagramElement(id, data4Layout.config.securityLevel); + + data4Layout.type = diagObj.type; + data4Layout.layoutAlgorithm = getRegisteredLayoutAlgorithm(data4Layout.config.layout, { + fallback: 'cose-bilkent', + }); + + data4Layout.diagramId = id; + const mm = db.getMindmap(); if (!mm) { return; } - const conf = getConfig(); - conf.htmlLabels = false; + data4Layout.nodes.forEach((node) => { + if (node.shape === 'rounded') { + node.radius = 15; + node.taper = 15; + node.stroke = 'none'; + node.width = 0; + node.padding = 15; + } else if (node.shape === 'circle') { + node.padding = 10; + } else if (node.shape === 'rect') { + node.width = 0; + node.padding = 10; + } + }); - const svg = selectSvgElement(id); + // Use the unified rendering system + await render(data4Layout, svg); - // Draw the graph and start with drawing the nodes without proper position - // this gives us the size of the nodes and we can set the positions later - - const edgesElem = svg.append('g'); - edgesElem.attr('class', 'mindmap-edges'); - const nodesElem = svg.append('g'); - nodesElem.attr('class', 'mindmap-nodes'); - await drawNodes(db, nodesElem, mm as FilledMindMapNode, -1, conf); - - // Next step is to layout the mindmap, giving each node a position - - const cy = await layoutMindmap(mm, conf); - - // After this we can draw, first the edges and the then nodes with the correct position - drawEdges(edgesElem, cy); - positionNodes(db, cy); - - // Setup the view box and size of the svg element - setupGraphViewbox( - undefined, + // Setup the view box and size of the svg element using config from data4Layout + setupViewPortForSVG( svg, - conf.mindmap?.padding ?? defaultConfig.mindmap.padding, - conf.mindmap?.useMaxWidth ?? defaultConfig.mindmap.useMaxWidth + data4Layout.config.mindmap?.padding ?? defaultConfig.mindmap.padding, + 'mindmapDiagram', + data4Layout.config.mindmap?.useMaxWidth ?? defaultConfig.mindmap.useMaxWidth ); }; diff --git a/packages/mermaid/src/diagrams/mindmap/styles.ts b/packages/mermaid/src/diagrams/mindmap/styles.ts index fffa6e4d9..8372bddf1 100644 --- a/packages/mermaid/src/diagrams/mindmap/styles.ts +++ b/packages/mermaid/src/diagrams/mindmap/styles.ts @@ -64,6 +64,12 @@ const getStyles: DiagramStylesProvider = (options) => .section-root text { fill: ${options.gitBranchLabel0}; } + .section-root span { + color: ${options.gitBranchLabel0}; + } + .section-2 span { + color: ${options.gitBranchLabel0}; + } .icon-container { height:100%; display: flex; diff --git a/packages/mermaid/src/diagrams/packet/db.ts b/packages/mermaid/src/diagrams/packet/db.ts index d7b550472..863bd79e1 100644 --- a/packages/mermaid/src/diagrams/packet/db.ts +++ b/packages/mermaid/src/diagrams/packet/db.ts @@ -1,6 +1,7 @@ import { getConfig as commonGetConfig } from '../../config.js'; import type { PacketDiagramConfig } from '../../config.type.js'; import DEFAULT_CONFIG from '../../defaultConfig.js'; +import type { DiagramDB } from '../../diagram-api/types.js'; import { cleanAndMerge } from '../../utils.js'; import { clear as commonClear, @@ -11,49 +12,42 @@ import { setAccTitle, setDiagramTitle, } from '../common/commonDb.js'; -import type { PacketDB, PacketData, PacketWord } from './types.js'; - -const defaultPacketData: PacketData = { - packet: [], -}; - -let data: PacketData = structuredClone(defaultPacketData); - +import type { PacketWord } from './types.js'; const DEFAULT_PACKET_CONFIG: Required = DEFAULT_CONFIG.packet; -const getConfig = (): Required => { - const config = cleanAndMerge({ - ...DEFAULT_PACKET_CONFIG, - ...commonGetConfig().packet, - }); - if (config.showBits) { - config.paddingY += 10; +export class PacketDB implements DiagramDB { + private packet: PacketWord[] = []; + + public getConfig() { + const config = cleanAndMerge({ + ...DEFAULT_PACKET_CONFIG, + ...commonGetConfig().packet, + }); + if (config.showBits) { + config.paddingY += 10; + } + return config; } - return config; -}; -const getPacket = (): PacketWord[] => data.packet; - -const pushWord = (word: PacketWord) => { - if (word.length > 0) { - data.packet.push(word); + public getPacket() { + return this.packet; } -}; -const clear = () => { - commonClear(); - data = structuredClone(defaultPacketData); -}; + public pushWord(word: PacketWord) { + if (word.length > 0) { + this.packet.push(word); + } + } -export const db: PacketDB = { - pushWord, - getPacket, - getConfig, - clear, - setAccTitle, - getAccTitle, - setDiagramTitle, - getDiagramTitle, - getAccDescription, - setAccDescription, -}; + public clear() { + commonClear(); + this.packet = []; + } + + public setAccTitle = setAccTitle; + public getAccTitle = getAccTitle; + public setDiagramTitle = setDiagramTitle; + public getDiagramTitle = getDiagramTitle; + public getAccDescription = getAccDescription; + public setAccDescription = setAccDescription; +} diff --git a/packages/mermaid/src/diagrams/packet/diagram.ts b/packages/mermaid/src/diagrams/packet/diagram.ts index a73a77c05..84a7bca8f 100644 --- a/packages/mermaid/src/diagrams/packet/diagram.ts +++ b/packages/mermaid/src/diagrams/packet/diagram.ts @@ -1,12 +1,14 @@ import type { DiagramDefinition } from '../../diagram-api/types.js'; -import { db } from './db.js'; +import { PacketDB } from './db.js'; import { parser } from './parser.js'; import { renderer } from './renderer.js'; import { styles } from './styles.js'; export const diagram: DiagramDefinition = { parser, - db, + get db() { + return new PacketDB(); + }, renderer, styles, }; diff --git a/packages/mermaid/src/diagrams/packet/packet.spec.ts b/packages/mermaid/src/diagrams/packet/packet.spec.ts index b03ffe4d1..fd7b3211a 100644 --- a/packages/mermaid/src/diagrams/packet/packet.spec.ts +++ b/packages/mermaid/src/diagrams/packet/packet.spec.ts @@ -1,24 +1,26 @@ import { it, describe, expect } from 'vitest'; -import { db } from './db.js'; +import { PacketDB } from './db.js'; import { parser } from './parser.js'; -const { clear, getPacket, getDiagramTitle, getAccTitle, getAccDescription } = db; - describe('packet diagrams', () => { + let db: PacketDB; beforeEach(() => { - clear(); + db = new PacketDB(); + if (parser.parser) { + parser.parser.yy = db; + } }); it('should handle a packet-beta definition', async () => { const str = `packet-beta`; await expect(parser.parse(str)).resolves.not.toThrow(); - expect(getPacket()).toMatchInlineSnapshot('[]'); + expect(db.getPacket()).toMatchInlineSnapshot('[]'); }); it('should handle a packet definition', async () => { const str = `packet`; await expect(parser.parse(str)).resolves.not.toThrow(); - expect(getPacket()).toMatchInlineSnapshot('[]'); + expect(db.getPacket()).toMatchInlineSnapshot('[]'); }); it('should handle diagram with data and title', async () => { @@ -29,10 +31,10 @@ describe('packet diagrams', () => { 0-10: "test" `; await expect(parser.parse(str)).resolves.not.toThrow(); - expect(getDiagramTitle()).toMatchInlineSnapshot('"Packet diagram"'); - expect(getAccTitle()).toMatchInlineSnapshot('"Packet accTitle"'); - expect(getAccDescription()).toMatchInlineSnapshot('"Packet accDescription"'); - expect(getPacket()).toMatchInlineSnapshot(` + expect(db.getDiagramTitle()).toMatchInlineSnapshot('"Packet diagram"'); + expect(db.getAccTitle()).toMatchInlineSnapshot('"Packet accTitle"'); + expect(db.getAccDescription()).toMatchInlineSnapshot('"Packet accDescription"'); + expect(db.getPacket()).toMatchInlineSnapshot(` [ [ { @@ -52,7 +54,7 @@ describe('packet diagrams', () => { 11: "single" `; await expect(parser.parse(str)).resolves.not.toThrow(); - expect(getPacket()).toMatchInlineSnapshot(` + expect(db.getPacket()).toMatchInlineSnapshot(` [ [ { @@ -78,7 +80,7 @@ describe('packet diagrams', () => { +16: "word" `; await expect(parser.parse(str)).resolves.not.toThrow(); - expect(getPacket()).toMatchInlineSnapshot(` + expect(db.getPacket()).toMatchInlineSnapshot(` [ [ { @@ -104,7 +106,7 @@ describe('packet diagrams', () => { +16: "word" `; await expect(parser.parse(str)).resolves.not.toThrow(); - expect(getPacket()).toMatchInlineSnapshot(` + expect(db.getPacket()).toMatchInlineSnapshot(` [ [ { @@ -130,7 +132,7 @@ describe('packet diagrams', () => { 11-90: "multiple" `; await expect(parser.parse(str)).resolves.not.toThrow(); - expect(getPacket()).toMatchInlineSnapshot(` + expect(db.getPacket()).toMatchInlineSnapshot(` [ [ { @@ -172,7 +174,7 @@ describe('packet diagrams', () => { 17-63: "multiple" `; await expect(parser.parse(str)).resolves.not.toThrow(); - expect(getPacket()).toMatchInlineSnapshot(` + expect(db.getPacket()).toMatchInlineSnapshot(` [ [ { diff --git a/packages/mermaid/src/diagrams/packet/parser.ts b/packages/mermaid/src/diagrams/packet/parser.ts index 1dcccd636..689d86fb3 100644 --- a/packages/mermaid/src/diagrams/packet/parser.ts +++ b/packages/mermaid/src/diagrams/packet/parser.ts @@ -3,12 +3,12 @@ import { parse } from '@mermaid-js/parser'; import type { ParserDefinition } from '../../diagram-api/types.js'; import { log } from '../../logger.js'; import { populateCommonDb } from '../common/populateCommonDb.js'; -import { db } from './db.js'; +import { PacketDB } from './db.js'; import type { PacketBlock, PacketWord } from './types.js'; const maxPacketSize = 10_000; -const populate = (ast: Packet) => { +const populate = (ast: Packet, db: PacketDB) => { populateCommonDb(ast, db); let lastBit = -1; let word: PacketWord = []; @@ -91,9 +91,17 @@ const getNextFittingBlock = ( }; export const parser: ParserDefinition = { + // @ts-expect-error - PacketDB is not assignable to DiagramDB + parser: { yy: undefined }, parse: async (input: string): Promise => { const ast: Packet = await parse('packet', input); + const db = parser.parser?.yy; + if (!(db instanceof PacketDB)) { + throw new Error( + 'parser.parser?.yy was not a PacketDB. This is due to a bug within Mermaid, please report this issue at https://github.com/mermaid-js/mermaid/issues.' + ); + } log.debug(ast); - populate(ast); + populate(ast, db); }, }; diff --git a/packages/mermaid/src/diagrams/pie/pie.spec.ts b/packages/mermaid/src/diagrams/pie/pie.spec.ts index f00906cc5..60fff01e1 100644 --- a/packages/mermaid/src/diagrams/pie/pie.spec.ts +++ b/packages/mermaid/src/diagrams/pie/pie.spec.ts @@ -139,6 +139,32 @@ describe('pie', () => { }).rejects.toThrowError(); }); + it('should handle simple pie with zero slice value', async () => { + await parser.parse(`pie title Default text position: Animal adoption + accTitle: simple pie char demo + accDescr: pie chart with 3 sections: dogs, cats, rats. Most are dogs. + "dogs" : 0 + "rats" : 40.12 + `); + + const sections = db.getSections(); + expect(sections.get('dogs')).toBe(0); + expect(sections.get('rats')).toBe(40.12); + }); + + it('should handle simple pie with negative slice value', async () => { + await expect(async () => { + await parser.parse(`pie title Default text position: Animal adoption + accTitle: simple pie char demo + accDescr: pie chart with 3 sections: dogs, cats, rats. Most are dogs. + "dogs" : -60.67 + "rats" : 40.12 + `); + }).rejects.toThrowError( + '"dogs" has invalid value: -60.67. Negative values are not allowed in pie charts. All slice values must be >= 0.' + ); + }); + it('should handle unsafe properties', async () => { await expect( parser.parse(`pie title Unsafe props test diff --git a/packages/mermaid/src/diagrams/pie/pieDb.ts b/packages/mermaid/src/diagrams/pie/pieDb.ts index 64831495c..083ee97d5 100644 --- a/packages/mermaid/src/diagrams/pie/pieDb.ts +++ b/packages/mermaid/src/diagrams/pie/pieDb.ts @@ -34,6 +34,11 @@ const clear = (): void => { }; const addSection = ({ label, value }: D3Section): void => { + if (value < 0) { + throw new Error( + `"${label}" has invalid value: ${value}. Negative values are not allowed in pie charts. All slice values must be >= 0.` + ); + } if (!sections.has(label)) { sections.set(label, value); log.debug(`added new section: ${label}, with value: ${value}`); diff --git a/packages/mermaid/src/diagrams/pie/pieRenderer.ts b/packages/mermaid/src/diagrams/pie/pieRenderer.ts index a0cdce3df..5b87613ff 100644 --- a/packages/mermaid/src/diagrams/pie/pieRenderer.ts +++ b/packages/mermaid/src/diagrams/pie/pieRenderer.ts @@ -10,20 +10,14 @@ import { cleanAndMerge, parseFontSize } from '../../utils.js'; import type { D3Section, PieDB, Sections } from './pieTypes.js'; const createPieArcs = (sections: Sections): d3.PieArcDatum[] => { - // Compute the position of each group on the pie: + const sum = [...sections.values()].reduce((acc, val) => acc + val, 0); + const pieData: D3Section[] = [...sections.entries()] - .map((element: [string, number]): D3Section => { - return { - label: element[0], - value: element[1], - }; - }) - .sort((a: D3Section, b: D3Section): number => { - return b.value - a.value; - }); - const pie: d3.Pie = d3pie().value( - (d3Section: D3Section): number => d3Section.value - ); + .map(([label, value]) => ({ label, value })) + .filter((d) => (d.value / sum) * 100 >= 1) // Remove values < 1% + .sort((a, b) => b.value - a.value); + + const pie: d3.Pie = d3pie().value((d) => d.value); return pie(pieData); }; @@ -89,13 +83,21 @@ export const draw: DrawDefinition = (text, id, _version, diagObj) => { themeVariables.pie11, themeVariables.pie12, ]; + let sum = 0; + sections.forEach((section) => { + sum += section; + }); + + // Filter out arcs that would render as 0% + const filteredArcs = arcs.filter((datum) => ((datum.data.value / sum) * 100).toFixed(0) !== '0'); + // Set the color scale const color: d3.ScaleOrdinal = scaleOrdinal(myGeneratedColors); // Build the pie chart: each part of the pie is a path that we build using the arc function. group .selectAll('mySlices') - .data(arcs) + .data(filteredArcs) .enter() .append('path') .attr('d', arcGenerator) @@ -104,15 +106,11 @@ export const draw: DrawDefinition = (text, id, _version, diagObj) => { }) .attr('class', 'pieCircle'); - let sum = 0; - sections.forEach((section) => { - sum += section; - }); // Now add the percentage. // Use the centroid method to get the best coordinates. group .selectAll('mySlices') - .data(arcs) + .data(filteredArcs) .enter() .append('text') .text((datum: d3.PieArcDatum): string => { @@ -133,15 +131,20 @@ export const draw: DrawDefinition = (text, id, _version, diagObj) => { .attr('class', 'pieTitleText'); // Add the legends/annotations for each section + const allSectionData: D3Section[] = [...sections.entries()].map(([label, value]) => ({ + label, + value, + })); + const legend = group .selectAll('.legend') - .data(color.domain()) + .data(allSectionData) .enter() .append('g') .attr('class', 'legend') .attr('transform', (_datum, index: number): string => { const height = LEGEND_RECT_SIZE + LEGEND_SPACING; - const offset = (height * color.domain().length) / 2; + const offset = (height * allSectionData.length) / 2; const horizontal = 12 * LEGEND_RECT_SIZE; const vertical = index * height - offset; return 'translate(' + horizontal + ',' + vertical + ')'; @@ -151,20 +154,18 @@ export const draw: DrawDefinition = (text, id, _version, diagObj) => { .append('rect') .attr('width', LEGEND_RECT_SIZE) .attr('height', LEGEND_RECT_SIZE) - .style('fill', color) - .style('stroke', color); + .style('fill', (d) => color(d.label)) + .style('stroke', (d) => color(d.label)); legend - .data(arcs) .append('text') .attr('x', LEGEND_RECT_SIZE + LEGEND_SPACING) .attr('y', LEGEND_RECT_SIZE - LEGEND_SPACING) - .text((datum: d3.PieArcDatum): string => { - const { label, value } = datum.data; + .text((d) => { if (db.getShowData()) { - return `${label} [${value}]`; + return `${d.label} [${d.value}]`; } - return label; + return d.label; }); const longestTextWidth = Math.max( diff --git a/packages/mermaid/src/diagrams/sankey/parser/sankey.jison b/packages/mermaid/src/diagrams/sankey/parser/sankey.jison index 9d66b69a4..d531c438a 100644 --- a/packages/mermaid/src/diagrams/sankey/parser/sankey.jison +++ b/packages/mermaid/src/diagrams/sankey/parser/sankey.jison @@ -27,6 +27,7 @@ TEXTDATA [\u0020-\u0021\u0023-\u002B\u002D-\u007E] %% "sankey-beta" { this.pushState('csv'); return 'SANKEY'; } +"sankey" { this.pushState('csv'); return 'SANKEY'; } <> { return 'EOF' } // match end of file ({CRLF}|{LF}) { return 'NEWLINE' } {COMMA} { return 'COMMA' } diff --git a/packages/mermaid/src/diagrams/sankey/parser/sankey.spec.ts b/packages/mermaid/src/diagrams/sankey/parser/sankey.spec.ts index 007cda6f9..10fc86963 100644 --- a/packages/mermaid/src/diagrams/sankey/parser/sankey.spec.ts +++ b/packages/mermaid/src/diagrams/sankey/parser/sankey.spec.ts @@ -13,7 +13,7 @@ describe('Sankey diagram', function () { sankey.parser.yy.clear(); }); - it('parses csv', () => { + it('parses csv with sankey-beta syntax', () => { const csv = path.resolve(__dirname, './energy.csv'); const data = fs.readFileSync(csv, 'utf8'); const graphDefinition = prepareTextForParsing(cleanupComments('sankey-beta\n\n ' + data)); @@ -21,7 +21,15 @@ describe('Sankey diagram', function () { sankey.parser.parse(graphDefinition); }); - it('allows __proto__ as id', function () { + it('parses csv with sankey syntax', () => { + const csv = path.resolve(__dirname, './energy.csv'); + const data = fs.readFileSync(csv, 'utf8'); + const graphDefinition = prepareTextForParsing(cleanupComments('sankey\n\n ' + data)); + + sankey.parser.parse(graphDefinition); + }); + + it('allows __proto__ as id with sankey-beta syntax', function () { sankey.parser.parse( prepareTextForParsing(`sankey-beta __proto__,A,0.597 @@ -29,5 +37,14 @@ describe('Sankey diagram', function () { `) ); }); + + it('allows __proto__ as id with sankey syntax', function () { + sankey.parser.parse( + prepareTextForParsing(`sankey + __proto__,A,0.597 + A,__proto__,0.403 + `) + ); + }); }); }); diff --git a/packages/mermaid/src/diagrams/sankey/sankeyDetector.ts b/packages/mermaid/src/diagrams/sankey/sankeyDetector.ts index 73c4d1428..589bc9ade 100644 --- a/packages/mermaid/src/diagrams/sankey/sankeyDetector.ts +++ b/packages/mermaid/src/diagrams/sankey/sankeyDetector.ts @@ -3,7 +3,7 @@ import type { DiagramDetector, ExternalDiagramDefinition } from '../../diagram-a const id = 'sankey'; const detector: DiagramDetector = (txt) => { - return /^\s*sankey-beta/.test(txt); + return /^\s*sankey(-beta)?/.test(txt); }; const loader = async () => { diff --git a/packages/mermaid/src/diagrams/sequence/parser/sequenceDiagram.jison b/packages/mermaid/src/diagrams/sequence/parser/sequenceDiagram.jison index d2e81df5f..13e63f3ae 100644 --- a/packages/mermaid/src/diagrams/sequence/parser/sequenceDiagram.jison +++ b/packages/mermaid/src/diagrams/sequence/parser/sequenceDiagram.jison @@ -14,7 +14,7 @@ // Special states for recognizing aliases // A special state for grabbing text up to the first comment/newline -%x ID ALIAS LINE +%x ID ALIAS LINE CONFIG CONFIG_DATA %x acc_title %x acc_descr @@ -28,12 +28,17 @@ \%%(?!\{)[^\n]* /* skip comments */ [^\}]\%\%[^\n]* /* skip comments */ [0-9]+(?=[ \n]+) return 'NUM'; +\@\{ { this.begin('CONFIG'); return 'CONFIG_START'; } +[^\}]+ { return 'CONFIG_CONTENT'; } +\} { this.popState(); this.popState(); return 'CONFIG_END'; } +[^\<->\->:\n,;@\s]+(?=\@\{) { yytext = yytext.trim(); return 'ACTOR'; } +[^\<->\->:\n,;@]+?([\-]*[^\<->\->:\n,;@]+?)*?(?=((?!\n)\s)+"as"(?!\n)\s|[#\n;]|$) { yytext = yytext.trim(); this.begin('ALIAS'); return 'ACTOR'; } "box" { this.begin('LINE'); return 'box'; } "participant" { this.begin('ID'); return 'participant'; } "actor" { this.begin('ID'); return 'participant_actor'; } "create" return 'create'; "destroy" { this.begin('ID'); return 'destroy'; } -[^\<->\->:\n,;]+?([\-]*[^\<->\->:\n,;]+?)*?(?=((?!\n)\s)+"as"(?!\n)\s|[#\n;]|$) { yytext = yytext.trim(); this.begin('ALIAS'); return 'ACTOR'; } +[^<\->\->:\n,;]+?([\-]*[^<\->\->:\n,;]+?)*?(?=((?!\n)\s)+"as"(?!\n)\s|[#\n;]|$) { yytext = yytext.trim(); this.begin('ALIAS'); return 'ACTOR'; } "as" { this.popState(); this.popState(); this.begin('LINE'); return 'AS'; } (?:) { this.popState(); this.popState(); return 'NEWLINE'; } "loop" { this.begin('LINE'); return 'loop'; } @@ -73,7 +78,7 @@ accDescr\s*"{"\s* { this.begin("acc_descr_multili "off" return 'off'; "," return ','; ";" return 'NEWLINE'; -[^\+\<->\->:\n,;]+((?!(\-x|\-\-x|\-\)|\-\-\)))[\-]*[^\+\<->\->:\n,;]+)* { yytext = yytext.trim(); return 'ACTOR'; } +[^+<\->\->:\n,;]+((?!(\-x|\-\-x|\-\)|\-\-\)))[\-]*[^\+<\->\->:\n,;]+)* { yytext = yytext.trim(); return 'ACTOR'; } "->>" return 'SOLID_ARROW'; "<<->>" return 'BIDIRECTIONAL_SOLID_ARROW'; "-->>" return 'DOTTED_ARROW'; @@ -231,6 +236,8 @@ participant_statement | 'participant_actor' actor 'AS' restOfLine 'NEWLINE' {$2.draw='actor'; $2.type='addParticipant';$2.description=yy.parseMessage($4); $$=$2;} | 'participant_actor' actor 'NEWLINE' {$2.draw='actor'; $2.type='addParticipant'; $$=$2;} | 'destroy' actor 'NEWLINE' {$2.type='destroyParticipant'; $$=$2;} + | 'participant' actor_with_config 'NEWLINE' {$2.draw='participant'; $2.type='addParticipant'; $$=$2;} + ; note_statement @@ -301,6 +308,23 @@ signal { $$ = [$1,$3,{type: 'addMessage', from:$1.actor, to:$3.actor, signalType:$2, msg:$4}]} ; +actor_with_config + : ACTOR config_object + { + $$ = { + type: 'addParticipant', + actor: $1, + config: $2 + }; + } + ; + +config_object + : CONFIG_START CONFIG_CONTENT CONFIG_END + { + $$ = $2.trim(); + } + ; // actor // : actor_participant // | actor_actor @@ -313,7 +337,7 @@ signaltype : SOLID_OPEN_ARROW { $$ = yy.LINETYPE.SOLID_OPEN; } | DOTTED_OPEN_ARROW { $$ = yy.LINETYPE.DOTTED_OPEN; } | SOLID_ARROW { $$ = yy.LINETYPE.SOLID; } - | BIDIRECTIONAL_SOLID_ARROW { $$ = yy.LINETYPE.BIDIRECTIONAL_SOLID; } + | BIDIRECTIONAL_SOLID_ARROW { $$ = yy.LINETYPE.BIDIRECTIONAL_SOLID; } | DOTTED_ARROW { $$ = yy.LINETYPE.DOTTED; } | BIDIRECTIONAL_DOTTED_ARROW { $$ = yy.LINETYPE.BIDIRECTIONAL_DOTTED; } | SOLID_CROSS { $$ = yy.LINETYPE.SOLID_CROSS; } diff --git a/packages/mermaid/src/diagrams/sequence/sequenceDb.ts b/packages/mermaid/src/diagrams/sequence/sequenceDb.ts index c6b44dac0..67ae19de5 100644 --- a/packages/mermaid/src/diagrams/sequence/sequenceDb.ts +++ b/packages/mermaid/src/diagrams/sequence/sequenceDb.ts @@ -1,4 +1,5 @@ import { getConfig } from '../../diagram-api/diagramAPI.js'; +import * as yaml from 'js-yaml'; import type { DiagramDB } from '../../diagram-api/types.js'; import { log } from '../../logger.js'; import { ImperativeState } from '../../utils/imperativeState.js'; @@ -13,6 +14,7 @@ import { setDiagramTitle, } from '../common/commonDb.js'; import type { Actor, AddMessageParams, Box, Message, Note } from './types.js'; +import type { ParticipantMetaData } from '../../types.js'; interface SequenceState { prevActor?: string; @@ -75,6 +77,17 @@ const PLACEMENT = { OVER: 2, } as const; +export const PARTICIPANT_TYPE = { + ACTOR: 'actor', + BOUNDARY: 'boundary', + COLLECTIONS: 'collections', + CONTROL: 'control', + DATABASE: 'database', + ENTITY: 'entity', + PARTICIPANT: 'participant', + QUEUE: 'queue', +} as const; + export class SequenceDB implements DiagramDB { private readonly state = new ImperativeState(() => ({ prevActor: undefined, @@ -119,9 +132,22 @@ export class SequenceDB implements DiagramDB { id: string, name: string, description: { text: string; wrap?: boolean | null; type: string }, - type: string + type: string, + metadata?: any ) { let assignedBox = this.state.records.currentBox; + let doc; + if (metadata !== undefined) { + let yamlData; + // detect if shapeData contains a newline character + if (!metadata.includes('\n')) { + yamlData = '{\n' + metadata + '\n}'; + } else { + yamlData = metadata + '\n'; + } + doc = yaml.load(yamlData, { schema: yaml.JSON_SCHEMA }) as ParticipantMetaData; + } + type = doc?.type ?? type; const old = this.state.records.actors.get(id); if (old) { // If already set and trying to set to a new one throw error @@ -518,7 +544,7 @@ export class SequenceDB implements DiagramDB { }); break; case 'addParticipant': - this.addActor(param.actor, param.actor, param.description, param.draw); + this.addActor(param.actor, param.actor, param.description, param.draw, param.config); break; case 'createParticipant': if (this.state.records.actors.has(param.actor)) { @@ -527,7 +553,7 @@ export class SequenceDB implements DiagramDB { ); } this.state.records.lastCreated = param.actor; - this.addActor(param.actor, param.actor, param.description, param.draw); + this.addActor(param.actor, param.actor, param.description, param.draw, param.config); this.state.records.createdActors.set(param.actor, this.state.records.messages.length); break; case 'destroyParticipant': diff --git a/packages/mermaid/src/diagrams/sequence/sequenceDiagram.spec.js b/packages/mermaid/src/diagrams/sequence/sequenceDiagram.spec.js index c3b8c2b4a..4e69fda7e 100644 --- a/packages/mermaid/src/diagrams/sequence/sequenceDiagram.spec.js +++ b/packages/mermaid/src/diagrams/sequence/sequenceDiagram.spec.js @@ -350,6 +350,26 @@ Bob-->Alice-in-Wonderland:I am good thanks!`); expect(messages[1].from).toBe('Bob'); }); + it('should handle equals in participant names', async () => { + const diagram = await Diagram.fromText(` +sequenceDiagram +participant Alice=Wonderland +participant Bob +Alice=Wonderland->Bob:Hello Bob, how are - you? +Bob-->Alice=Wonderland:I am good thanks!`); + + const actors = diagram.db.getActors(); + expect([...actors.keys()]).toEqual(['Alice=Wonderland', 'Bob']); + expect(actors.get('Alice=Wonderland').description).toBe('Alice=Wonderland'); + expect(actors.get('Bob').description).toBe('Bob'); + + const messages = diagram.db.getMessages(); + + expect(messages.length).toBe(2); + expect(messages[0].from).toBe('Alice=Wonderland'); + expect(messages[1].from).toBe('Bob'); + }); + it('should alias participants', async () => { const diagram = await Diagram.fromText(` sequenceDiagram @@ -1348,7 +1368,7 @@ link a: Tests @ https://tests.contoso.com/?svc=alice@contoso.com it('should handle box without description', async () => { const diagram = await Diagram.fromText(` sequenceDiagram - box Aqua + box aqua participant a as Alice participant b as Bob end @@ -1364,7 +1384,7 @@ link a: Tests @ https://tests.contoso.com/?svc=alice@contoso.com const boxes = diagram.db.getBoxes(); expect(boxes[0].name).toBeFalsy(); expect(boxes[0].actorKeys).toEqual(['a', 'b']); - expect(boxes[0].fill).toEqual('Aqua'); + expect(boxes[0].fill).toEqual('aqua'); }); it('should handle simple actor creation', async () => { @@ -2038,4 +2058,272 @@ Bob->>Alice:Got it! expect(messages[0].from).toBe('Alice'); expect(messages[0].to).toBe('Bob'); }); + describe('when parsing extended participant syntax', () => { + it('should parse participants with different quote styles and whitespace', async () => { + const diagram = await Diagram.fromText(` + sequenceDiagram + participant Alice@{ "type" : "database" } + participant Bob@{ "type" : "database" } + participant Carl@{ type: "database" } + participant David@{ "type" : 'database' } + participant Eve@{ type: 'database' } + participant Favela@{ "type" : "database" } + Bob->>+Alice: Hi Alice + Alice->>+Bob: Hi Bob + `); + + const actors = diagram.db.getActors(); + + expect(actors.get('Alice').type).toBe('database'); + expect(actors.get('Alice').description).toBe('Alice'); + + expect(actors.get('Bob').type).toBe('database'); + expect(actors.get('Bob').description).toBe('Bob'); + + expect(actors.get('Carl').type).toBe('database'); + expect(actors.get('Carl').description).toBe('Carl'); + + expect(actors.get('David').type).toBe('database'); + expect(actors.get('David').description).toBe('David'); + + expect(actors.get('Eve').type).toBe('database'); + expect(actors.get('Eve').description).toBe('Eve'); + + expect(actors.get('Favela').type).toBe('database'); + expect(actors.get('Favela').description).toBe('Favela'); + + // Verify messages were parsed correctly + const messages = diagram.db.getMessages(); + expect(messages.length).toBe(4); // 2 messages + 2 activation messages + expect(messages[0].from).toBe('Bob'); + expect(messages[0].to).toBe('Alice'); + expect(messages[0].message).toBe('Hi Alice'); + expect(messages[2].from).toBe('Alice'); // Second message (index 2 due to activation) + expect(messages[2].to).toBe('Bob'); + expect(messages[2].message).toBe('Hi Bob'); + }); + + it('should parse mixed participant types with extended syntax', async () => { + const diagram = await Diagram.fromText(` + sequenceDiagram + participant lead + participant dsa@{ "type" : "queue" } + API->>+Database: getUserb + Database-->>-API: userb + dsa --> Database: hello +`); + + // Verify actors were created + const actors = diagram.db.getActors(); + + expect(actors.get('lead').type).toBe('participant'); + expect(actors.get('lead').description).toBe('lead'); + + // Participant with extended syntax + expect(actors.get('dsa').type).toBe('queue'); + expect(actors.get('dsa').description).toBe('dsa'); + + // Implicitly created actors (from messages) + expect(actors.get('API').type).toBe('participant'); + expect(actors.get('API').description).toBe('API'); + + expect(actors.get('Database').type).toBe('participant'); + expect(actors.get('Database').description).toBe('Database'); + + // Verify messages were parsed correctly + const messages = diagram.db.getMessages(); + expect(messages.length).toBe(5); // 3 messages + 2 activation messages + + // First message with activation + expect(messages[0].from).toBe('API'); + expect(messages[0].to).toBe('Database'); + expect(messages[0].message).toBe('getUserb'); + expect(messages[0].activate).toBe(true); + + // Second message with deactivation + expect(messages[2].from).toBe('Database'); + expect(messages[2].to).toBe('API'); + expect(messages[2].message).toBe('userb'); + + // Third message + expect(messages[4].from).toBe('dsa'); + expect(messages[4].to).toBe('Database'); + expect(messages[4].message).toBe('hello'); + }); + + it('should fail for malformed JSON in participant definition', async () => { + const invalidDiagram = ` + sequenceDiagram + participant D@{ "type: "entity" } + participant E@{ "type": "dat + abase } + `; + + let error = false; + try { + await mermaidAPI.parse(invalidDiagram); + } catch (e) { + error = true; + } + expect(error).toBe(true); + }); + + it('should fail for missing colon separator', async () => { + const invalidDiagram = ` + sequenceDiagram + participant C@{ "type" "control" } + C ->> C: action + `; + + let error = false; + try { + await mermaidAPI.parse(invalidDiagram); + } catch (e) { + error = true; + } + expect(error).toBe(true); + }); + + it('should fail for missing closing brace', async () => { + const invalidDiagram = ` + sequenceDiagram + participant E@{ "type": "entity" + E ->> E: process + `; + + let error = false; + try { + await mermaidAPI.parse(invalidDiagram); + } catch (e) { + error = true; + } + expect(error).toBe(true); + }); + }); + describe('participant type parsing', () => { + it('should parse boundary participant', async () => { + const diagram = await Diagram.fromText(` + sequenceDiagram + participant boundary@{ "type" : "boundary" } + boundary->boundary: test + `); + const actors = diagram.db.getActors(); + expect(actors.get('boundary').type).toBe('boundary'); + expect(actors.get('boundary').description).toBe('boundary'); + }); + + it('should parse control participant', async () => { + const diagram = await Diagram.fromText(` + sequenceDiagram + participant C@{ "type" : "control" } + C->C: test + `); + const actors = diagram.db.getActors(); + expect(actors.get('C').type).toBe('control'); + expect(actors.get('C').description).toBe('C'); + }); + + it('should parse entity participant', async () => { + const diagram = await Diagram.fromText(` + sequenceDiagram + participant E@{ "type" : "entity" } + E->E: test + `); + const actors = diagram.db.getActors(); + expect(actors.get('E').type).toBe('entity'); + expect(actors.get('E').description).toBe('E'); + }); + + it('should parse database participant', async () => { + const diagram = await Diagram.fromText(` + sequenceDiagram + participant D@{ "type" : "database" } + D->D: test + `); + const actors = diagram.db.getActors(); + expect(actors.get('D').type).toBe('database'); + expect(actors.get('D').description).toBe('D'); + }); + + it('should parse collections participant', async () => { + const diagram = await Diagram.fromText(` + sequenceDiagram + participant L@{ "type" : "collections" } + L->L: test + `); + const actors = diagram.db.getActors(); + expect(actors.get('L').type).toBe('collections'); + expect(actors.get('L').description).toBe('L'); + }); + + it('should parse queue participant', async () => { + const diagram = await Diagram.fromText(` + sequenceDiagram + participant Q@{ "type" : "queue" } + Q->Q: test + `); + const actors = diagram.db.getActors(); + expect(actors.get('Q').type).toBe('queue'); + expect(actors.get('Q').description).toBe('Q'); + }); + }); + + describe('participant type parsing', () => { + it('should parse actor participant', async () => { + const diagram = await Diagram.fromText(` + sequenceDiagram + participant A@{ "type" : "queue" } + A->A: test + `); + const actors = diagram.db.getActors(); + expect(actors.get('A').type).toBe('queue'); + expect(actors.get('A').description).toBe('A'); + }); + + it('should parse participant participant', async () => { + const diagram = await Diagram.fromText(` + sequenceDiagram + participant P@{ "type" : "database" } + P->P: test + `); + const actors = diagram.db.getActors(); + expect(actors.get('P').type).toBe('database'); + expect(actors.get('P').description).toBe('P'); + }); + + it('should parse boundary using actor keyword', async () => { + const diagram = await Diagram.fromText(` + sequenceDiagram + participant Alice@{ "type" : "collections" } + participant Bob@{ "type" : "control" } + Alice->>Bob: Hello Bob, how are you? + `); + const actors = diagram.db.getActors(); + expect(actors.get('Alice').type).toBe('collections'); + expect(actors.get('Bob').type).toBe('control'); + expect(actors.get('Bob').description).toBe('Bob'); + }); + + it('should parse control using participant keyword', async () => { + const diagram = await Diagram.fromText(` + sequenceDiagram + participant C@{ "type" : "control" } + C->C: test + `); + const actors = diagram.db.getActors(); + expect(actors.get('C').type).toBe('control'); + expect(actors.get('C').description).toBe('C'); + }); + + it('should parse entity using actor keyword', async () => { + const diagram = await Diagram.fromText(` + sequenceDiagram + participant E@{ "type" : "entity" } + E->E: test + `); + const actors = diagram.db.getActors(); + expect(actors.get('E').type).toBe('entity'); + expect(actors.get('E').description).toBe('E'); + }); + }); }); diff --git a/packages/mermaid/src/diagrams/sequence/sequenceRenderer.ts b/packages/mermaid/src/diagrams/sequence/sequenceRenderer.ts index cfba92b79..5fac3cf2d 100644 --- a/packages/mermaid/src/diagrams/sequence/sequenceRenderer.ts +++ b/packages/mermaid/src/diagrams/sequence/sequenceRenderer.ts @@ -10,6 +10,7 @@ import assignWithDepth from '../../assignWithDepth.js'; import utils from '../../utils.js'; import { configureSvgSize } from '../../setupGraphViewbox.js'; import type { Diagram } from '../../Diagram.js'; +import { PARTICIPANT_TYPE } from './sequenceDb.js'; let conf = {}; @@ -476,7 +477,29 @@ const drawMessage = async function (diagram, msgModel, lineStartY: number, diagO // add node number if (sequenceVisible || conf.showSequenceNumbers) { - line.attr('marker-start', 'url(' + url + '#sequencenumber)'); + const isBidirectional = + type === diagObj.db.LINETYPE.BIDIRECTIONAL_SOLID || + type === diagObj.db.LINETYPE.BIDIRECTIONAL_DOTTED; + + if (isBidirectional) { + const SEQUENCE_NUMBER_RADIUS = 6; + + if (startx < stopx) { + line.attr('x1', startx + 2 * SEQUENCE_NUMBER_RADIUS); + } else { + line.attr('x1', startx + SEQUENCE_NUMBER_RADIUS); + } + } + + diagram + .append('line') + .attr('x1', startx) + .attr('y1', lineStartY) + .attr('x2', startx) + .attr('y2', lineStartY) + .attr('stroke-width', 0) + .attr('marker-start', 'url(' + url + '#sequencenumber)'); + diagram .append('text') .attr('x', startx) @@ -724,11 +747,19 @@ function adjustCreatedDestroyedData( msgModel.startx = msgModel.startx - adjustment; } } + const actorArray = [ + PARTICIPANT_TYPE.ACTOR, + PARTICIPANT_TYPE.CONTROL, + PARTICIPANT_TYPE.ENTITY, + PARTICIPANT_TYPE.DATABASE, + ]; // if it is a create message if (createdActors.get(msg.to) == index) { const actor = actors.get(msg.to); - const adjustment = actor.type == 'actor' ? ACTOR_TYPE_WIDTH / 2 + 3 : actor.width / 2 + 3; + const adjustment = actorArray.includes(actor.type) + ? ACTOR_TYPE_WIDTH / 2 + 3 + : actor.width / 2 + 3; receiverAdjustment(actor, adjustment); actor.starty = lineStartY - actor.height / 2; bounds.bumpVerticalPos(actor.height / 2); @@ -737,7 +768,7 @@ function adjustCreatedDestroyedData( else if (destroyedActors.get(msg.from) == index) { const actor = actors.get(msg.from); if (conf.mirrorActors) { - const adjustment = actor.type == 'actor' ? ACTOR_TYPE_WIDTH / 2 : actor.width / 2; + const adjustment = actorArray.includes(actor.type) ? ACTOR_TYPE_WIDTH / 2 : actor.width / 2; senderAdjustment(actor, adjustment); } actor.stopy = lineStartY - actor.height / 2; @@ -747,7 +778,9 @@ function adjustCreatedDestroyedData( else if (destroyedActors.get(msg.to) == index) { const actor = actors.get(msg.to); if (conf.mirrorActors) { - const adjustment = actor.type == 'actor' ? ACTOR_TYPE_WIDTH / 2 + 3 : actor.width / 2 + 3; + const adjustment = actorArray.includes(actor.type) + ? ACTOR_TYPE_WIDTH / 2 + 3 + : actor.width / 2 + 3; receiverAdjustment(actor, adjustment); } actor.stopy = lineStartY - actor.height / 2; @@ -1065,10 +1098,11 @@ export const draw = async function (_text: string, id: string, _version: string, for (const box of bounds.models.boxes) { box.height = bounds.getVerticalPos() - box.y; bounds.insert(box.x, box.y, box.x + box.width, box.height); - box.startx = box.x; - box.starty = box.y; - box.stopx = box.startx + box.width; - box.stopy = box.starty + box.height; + const boxPadding = conf.boxMargin * 2; + box.startx = box.x - boxPadding; + box.starty = box.y - boxPadding * 0.25; + box.stopx = box.startx + box.width + 2 * boxPadding; + box.stopy = box.starty + box.height + boxPadding * 0.75; box.stroke = 'rgb(0,0,0, 0.5)'; svgDraw.drawBox(diagram, box, conf); } @@ -1333,6 +1367,9 @@ async function calculateActorMargins( return (total += actors.get(aKey).width + (actors.get(aKey).margin || 0)); }, 0); + const standardBoxPadding = conf.boxMargin * 8; + totalWidth += standardBoxPadding; + totalWidth -= 2 * conf.boxTextMargin; if (box.wrap) { box.name = utils.wrapLabel(box.name, totalWidth - 2 * conf.wrapPadding, textFont); diff --git a/packages/mermaid/src/diagrams/sequence/styles.js b/packages/mermaid/src/diagrams/sequence/styles.js index 5c36b4ed1..3cee9d3dc 100644 --- a/packages/mermaid/src/diagrams/sequence/styles.js +++ b/packages/mermaid/src/diagrams/sequence/styles.js @@ -12,6 +12,11 @@ const getStyles = (options) => .actor-line { stroke: ${options.actorLineColor}; } + + .innerArc { + stroke-width: 1.5; + stroke-dasharray: none; + } .messageLine0 { stroke-width: 1.5; @@ -115,6 +120,7 @@ const getStyles = (options) => fill: ${options.actorBkg}; stroke-width: 2px; } + `; export default getStyles; diff --git a/packages/mermaid/src/diagrams/sequence/svgDraw.js b/packages/mermaid/src/diagrams/sequence/svgDraw.js index 04ccd8a84..1971082a8 100644 --- a/packages/mermaid/src/diagrams/sequence/svgDraw.js +++ b/packages/mermaid/src/diagrams/sequence/svgDraw.js @@ -1,8 +1,12 @@ -import common, { calculateMathMLDimensions, hasKatex, renderKatex } from '../common/common.js'; -import * as svgDrawCommon from '../common/svgDrawCommon.js'; -import { ZERO_WIDTH_SPACE, parseFontSize } from '../../utils.js'; import { sanitizeUrl } from '@braintree/sanitize-url'; import * as configApi from '../../config.js'; +import { ZERO_WIDTH_SPACE, parseFontSize } from '../../utils.js'; +import common, { + calculateMathMLDimensions, + hasKatex, + renderKatexSanitized, +} from '../common/common.js'; +import * as svgDrawCommon from '../common/svgDrawCommon.js'; export const ACTOR_TYPE_WIDTH = 18 * 2; const TOP_ACTOR_CLASS = 'actor-top'; @@ -87,13 +91,13 @@ const popupMenuToggle = function (popId) { export const drawKatex = async function (elem, textData, msgModel = null) { let textElem = elem.append('foreignObject'); - const lines = await renderKatex(textData.text, configApi.getConfig()); + const linesSanitized = await renderKatexSanitized(textData.text, configApi.getConfig()); const divElem = textElem .append('xhtml:div') .attr('style', 'width: fit-content;') .attr('xmlns', 'http://www.w3.org/1999/xhtml') - .html(lines); + .html(linesSanitized); const dim = divElem.node().getBoundingClientRect(); textElem.attr('height', Math.round(dim.height)).attr('width', Math.round(dim.width)); @@ -411,6 +415,600 @@ const drawActorTypeParticipant = function (elem, actor, conf, isFooter) { return height; }; +/** + * Draws an actor in the diagram with the attached line + * + * @param {any} elem - The diagram we'll draw to. + * @param {any} actor - The actor to draw. + * @param {any} conf - DrawText implementation discriminator object + * @param {boolean} isFooter - If the actor is the footer one + */ +const drawActorTypeCollections = function (elem, actor, conf, isFooter) { + const actorY = isFooter ? actor.stopy : actor.starty; + const center = actor.x + actor.width / 2; + const centerY = actorY + actor.height; + + const boxplusLineGroup = elem.append('g').lower(); + var g = boxplusLineGroup; + + if (!isFooter) { + actorCnt++; + if (Object.keys(actor.links || {}).length && !conf.forceMenus) { + g.attr('onclick', popupMenuToggle(`actor${actorCnt}_popup`)).attr('cursor', 'pointer'); + } + g.append('line') + .attr('id', 'actor' + actorCnt) + .attr('x1', center) + .attr('y1', centerY) + .attr('x2', center) + .attr('y2', 2000) + .attr('class', 'actor-line 200') + .attr('stroke-width', '0.5px') + .attr('stroke', '#999') + .attr('name', actor.name); + + g = boxplusLineGroup.append('g'); + actor.actorCnt = actorCnt; + + if (actor.links != null) { + g.attr('id', 'root-' + actorCnt); + } + } + + const rect = svgDrawCommon.getNoteRect(); + var cssclass = 'actor'; + if (actor.properties?.class) { + cssclass = actor.properties.class; + } else { + rect.fill = '#eaeaea'; + } + if (isFooter) { + cssclass += ` ${BOTTOM_ACTOR_CLASS}`; + } else { + cssclass += ` ${TOP_ACTOR_CLASS}`; + } + rect.x = actor.x; + rect.y = actorY; + rect.width = actor.width; + rect.height = actor.height; + rect.class = cssclass; + rect.name = actor.name; + + // DRAW STACKED RECTANGLES + const offset = 6; + const shadowRect = { + ...rect, + x: rect.x + (isFooter ? -offset : -offset), + y: rect.y + (isFooter ? +offset : +offset), + class: 'actor', + }; + const rectElem = drawRect(g, rect); // draw main rectangle on top + drawRect(g, shadowRect); + actor.rectData = rect; + + if (actor.properties?.icon) { + const iconSrc = actor.properties.icon.trim(); + if (iconSrc.charAt(0) === '@') { + svgDrawCommon.drawEmbeddedImage(g, rect.x + rect.width - 20, rect.y + 10, iconSrc.substr(1)); + } else { + svgDrawCommon.drawImage(g, rect.x + rect.width - 20, rect.y + 10, iconSrc); + } + } + + _drawTextCandidateFunc(conf, hasKatex(actor.description))( + actor.description, + g, + rect.x - offset, + rect.y + offset, + rect.width, + rect.height, + { class: `actor ${ACTOR_BOX_CLASS}` }, + conf + ); + + let height = actor.height; + if (rectElem.node) { + const bounds = rectElem.node().getBBox(); + actor.height = bounds.height; + height = bounds.height; + } + + return height; +}; + +const drawActorTypeQueue = function (elem, actor, conf, isFooter) { + const actorY = isFooter ? actor.stopy : actor.starty; + const center = actor.x + actor.width / 2; + const centerY = actorY + actor.height; + + const boxplusLineGroup = elem.append('g').lower(); + let g = boxplusLineGroup; + + if (!isFooter) { + actorCnt++; + if (Object.keys(actor.links || {}).length && !conf.forceMenus) { + g.attr('onclick', popupMenuToggle(`actor${actorCnt}_popup`)).attr('cursor', 'pointer'); + } + g.append('line') + .attr('id', 'actor' + actorCnt) + .attr('x1', center) + .attr('y1', centerY) + .attr('x2', center) + .attr('y2', 2000) + .attr('class', 'actor-line 200') + .attr('stroke-width', '0.5px') + .attr('stroke', '#999') + .attr('name', actor.name); + + g = boxplusLineGroup.append('g'); + actor.actorCnt = actorCnt; + + if (actor.links != null) { + g.attr('id', 'root-' + actorCnt); + } + } + + const rect = svgDrawCommon.getNoteRect(); + let cssclass = 'actor'; + if (actor.properties?.class) { + cssclass = actor.properties.class; + } else { + rect.fill = '#eaeaea'; + } + + if (isFooter) { + cssclass += ` ${BOTTOM_ACTOR_CLASS}`; + } else { + cssclass += ` ${TOP_ACTOR_CLASS}`; + } + + rect.x = actor.x; + rect.y = actorY; + rect.width = actor.width; + rect.height = actor.height; + rect.class = cssclass; + rect.name = actor.name; + + // Cylinder dimensions + const ry = rect.height / 2; + const rx = ry / (2.5 + rect.height / 50); + + // Cylinder base group + const cylinderGroup = g.append('g'); + const cylinderArc = g.append('g'); + + // Main cylinder body + cylinderGroup + .append('path') + .attr( + 'd', + `M ${rect.x},${rect.y + ry} + a ${rx},${ry} 0 0 0 0,${rect.height} + h ${rect.width - 2 * rx} + a ${rx},${ry} 0 0 0 0,-${rect.height} + Z + ` + ) + .attr('class', cssclass); + cylinderArc + .append('path') + .attr( + 'd', + `M ${rect.x},${rect.y + ry} + a ${rx},${ry} 0 0 0 0,${rect.height}` + ) + .attr('stroke', '#666') + .attr('stroke-width', '1px') + .attr('class', cssclass); + + cylinderGroup.attr('transform', `translate(${rx}, ${-(rect.height / 2)})`); + cylinderArc.attr('transform', `translate(${rect.width - rx}, ${-rect.height / 2})`); + + actor.rectData = rect; + + if (actor.properties?.icon) { + const iconSrc = actor.properties.icon.trim(); + const iconX = rect.x + rect.width - 20; + const iconY = rect.y + 10; + if (iconSrc.charAt(0) === '@') { + svgDrawCommon.drawEmbeddedImage(g, iconX, iconY, iconSrc.substr(1)); + } else { + svgDrawCommon.drawImage(g, iconX, iconY, iconSrc); + } + } + + _drawTextCandidateFunc(conf, hasKatex(actor.description))( + actor.description, + g, + rect.x, + rect.y, + rect.width, + rect.height, + { class: `actor ${ACTOR_BOX_CLASS}` }, + conf + ); + + let height = actor.height; + const lastPath = cylinderGroup.select('path:last-child'); + if (lastPath.node()) { + const bounds = lastPath.node().getBBox(); + actor.height = bounds.height; + height = bounds.height; + } + + return height; +}; + +const drawActorTypeControl = function (elem, actor, conf, isFooter) { + const actorY = isFooter ? actor.stopy : actor.starty; + const center = actor.x + actor.width / 2; + const centerY = actorY + 75; + + const line = elem.append('g').lower(); + + if (!isFooter) { + actorCnt++; + line + .append('line') + .attr('id', 'actor' + actorCnt) + .attr('x1', center) + .attr('y1', centerY) + .attr('x2', center) + .attr('y2', 2000) + .attr('class', 'actor-line 200') + .attr('stroke-width', '0.5px') + .attr('stroke', '#999') + .attr('name', actor.name); + + actor.actorCnt = actorCnt; + } + const actElem = elem.append('g'); + let cssClass = ACTOR_MAN_FIGURE_CLASS; + if (isFooter) { + cssClass += ` ${BOTTOM_ACTOR_CLASS}`; + } else { + cssClass += ` ${TOP_ACTOR_CLASS}`; + } + actElem.attr('class', cssClass); + actElem.attr('name', actor.name); + + const rect = svgDrawCommon.getNoteRect(); + rect.x = actor.x; + rect.y = actorY; + rect.fill = '#eaeaea'; + rect.width = actor.width; + rect.height = actor.height; + rect.class = 'actor'; + + const cx = actor.x + actor.width / 2; + const cy = actorY + 30; + const r = 18; + + actElem + .append('defs') + .append('marker') + .attr('id', 'filled-head-control') + .attr('refX', 11) + .attr('refY', 5.8) + .attr('markerWidth', 20) + .attr('markerHeight', 28) + .attr('orient', '172.5') + .append('path') + .attr('d', 'M 14.4 5.6 L 7.2 10.4 L 8.8 5.6 L 7.2 0.8 Z'); + + // Draw the base circle + actElem + .append('circle') + .attr('cx', cx) + .attr('cy', cy) + .attr('r', r) + .attr('fill', '#eaeaf7') + .attr('stroke', '#666') + .attr('stroke-width', 1.2); + + // Draw looping arrow as arc path + actElem + .append('line') + .attr('marker-end', 'url(#filled-head-control)') + .attr('transform', `translate(${cx}, ${cy - r})`); + + const bounds = actElem.node().getBBox(); + actor.height = bounds.height + 2 * (conf?.sequence?.labelBoxHeight ?? 0); + + _drawTextCandidateFunc(conf, hasKatex(actor.description))( + actor.description, + actElem, + rect.x, + rect.y + r + (isFooter ? 5 : 10), + rect.width, + rect.height, + { class: `actor ${ACTOR_MAN_FIGURE_CLASS}` }, + conf + ); + + return actor.height; +}; + +const drawActorTypeEntity = function (elem, actor, conf, isFooter) { + const actorY = isFooter ? actor.stopy : actor.starty; + const center = actor.x + actor.width / 2; + const centerY = actorY + 75; + + const line = elem.append('g').lower(); + + const actElem = elem.append('g'); + let cssClass = ACTOR_MAN_FIGURE_CLASS; + if (isFooter) { + cssClass += ` ${BOTTOM_ACTOR_CLASS}`; + } else { + cssClass += ` ${TOP_ACTOR_CLASS}`; + } + actElem.attr('class', cssClass); + actElem.attr('name', actor.name); + + const rect = svgDrawCommon.getNoteRect(); + rect.x = actor.x; + rect.y = actorY; + rect.fill = '#eaeaea'; + rect.width = actor.width; + rect.height = actor.height; + rect.class = 'actor'; + + const cx = actor.x + actor.width / 2; + const cy = actorY + (!isFooter ? 25 : 10); + const r = 18; + + actElem + .append('circle') + .attr('cx', cx) + .attr('cy', cy) + .attr('r', r) + .attr('width', actor.width) + .attr('height', actor.height); + + actElem + .append('line') + .attr('x1', cx - r) + .attr('x2', cx + r) + .attr('y1', cy + r) + .attr('y2', cy + r) + .attr('stroke', '#333') + .attr('stroke-width', 2); + + const bounds = actElem.node().getBBox(); + actor.height = bounds.height + (conf?.sequence?.labelBoxHeight ?? 0); + + if (!isFooter) { + actorCnt++; + line + .append('line') + .attr('id', 'actor' + actorCnt) + .attr('x1', center) + .attr('y1', centerY) + .attr('x2', center) + .attr('y2', 2000) + .attr('class', 'actor-line 200') + .attr('stroke-width', '0.5px') + .attr('stroke', '#999') + .attr('name', actor.name); + + actor.actorCnt = actorCnt; + } + + _drawTextCandidateFunc(conf, hasKatex(actor.description))( + actor.description, + actElem, + rect.x, + rect.y + (!isFooter ? (cy + r - actorY) / 2 : (cy - actorY + r - 5) / 2), + rect.width, + rect.height, + { class: `actor ${ACTOR_MAN_FIGURE_CLASS}` }, + conf + ); + + if (!isFooter) { + actElem.attr('transform', `translate(${0}, ${r / 2})`); + } else { + actElem.attr('transform', `translate(${0}, ${r / 2})`); + } + + return actor.height; +}; + +const drawActorTypeDatabase = function (elem, actor, conf, isFooter) { + const actorY = isFooter ? actor.stopy : actor.starty; + const center = actor.x + actor.width / 2; + const centerY = actorY + actor.height + 2 * conf.boxTextMargin; + + const boxplusLineGroup = elem.append('g').lower(); + let g = boxplusLineGroup; + + if (!isFooter) { + actorCnt++; + if (Object.keys(actor.links || {}).length && !conf.forceMenus) { + g.attr('onclick', popupMenuToggle(`actor${actorCnt}_popup`)).attr('cursor', 'pointer'); + } + g.append('line') + .attr('id', 'actor' + actorCnt) + .attr('x1', center) + .attr('y1', centerY) + .attr('x2', center) + .attr('y2', 2000) + .attr('class', 'actor-line 200') + .attr('stroke-width', '0.5px') + .attr('stroke', '#999') + .attr('name', actor.name); + + g = boxplusLineGroup.append('g'); + actor.actorCnt = actorCnt; + + if (actor.links != null) { + g.attr('id', 'root-' + actorCnt); + } + } + + const rect = svgDrawCommon.getNoteRect(); + + let cssclass = 'actor'; + if (actor.properties?.class) { + cssclass = actor.properties.class; + } else { + rect.fill = '#eaeaea'; + } + + if (isFooter) { + cssclass += ` ${BOTTOM_ACTOR_CLASS}`; + } else { + cssclass += ` ${TOP_ACTOR_CLASS}`; + } + + rect.x = actor.x; + rect.y = actorY; + rect.width = actor.width; + rect.height = actor.height; + rect.class = cssclass; + rect.name = actor.name; + + // Cylinder dimensions + rect.x = actor.x; + rect.y = actorY; + const w = rect.width / 4; + const h = rect.width / 4; + const rx = w / 2; + const ry = rx / (2.5 + w / 50); + + // Cylinder base group + const cylinderGroup = g.append('g'); + + const d = ` + M ${rect.x},${rect.y + ry} + a ${rx},${ry} 0 0 0 ${w},0 + a ${rx},${ry} 0 0 0 -${w},0 + l 0,${h - 2 * ry} + a ${rx},${ry} 0 0 0 ${w},0 + l 0,-${h - 2 * ry} +`; + // Draw the main cylinder body + cylinderGroup + .append('path') + .attr('d', d) + .attr('fill', '#eaeaea') + .attr('stroke', '#000') + .attr('stroke-width', 1) + .attr('class', cssclass); + + if (!isFooter) { + cylinderGroup.attr('transform', `translate(${w * 1.5}, ${(rect.height + ry) / 4})`); + } else { + cylinderGroup.attr('transform', `translate(${w * 1.5}, ${rect.height / 4 - 2 * ry})`); + } + actor.rectData = rect; + _drawTextCandidateFunc(conf, hasKatex(actor.description))( + actor.description, + g, + rect.x, + rect.y + (!isFooter ? (rect.height + ry) / 2 : (rect.height + h) / 4), + rect.width, + rect.height, + { class: `actor ${ACTOR_BOX_CLASS}` }, + conf + ); + + const lastPath = cylinderGroup.select('path:last-child'); + if (lastPath.node()) { + const bounds = lastPath.node().getBBox(); + actor.height = bounds.height + (conf.sequence.labelBoxHeight ?? 0); + } + + return actor.height; +}; + +const drawActorTypeBoundary = function (elem, actor, conf, isFooter) { + const actorY = isFooter ? actor.stopy : actor.starty; + const center = actor.x + actor.width / 2; + const centerY = actorY + 80; + const radius = 30; + const line = elem.append('g').lower(); + + if (!isFooter) { + actorCnt++; + line + .append('line') + .attr('id', 'actor' + actorCnt) + .attr('x1', center) + .attr('y1', centerY) + .attr('x2', center) + .attr('y2', 2000) + .attr('class', 'actor-line 200') + .attr('stroke-width', '0.5px') + .attr('stroke', '#999') + .attr('name', actor.name); + + actor.actorCnt = actorCnt; + } + const actElem = elem.append('g'); + let cssClass = ACTOR_MAN_FIGURE_CLASS; + if (isFooter) { + cssClass += ` ${BOTTOM_ACTOR_CLASS}`; + } else { + cssClass += ` ${TOP_ACTOR_CLASS}`; + } + actElem.attr('class', cssClass); + actElem.attr('name', actor.name); + + const rect = svgDrawCommon.getNoteRect(); + rect.x = actor.x; + rect.y = actorY; + rect.fill = '#eaeaea'; + rect.width = actor.width; + rect.height = actor.height; + rect.class = 'actor'; + + actElem + .append('line') + .attr('id', 'actor-man-torso' + actorCnt) + .attr('x1', actor.x + actor.width / 2 - radius * 2.5) + .attr('y1', actorY + 10) + .attr('x2', actor.x + actor.width / 2 - 15) + .attr('y2', actorY + 10); + + actElem + .append('line') + .attr('id', 'actor-man-arms' + actorCnt) + .attr('x1', actor.x + actor.width / 2 - radius * 2.5) + .attr('y1', actorY + 0) // starting Y + .attr('x2', actor.x + actor.width / 2 - radius * 2.5) + .attr('y2', actorY + 20); // ending Y (26px long, adjust as needed) + + actElem + .append('circle') + .attr('cx', actor.x + actor.width / 2) + .attr('cy', actorY + 10) + .attr('r', radius); + + const bounds = actElem.node().getBBox(); + actor.height = bounds.height + (conf.sequence.labelBoxHeight ?? 0); + + _drawTextCandidateFunc(conf, hasKatex(actor.description))( + actor.description, + actElem, + rect.x, + rect.y + (!isFooter ? radius / 2 + 3 : radius / 2 - 4), + rect.width, + rect.height, + { class: `actor ${ACTOR_MAN_FIGURE_CLASS}` }, + conf + ); + + if (!isFooter) { + actElem.attr('transform', `translate(0,${radius / 2 + 7})`); + } else { + actElem.attr('transform', `translate(0,${radius / 2 + 7})`); + } + + return actor.height; +}; + const drawActorTypeActor = function (elem, actor, conf, isFooter) { const actorY = isFooter ? actor.stopy : actor.starty; const center = actor.x + actor.width / 2; @@ -512,6 +1110,18 @@ export const drawActor = async function (elem, actor, conf, isFooter) { return await drawActorTypeActor(elem, actor, conf, isFooter); case 'participant': return await drawActorTypeParticipant(elem, actor, conf, isFooter); + case 'boundary': + return await drawActorTypeBoundary(elem, actor, conf, isFooter); + case 'control': + return await drawActorTypeControl(elem, actor, conf, isFooter); + case 'entity': + return await drawActorTypeEntity(elem, actor, conf, isFooter); + case 'database': + return await drawActorTypeDatabase(elem, actor, conf, isFooter); + case 'collections': + return await drawActorTypeCollections(elem, actor, conf, isFooter); + case 'queue': + return await drawActorTypeQueue(elem, actor, conf, isFooter); } }; @@ -965,7 +1575,7 @@ const _drawTextCandidateFunc = (function () { .append('div') .style('text-align', 'center') .style('vertical-align', 'middle') - .html(await renderKatex(content, configApi.getConfig())); + .html(await renderKatexSanitized(content, configApi.getConfig())); byTspan(content, s, x, y, width, height, textAttrs, conf); _setTextAttrs(text, textAttrs); diff --git a/packages/mermaid/src/diagrams/xychart/parser/xychart.jison b/packages/mermaid/src/diagrams/xychart/parser/xychart.jison index 987132d17..33575b946 100644 --- a/packages/mermaid/src/diagrams/xychart/parser/xychart.jison +++ b/packages/mermaid/src/diagrams/xychart/parser/xychart.jison @@ -30,6 +30,7 @@ [^\}]* { return "acc_descr_multiline_value"; } "xychart-beta" {return 'XYCHART';} +"xychart" {return 'XYCHART';} (?:"vertical"|"horizontal") {return 'CHART_ORIENTATION'} "x-axis" { this.pushState("axis_data"); return "X_AXIS"; } diff --git a/packages/mermaid/src/diagrams/xychart/parser/xychart.jison.spec.ts b/packages/mermaid/src/diagrams/xychart/parser/xychart.jison.spec.ts index d7de15f66..409972828 100644 --- a/packages/mermaid/src/diagrams/xychart/parser/xychart.jison.spec.ts +++ b/packages/mermaid/src/diagrams/xychart/parser/xychart.jison.spec.ts @@ -33,44 +33,44 @@ describe('Testing xychart jison file', () => { clearMocks(); }); - it('should throw error if xychart-beta text is not there', () => { - const str = 'xychart-beta-1'; + it('should throw error if xychart text is not there', () => { + const str = 'xychart-1'; expect(parserFnConstructor(str)).toThrow(); }); it('should not throw error if only xychart is there', () => { - const str = 'xychart-beta'; + const str = 'xychart'; expect(parserFnConstructor(str)).not.toThrow(); }); it('parse title of the chart within "', () => { - const str = 'xychart-beta \n title "This is a title"'; + const str = 'xychart \n title "This is a title"'; expect(parserFnConstructor(str)).not.toThrow(); expect(mockDB.setDiagramTitle).toHaveBeenCalledWith('This is a title'); }); it('parse title of the chart without "', () => { - const str = 'xychart-beta \n title oneLinertitle'; + const str = 'xychart \n title oneLinertitle'; expect(parserFnConstructor(str)).not.toThrow(); expect(mockDB.setDiagramTitle).toHaveBeenCalledWith('oneLinertitle'); }); it('parse chart orientation', () => { - const str = 'xychart-beta vertical'; + const str = 'xychart vertical'; expect(parserFnConstructor(str)).not.toThrow(); expect(mockDB.setOrientation).toHaveBeenCalledWith('vertical'); }); it('parse chart orientation with spaces', () => { - let str = 'xychart-beta horizontal '; + let str = 'xychart horizontal '; expect(parserFnConstructor(str)).not.toThrow(); expect(mockDB.setOrientation).toHaveBeenCalledWith('horizontal'); - str = 'xychart-beta abc'; + str = 'xychart abc'; expect(parserFnConstructor(str)).toThrow(); }); it('parse x-axis', () => { - const str = 'xychart-beta \nx-axis xAxisName\n'; + const str = 'xychart \nx-axis xAxisName\n'; expect(parserFnConstructor(str)).not.toThrow(); expect(mockDB.setXAxisTitle).toHaveBeenCalledWith({ text: 'xAxisName', @@ -79,7 +79,7 @@ describe('Testing xychart jison file', () => { }); it('parse x-axis with axis name without "', () => { - const str = 'xychart-beta \nx-axis xAxisName \n'; + const str = 'xychart \nx-axis xAxisName \n'; expect(parserFnConstructor(str)).not.toThrow(); expect(mockDB.setXAxisTitle).toHaveBeenCalledWith({ text: 'xAxisName', @@ -88,7 +88,7 @@ describe('Testing xychart jison file', () => { }); it('parse x-axis with axis name with "', () => { - const str = 'xychart-beta \n x-axis "xAxisName has space"\n'; + const str = 'xychart \n x-axis "xAxisName has space"\n'; expect(parserFnConstructor(str)).not.toThrow(); expect(mockDB.setXAxisTitle).toHaveBeenCalledWith({ text: 'xAxisName has space', @@ -97,7 +97,7 @@ describe('Testing xychart jison file', () => { }); it('parse x-axis with axis name with " with spaces', () => { - const str = 'xychart-beta \n x-axis " xAxisName has space " \n'; + const str = 'xychart \n x-axis " xAxisName has space " \n'; expect(parserFnConstructor(str)).not.toThrow(); expect(mockDB.setXAxisTitle).toHaveBeenCalledWith({ text: ' xAxisName has space ', @@ -106,7 +106,7 @@ describe('Testing xychart jison file', () => { }); it('parse x-axis with axis name and range data', () => { - const str = 'xychart-beta \nx-axis xAxisName 45.5 --> 33 \n'; + const str = 'xychart \nx-axis xAxisName 45.5 --> 33 \n'; expect(parserFnConstructor(str)).not.toThrow(); expect(mockDB.setXAxisTitle).toHaveBeenCalledWith({ text: 'xAxisName', @@ -115,11 +115,11 @@ describe('Testing xychart jison file', () => { expect(mockDB.setXAxisRangeData).toHaveBeenCalledWith(45.5, 33); }); it('parse x-axis throw error for invalid range data', () => { - const str = 'xychart-beta \nx-axis xAxisName aaa --> 33 \n'; + const str = 'xychart \nx-axis xAxisName aaa --> 33 \n'; expect(parserFnConstructor(str)).toThrow(); }); it('parse x-axis with axis name and range data with only decimal part', () => { - const str = 'xychart-beta \nx-axis xAxisName 45.5 --> .34 \n'; + const str = 'xychart \nx-axis xAxisName 45.5 --> .34 \n'; expect(parserFnConstructor(str)).not.toThrow(); expect(mockDB.setXAxisTitle).toHaveBeenCalledWith({ text: 'xAxisName', @@ -129,7 +129,7 @@ describe('Testing xychart jison file', () => { }); it('parse x-axis without axis name and range data', () => { - const str = 'xychart-beta \nx-axis 45.5 --> 1.34 \n'; + const str = 'xychart \nx-axis 45.5 --> 1.34 \n'; expect(parserFnConstructor(str)).not.toThrow(); expect(mockDB.setXAxisTitle).toHaveBeenCalledWith({ text: '', @@ -139,7 +139,7 @@ describe('Testing xychart jison file', () => { }); it('parse x-axis with axis name and category data', () => { - const str = 'xychart-beta \nx-axis xAxisName [ "cat1" , cat2a ] \n '; + const str = 'xychart \nx-axis xAxisName [ "cat1" , cat2a ] \n '; expect(parserFnConstructor(str)).not.toThrow(); expect(mockDB.setXAxisTitle).toHaveBeenCalledWith({ text: 'xAxisName', @@ -155,7 +155,7 @@ describe('Testing xychart jison file', () => { }); it('parse x-axis without axis name and category data', () => { - const str = 'xychart-beta \nx-axis [ "cat1" , cat2a ] \n '; + const str = 'xychart \nx-axis [ "cat1" , cat2a ] \n '; expect(parserFnConstructor(str)).not.toThrow(); expect(mockDB.setXAxisTitle).toHaveBeenCalledWith({ text: '', @@ -171,14 +171,14 @@ describe('Testing xychart jison file', () => { }); it('parse x-axis throw error if unbalanced bracket', () => { - let str = 'xychart-beta \nx-axis xAxisName [ "cat1" [ cat2a ] \n '; + let str = 'xychart \nx-axis xAxisName [ "cat1" [ cat2a ] \n '; expect(parserFnConstructor(str)).toThrow(); - str = 'xychart-beta \nx-axis xAxisName [ "cat1" , cat2a ] ] \n '; + str = 'xychart \nx-axis xAxisName [ "cat1" , cat2a ] ] \n '; expect(parserFnConstructor(str)).toThrow(); }); it('parse x-axis complete variant 1', () => { - const str = `xychart-beta \n x-axis "this is x axis" [category1, "category 2", category3]\n`; + const str = `xychart \n x-axis "this is x axis" [category1, "category 2", category3]\n`; expect(parserFnConstructor(str)).not.toThrow(); expect(mockDB.setXAxisTitle).toHaveBeenCalledWith({ text: 'this is x axis', type: 'text' }); expect(mockDB.setXAxisBand).toHaveBeenCalledWith([ @@ -189,8 +189,7 @@ describe('Testing xychart jison file', () => { }); it('parse x-axis complete variant 2', () => { - const str = - 'xychart-beta \nx-axis xAxisName [ "cat1 with space" , cat2 , cat3] \n '; + const str = 'xychart \nx-axis xAxisName [ "cat1 with space" , cat2 , cat3] \n '; expect(parserFnConstructor(str)).not.toThrow(); expect(mockDB.setXAxisTitle).toHaveBeenCalledWith({ text: 'xAxisName', type: 'text' }); expect(mockDB.setXAxisBand).toHaveBeenCalledWith([ @@ -202,7 +201,7 @@ describe('Testing xychart jison file', () => { it('parse x-axis complete variant 3', () => { const str = - 'xychart-beta \nx-axis xAxisName [ "cat1 with space" , cat2 asdf , cat3] \n '; + 'xychart \nx-axis xAxisName [ "cat1 with space" , cat2 asdf , cat3] \n '; expect(parserFnConstructor(str)).not.toThrow(); expect(mockDB.setXAxisTitle).toHaveBeenCalledWith({ text: 'xAxisName', type: 'text' }); expect(mockDB.setXAxisBand).toHaveBeenCalledWith([ @@ -213,17 +212,17 @@ describe('Testing xychart jison file', () => { }); it('parse y-axis with axis name', () => { - const str = 'xychart-beta \ny-axis yAxisName\n'; + const str = 'xychart \ny-axis yAxisName\n'; expect(parserFnConstructor(str)).not.toThrow(); expect(mockDB.setYAxisTitle).toHaveBeenCalledWith({ text: 'yAxisName', type: 'text' }); }); it('parse y-axis with axis name with spaces', () => { - const str = 'xychart-beta \ny-axis yAxisName \n'; + const str = 'xychart \ny-axis yAxisName \n'; expect(parserFnConstructor(str)).not.toThrow(); expect(mockDB.setYAxisTitle).toHaveBeenCalledWith({ text: 'yAxisName', type: 'text' }); }); it('parse y-axis with axis name with "', () => { - const str = 'xychart-beta \n y-axis "yAxisName has space"\n'; + const str = 'xychart \n y-axis "yAxisName has space"\n'; expect(parserFnConstructor(str)).not.toThrow(); expect(mockDB.setYAxisTitle).toHaveBeenCalledWith({ text: 'yAxisName has space', @@ -231,7 +230,7 @@ describe('Testing xychart jison file', () => { }); }); it('parse y-axis with axis name with " and spaces', () => { - const str = 'xychart-beta \n y-axis " yAxisName has space " \n'; + const str = 'xychart \n y-axis " yAxisName has space " \n'; expect(parserFnConstructor(str)).not.toThrow(); expect(mockDB.setYAxisTitle).toHaveBeenCalledWith({ text: ' yAxisName has space ', @@ -239,39 +238,39 @@ describe('Testing xychart jison file', () => { }); }); it('parse y-axis with axis name with range data', () => { - const str = 'xychart-beta \ny-axis yAxisName 45.5 --> 33 \n'; + const str = 'xychart \ny-axis yAxisName 45.5 --> 33 \n'; expect(parserFnConstructor(str)).not.toThrow(); expect(mockDB.setYAxisTitle).toHaveBeenCalledWith({ text: 'yAxisName', type: 'text' }); expect(mockDB.setYAxisRangeData).toHaveBeenCalledWith(45.5, 33); }); it('parse y-axis without axis name with range data', () => { - const str = 'xychart-beta \ny-axis 45.5 --> 33 \n'; + const str = 'xychart \ny-axis 45.5 --> 33 \n'; expect(parserFnConstructor(str)).not.toThrow(); expect(mockDB.setYAxisTitle).toHaveBeenCalledWith({ text: '', type: 'text' }); expect(mockDB.setYAxisRangeData).toHaveBeenCalledWith(45.5, 33); }); it('parse y-axis with axis name with range data with only decimal part', () => { - const str = 'xychart-beta \ny-axis yAxisName 45.5 --> .33 \n'; + const str = 'xychart \ny-axis yAxisName 45.5 --> .33 \n'; expect(parserFnConstructor(str)).not.toThrow(); expect(mockDB.setYAxisTitle).toHaveBeenCalledWith({ text: 'yAxisName', type: 'text' }); expect(mockDB.setYAxisRangeData).toHaveBeenCalledWith(45.5, 0.33); }); it('parse y-axis throw error for invalid number in range data', () => { - const str = 'xychart-beta \ny-axis yAxisName 45.5 --> abc \n'; + const str = 'xychart \ny-axis yAxisName 45.5 --> abc \n'; expect(parserFnConstructor(str)).toThrow(); }); it('parse y-axis throws error if range data is passed', () => { - const str = 'xychart-beta \ny-axis yAxisName [ 45.3, 33 ] \n'; + const str = 'xychart \ny-axis yAxisName [ 45.3, 33 ] \n'; expect(parserFnConstructor(str)).toThrow(); }); it('parse both axis at once', () => { - const str = 'xychart-beta\nx-axis xAxisName\ny-axis yAxisName\n'; + const str = 'xychart\nx-axis xAxisName\ny-axis yAxisName\n'; expect(parserFnConstructor(str)).not.toThrow(); expect(mockDB.setXAxisTitle).toHaveBeenCalledWith({ text: 'xAxisName', type: 'text' }); expect(mockDB.setYAxisTitle).toHaveBeenCalledWith({ text: 'yAxisName', type: 'text' }); }); it('parse line Data', () => { - const str = 'xychart-beta\nx-axis xAxisName\ny-axis yAxisName\n line lineTitle [23, 45, 56.6]'; + const str = 'xychart\nx-axis xAxisName\ny-axis yAxisName\n line lineTitle [23, 45, 56.6]'; expect(parserFnConstructor(str)).not.toThrow(); expect(mockDB.setLineData).toHaveBeenCalledWith( { text: 'lineTitle', type: 'text' }, @@ -282,7 +281,7 @@ describe('Testing xychart jison file', () => { }); it('parse line Data with spaces and +,- symbols', () => { const str = - 'xychart-beta\nx-axis xAxisName\ny-axis yAxisName\n line "lineTitle with space" [ +23 , -45 , 56.6 ] '; + 'xychart\nx-axis xAxisName\ny-axis yAxisName\n line "lineTitle with space" [ +23 , -45 , 56.6 ] '; expect(parserFnConstructor(str)).not.toThrow(); expect(mockDB.setYAxisTitle).toHaveBeenCalledWith({ text: 'yAxisName', type: 'text' }); expect(mockDB.setXAxisTitle).toHaveBeenCalledWith({ text: 'xAxisName', type: 'text' }); @@ -292,8 +291,7 @@ describe('Testing xychart jison file', () => { ); }); it('parse line Data without title', () => { - const str = - 'xychart-beta\nx-axis xAxisName\ny-axis yAxisName\n line [ +23 , -45 , 56.6 , .33] '; + const str = 'xychart\nx-axis xAxisName\ny-axis yAxisName\n line [ +23 , -45 , 56.6 , .33] '; expect(parserFnConstructor(str)).not.toThrow(); expect(mockDB.setYAxisTitle).toHaveBeenCalledWith({ text: 'yAxisName', type: 'text' }); expect(mockDB.setXAxisTitle).toHaveBeenCalledWith({ text: 'xAxisName', type: 'text' }); @@ -304,34 +302,32 @@ describe('Testing xychart jison file', () => { }); it('parse line Data throws error unbalanced brackets', () => { let str = - 'xychart-beta\nx-axis xAxisName\ny-axis yAxisName\n line "lineTitle with space" [ +23 [ -45 , 56.6 ] '; + 'xychart\nx-axis xAxisName\ny-axis yAxisName\n line "lineTitle with space" [ +23 [ -45 , 56.6 ] '; expect(parserFnConstructor(str)).toThrow(); str = - 'xychart-beta\nx-axis xAxisName\ny-axis yAxisName\n line "lineTitle with space" [ +23 , -45 ] 56.6 ] '; + 'xychart\nx-axis xAxisName\ny-axis yAxisName\n line "lineTitle with space" [ +23 , -45 ] 56.6 ] '; expect(parserFnConstructor(str)).toThrow(); }); it('parse line Data throws error if data is not provided', () => { - const str = 'xychart-beta\nx-axis xAxisName\ny-axis yAxisName\n line "lineTitle with space" '; + const str = 'xychart\nx-axis xAxisName\ny-axis yAxisName\n line "lineTitle with space" '; expect(parserFnConstructor(str)).toThrow(); }); it('parse line Data throws error if data is empty', () => { - const str = - 'xychart-beta\nx-axis xAxisName\ny-axis yAxisName\n line "lineTitle with space" [ ] '; + const str = 'xychart\nx-axis xAxisName\ny-axis yAxisName\n line "lineTitle with space" [ ] '; expect(parserFnConstructor(str)).toThrow(); }); it('parse line Data throws error if , is not in proper', () => { const str = - 'xychart-beta\nx-axis xAxisName\ny-axis yAxisName\n line "lineTitle with space" [ +23 , , -45 , 56.6 ] '; + 'xychart\nx-axis xAxisName\ny-axis yAxisName\n line "lineTitle with space" [ +23 , , -45 , 56.6 ] '; expect(parserFnConstructor(str)).toThrow(); }); it('parse line Data throws error if not number', () => { const str = - 'xychart-beta\nx-axis xAxisName\ny-axis yAxisName\n line "lineTitle with space" [ +23 , -4aa5 , 56.6 ] '; + 'xychart\nx-axis xAxisName\ny-axis yAxisName\n line "lineTitle with space" [ +23 , -4aa5 , 56.6 ] '; expect(parserFnConstructor(str)).toThrow(); }); it('parse bar Data', () => { - const str = - 'xychart-beta\nx-axis xAxisName\ny-axis yAxisName\n bar barTitle [23, 45, 56.6, .22]'; + const str = 'xychart\nx-axis xAxisName\ny-axis yAxisName\n bar barTitle [23, 45, 56.6, .22]'; expect(parserFnConstructor(str)).not.toThrow(); expect(mockDB.setYAxisTitle).toHaveBeenCalledWith({ text: 'yAxisName', type: 'text' }); expect(mockDB.setXAxisTitle).toHaveBeenCalledWith({ text: 'xAxisName', type: 'text' }); @@ -342,7 +338,7 @@ describe('Testing xychart jison file', () => { }); it('parse bar Data spaces and +,- symbol', () => { const str = - 'xychart-beta\nx-axis xAxisName\ny-axis yAxisName\n bar "barTitle with space" [ +23 , -45 , 56.6 ] '; + 'xychart\nx-axis xAxisName\ny-axis yAxisName\n bar "barTitle with space" [ +23 , -45 , 56.6 ] '; expect(parserFnConstructor(str)).not.toThrow(); expect(mockDB.setYAxisTitle).toHaveBeenCalledWith({ text: 'yAxisName', type: 'text' }); expect(mockDB.setXAxisTitle).toHaveBeenCalledWith({ text: 'xAxisName', type: 'text' }); @@ -352,8 +348,7 @@ describe('Testing xychart jison file', () => { ); }); it('parse bar Data without plot title', () => { - const str = - 'xychart-beta\nx-axis xAxisName\ny-axis yAxisName\n bar [ +23 , -45 , 56.6 ] '; + const str = 'xychart\nx-axis xAxisName\ny-axis yAxisName\n bar [ +23 , -45 , 56.6 ] '; expect(parserFnConstructor(str)).not.toThrow(); expect(mockDB.setYAxisTitle).toHaveBeenCalledWith({ text: 'yAxisName', type: 'text' }); expect(mockDB.setXAxisTitle).toHaveBeenCalledWith({ text: 'xAxisName', type: 'text' }); @@ -361,34 +356,34 @@ describe('Testing xychart jison file', () => { }); it('parse bar should throw for unbalanced brackets', () => { let str = - 'xychart-beta\nx-axis xAxisName\ny-axis yAxisName\n bar "barTitle with space" [ +23 [ -45 , 56.6 ] '; + 'xychart\nx-axis xAxisName\ny-axis yAxisName\n bar "barTitle with space" [ +23 [ -45 , 56.6 ] '; expect(parserFnConstructor(str)).toThrow(); str = - 'xychart-beta\nx-axis xAxisName\ny-axis yAxisName\n bar "barTitle with space" [ +23 , -45 ] 56.6 ] '; + 'xychart\nx-axis xAxisName\ny-axis yAxisName\n bar "barTitle with space" [ +23 , -45 ] 56.6 ] '; expect(parserFnConstructor(str)).toThrow(); }); it('parse bar should throw error if data is not provided', () => { - const str = 'xychart-beta\nx-axis xAxisName\ny-axis yAxisName\n bar "barTitle with space" '; + const str = 'xychart\nx-axis xAxisName\ny-axis yAxisName\n bar "barTitle with space" '; expect(parserFnConstructor(str)).toThrow(); }); it('parse bar should throw error if data is empty', () => { const str = - 'xychart-beta\nx-axis xAxisName\ny-axis yAxisName\n bar "barTitle with space" [ ] '; + 'xychart\nx-axis xAxisName\ny-axis yAxisName\n bar "barTitle with space" [ ] '; expect(parserFnConstructor(str)).toThrow(); }); it('parse bar should throw error if comma is not proper', () => { const str = - 'xychart-beta\nx-axis xAxisName\ny-axis yAxisName\n bar "barTitle with space" [ +23 , , -45 , 56.6 ] '; + 'xychart\nx-axis xAxisName\ny-axis yAxisName\n bar "barTitle with space" [ +23 , , -45 , 56.6 ] '; expect(parserFnConstructor(str)).toThrow(); }); it('parse bar should throw error if number is not passed', () => { const str = - 'xychart-beta\nx-axis xAxisName\ny-axis yAxisName\n bar "barTitle with space" [ +23 , -4aa5 , 56.6 ] '; + 'xychart\nx-axis xAxisName\ny-axis yAxisName\n bar "barTitle with space" [ +23 , -4aa5 , 56.6 ] '; expect(parserFnConstructor(str)).toThrow(); }); it('parse multiple bar and line variant 1', () => { const str = - 'xychart-beta\nx-axis xAxisName\ny-axis yAxisName\n bar barTitle1 [23, 45, 56.6] \n line lineTitle1 [11, 45.5, 67, 23] \n bar barTitle2 [13, 42, 56.89] \n line lineTitle2 [45, 99, 012]'; + 'xychart\nx-axis xAxisName\ny-axis yAxisName\n bar barTitle1 [23, 45, 56.6] \n line lineTitle1 [11, 45.5, 67, 23] \n bar barTitle2 [13, 42, 56.89] \n line lineTitle2 [45, 99, 012]'; expect(parserFnConstructor(str)).not.toThrow(); expect(mockDB.setYAxisTitle).toHaveBeenCalledWith({ text: 'yAxisName', type: 'text' }); expect(mockDB.setXAxisTitle).toHaveBeenCalledWith({ text: 'xAxisName', type: 'text' }); @@ -411,8 +406,8 @@ describe('Testing xychart jison file', () => { }); it('parse multiple bar and line variant 2', () => { const str = ` - xychart-beta horizontal - title Basic xychart + xychart horizontal + title "Basic xychart" x-axis "this is x axis" [category1, "category 2", category3] y-axis yaxisText 10 --> 150 bar barTitle1 [23, 45, 56.6] diff --git a/packages/mermaid/src/diagrams/xychart/xychartDetector.ts b/packages/mermaid/src/diagrams/xychart/xychartDetector.ts index 08be05b01..3a848cd7f 100644 --- a/packages/mermaid/src/diagrams/xychart/xychartDetector.ts +++ b/packages/mermaid/src/diagrams/xychart/xychartDetector.ts @@ -7,7 +7,7 @@ import type { const id = 'xychart'; const detector: DiagramDetector = (txt) => { - return /^\s*xychart-beta/.test(txt); + return /^\s*xychart(-beta)?/.test(txt); }; const loader: DiagramLoader = async () => { diff --git a/packages/mermaid/src/docs/.vitepress/components/EditorSelectionModal.vue b/packages/mermaid/src/docs/.vitepress/components/EditorSelectionModal.vue index e41a7096d..2334d446f 100644 --- a/packages/mermaid/src/docs/.vitepress/components/EditorSelectionModal.vue +++ b/packages/mermaid/src/docs/.vitepress/components/EditorSelectionModal.vue @@ -9,56 +9,136 @@ interface Feature { interface EditorColumn { title: string; description: string; - redirectUrl: string; + redBarText?: string; + redirectUrl?: string; + buttonText?: string; highlighted?: boolean; + proTrialUrl?: string; + proTrialButtonText?: string; features: Feature[]; + isButtonMargined?: boolean; } -const editorColumns: EditorColumn[] = [ - { - title: 'Playground', - description: 'Basic features, no login', - redirectUrl: - 'https://www.mermaidchart.com/play?utm_source=mermaid_js&utm_medium=editor_selection&utm_campaign=playground', - features: [ - { iconUrl: '/icons/public.svg', featureName: 'Diagram stored in URL' }, - { iconUrl: '/icons/terminal.svg', featureName: 'Code editor' }, - { iconUrl: '/icons/whiteboard.svg', featureName: 'Whiteboard' }, - ], - }, - { - title: 'Free', - description: 'Advanced features, free account', - redirectUrl: - 'https://www.mermaidchart.com/app/sign-up?utm_source=mermaid_js&utm_medium=editor_selection&utm_campaign=mermaid_chart&redirect=%2Fapp%2Fdiagrams%2Fnew', - highlighted: true, - features: [ - { iconUrl: '/icons/folder.svg', featureName: 'Storage' }, - { iconUrl: '/icons/terminal.svg', featureName: 'Code editor' }, - { iconUrl: '/icons/ai-diagram.svg', featureName: 'AI diagram generator' }, - { iconUrl: '/icons/whiteboard.svg', featureName: 'Whiteboard' }, - { iconUrl: '/icons/group.svg', featureName: 'Teams' }, - { iconUrl: '/icons/groups.svg', featureName: 'Multi-user editing' }, - { iconUrl: '/icons/ai-repair.svg', featureName: 'AI diagram repair' }, - { iconUrl: '/icons/version-history.svg', featureName: 'Version history' }, - { iconUrl: '/icons/comment.svg', featureName: 'Comments' }, - { iconUrl: '/icons/presentation.svg', featureName: 'Presentations' }, - { iconUrl: '/icons/plugins.svg', featureName: 'Advanced Plugins' }, - ], - }, - { - title: 'Open Source', - description: 'Code only, no login', - redirectUrl: 'https://mermaid.live/edit', - features: [ - { iconUrl: '/icons/public.svg', featureName: 'Diagram stored in URL' }, - { iconUrl: '/icons/terminal.svg', featureName: 'Code editor' }, - { iconUrl: '/icons/open-source.svg', featureName: 'Open source' }, - { iconUrl: '/icons/version-history.svg', featureName: 'Version history' }, - ], - }, +const mermaidChartFeatures: Feature[] = [ + { iconUrl: '/icons/folder.svg', featureName: 'Storage' }, + { iconUrl: '/icons/terminal.svg', featureName: 'Code editor' }, + { iconUrl: '/icons/ai-diagram.svg', featureName: 'AI diagram generator' }, + { iconUrl: '/icons/whiteboard.svg', featureName: 'Whiteboard' }, + { iconUrl: '/icons/group.svg', featureName: 'Teams' }, + { iconUrl: '/icons/groups.svg', featureName: 'Multi-user editing' }, + { iconUrl: '/icons/ai-repair.svg', featureName: 'AI diagram repair' }, + { iconUrl: '/icons/version-history.svg', featureName: 'Version history' }, + { iconUrl: '/icons/comment.svg', featureName: 'Comments' }, + { iconUrl: '/icons/presentation.svg', featureName: 'Presentations' }, + { iconUrl: '/icons/plugins.svg', featureName: 'Advanced plugins' }, ]; +const openSourceFeatures: Feature[] = [ + { iconUrl: '/icons/public.svg', featureName: 'Diagram stored in URL' }, + { iconUrl: '/icons/terminal.svg', featureName: 'Code editor' }, + { iconUrl: '/icons/open-source.svg', featureName: 'Open source' }, + { iconUrl: '/icons/version-history.svg', featureName: 'Version history' }, +]; + +const playgroundFeatures: Feature[] = [ + { iconUrl: '/icons/public.svg', featureName: 'Diagram stored in URL' }, + { iconUrl: '/icons/terminal.svg', featureName: 'Code editor' }, + { iconUrl: '/icons/whiteboard.svg', featureName: 'Whiteboard' }, +]; + +const editorColumnVariants: EditorColumn[][] = [ + [ + { + title: 'Playground', + description: 'Basic features, no login', + redirectUrl: + 'https://www.mermaidchart.com/app/sign-up?utm_source=mermaid_js&utm_medium=3_editor_selection_A&utm_campaign=start_playground', + buttonText: 'Start free', + features: playgroundFeatures, + }, + { + title: 'Free or Pro', + description: 'Advanced features, Free or Pro account', + proTrialUrl: + 'https://www.mermaidchart.com/app/sign-up?utm_source=mermaid_js&utm_medium=3_editor_selection_A&utm_campaign=start_free', + proTrialButtonText: 'Start free', + highlighted: true, + redBarText: 'Best for collaboration', + features: mermaidChartFeatures, + }, + { + title: 'Open Source', + description: 'Code only, no login', + redirectUrl: 'https://mermaid.live/edit', + buttonText: 'Start free', + features: openSourceFeatures, + }, + ], + [ + { + title: 'Mermaid Pro', + description: 'Unlock AI and real-time collaboration', + redirectUrl: + 'https://www.mermaidchart.com/app/sign-up?utm_source=mermaid_js&utm_medium=editor_selection_B&utm_campaign=start_free', + buttonText: 'Start Free', + highlighted: true, + redBarText: 'Recommended', + proTrialButtonText: 'Start Pro trial', + proTrialUrl: + 'https://www.mermaidchart.com/app/sign-up?utm_source=mermaid_js&utm_medium=editor_selection_B&utm_campaign=start_trial&redirect=%2Fapp%2Fuser%2Fbilling%2Fcheckout%3FisFromMermaid%3Dtrue', + features: mermaidChartFeatures, + }, + { + title: 'Open Source', + description: 'Code only, no login', + buttonText: 'Start free', + redirectUrl: 'https://mermaid.live/edit', + isButtonMargined: true, + features: openSourceFeatures, + }, + ], + [ + { + title: 'Mermaid Pro', + description: 'Unlock AI and real-time collaboration', + highlighted: true, + redBarText: 'Recommended', + proTrialButtonText: 'Start free trial', + proTrialUrl: + 'https://www.mermaidchart.com/app/sign-up?utm_source=mermaid_js&utm_medium=editor_selection_C&utm_campaign=start_trial&redirect=%2Fapp%2Fuser%2Fbilling%2Fcheckout%3FisFromMermaid%3Dtrue', + features: mermaidChartFeatures, + }, + { + title: 'Open Source', + description: 'Code only, no login', + buttonText: 'Start free', + redirectUrl: 'https://mermaid.live/edit', + features: openSourceFeatures, + }, + ], + [ + { + title: 'Mermaid Pro', + description: 'Unlock AI and real-time collaboration', + highlighted: true, + redBarText: 'Recommended', + proTrialButtonText: 'Start free', + proTrialUrl: + 'https://www.mermaidchart.com/app/sign-up?utm_source=mermaid_js&utm_medium=editor_selection_D&utm_campaign=start_free', + features: mermaidChartFeatures, + }, + { + title: 'Open Source', + description: 'Code only, no login', + redirectUrl: 'https://mermaid.live/edit', + buttonText: 'Start free', + features: openSourceFeatures, + }, + ], +]; + +const editorColumns = editorColumnVariants[Math.floor(Math.random() * editorColumnVariants.length)]; + const isVisible = ref(false); const handleMouseDown = (e: MouseEvent) => { @@ -84,44 +164,53 @@ onUnmounted(() => {