collab/mermaid/packages/mermaid-layout-tidy-tree/README.mdblame
View source
6dd74de1# @mermaid-js/layout-tidy-tree
6dd74de2
6dd74de3This package provides a bidirectional tidy tree layout engine for Mermaid based on the non-layered-tidy-tree-layout algorithm.
6dd74de4
6dd74de5> [!NOTE]
6dd74de6> The Tidy Tree Layout engine will not be available in all providers that support mermaid by default.
6dd74de7> The websites will have to install the @mermaid-js/layout-tidy-tree package to use the Tidy Tree layout engine.
6dd74de8
6dd74de9## Usage
6dd74de10
6dd74de11```
6dd74de12---
6dd74de13config:
6dd74de14 layout: tidy-tree
6dd74de15---
6dd74de16mindmap
6dd74de17root((mindmap))
6dd74de18 A
6dd74de19 B
6dd74de20```
6dd74de21
6dd74de22### With bundlers
6dd74de23
6dd74de24```sh
6dd74de25npm install @mermaid-js/layout-tidy-tree
6dd74de26```
6dd74de27
6dd74de28```ts
6dd74de29import mermaid from 'mermaid';
6dd74de30import tidyTreeLayouts from '@mermaid-js/layout-tidy-tree';
6dd74de31
6dd74de32mermaid.registerLayoutLoaders(tidyTreeLayouts);
6dd74de33```
6dd74de34
6dd74de35### With CDN
6dd74de36
6dd74de37```html
6dd74de38<script type="module">
6dd74de39 import mermaid from 'https://cdn.jsdelivr.net/npm/mermaid@11/dist/mermaid.esm.min.mjs';
6dd74de40 import tidyTreeLayouts from 'https://cdn.jsdelivr.net/npm/@mermaid-js/layout-tidy-tree@0/dist/mermaid-layout-tidy-tree.esm.min.mjs';
6dd74de41
6dd74de42 mermaid.registerLayoutLoaders(tidyTreeLayouts);
6dd74de43</script>
6dd74de44```
6dd74de45
6dd74de46## Tidy Tree Layout Overview
6dd74de47
6dd74de48tidy-tree: The bidirectional tidy tree layout
6dd74de49
6dd74de50The bidirectional tidy tree layout algorithm creates two separate trees that grow horizontally in opposite directions from a central root node:
6dd74de51Left tree: grows horizontally to the left (children alternate: 1st, 3rd, 5th...)
6dd74de52Right tree: grows horizontally to the right (children alternate: 2nd, 4th, 6th...)
6dd74de53
6dd74de54This creates a balanced, symmetric layout that is ideal for mindmaps, organizational charts, and other tree-based diagrams.
6dd74de55
6dd74de56Layout Structure:
6dd74de57[Child 3] ← [Child 1] ← [Root] → [Child 2] → [Child 4]
6dd74de58↓ ↓ ↓ ↓
6dd74de59[GrandChild] [GrandChild] [GrandChild] [GrandChild]