Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
47 commits
Select commit Hold shift + click to select a range
810893c
feat(layout)!: bundle ELK and make it the default layout
ashishjain0512 Aug 28, 2026
1a718eb
fix(docs): unbreak the docs build and resync generated docs
ashishjain0512 Aug 28, 2026
8105f5b
fix(e2e): stop the dagre pin overriding diagrams that pick their own …
ashishjain0512 Aug 28, 2026
cf03e4d
test(e2e): drop the dagre pin so baselines show the new ELK default
ashishjain0512 Aug 28, 2026
e98b045
test: give the usecase docs render spec room for ELK
ashishjain0512 Aug 28, 2026
f3488c6
Merge remote-tracking branch 'origin/develop' into claude/elk-default…
ashishjain0512 Aug 28, 2026
e46e822
style: format the rewritten lineHops imports
ashishjain0512 Aug 28, 2026
5522631
fix(mindmap): restore cose-bilkent as the mindmap default
ashishjain0512 Aug 28, 2026
afe237d
[autofix.ci] apply automated fixes
autofix-ci[bot] Aug 28, 2026
6b6d437
fix(elk): repair config sync and state notes broken by ELK becoming d…
ashishjain0512 Aug 28, 2026
f229f99
test(elk): pin the host config sync so it cannot be dropped again
knsv Aug 28, 2026
352cec9
Replaced elk layout to dagre layout
pbrolin47 Aug 31, 2026
fa4ba8a
changed elk-layout to dagre-layout for flowcharts
pbrolin47 Aug 31, 2026
0e2a507
Changed layout from elk to dagre
pbrolin47 Aug 31, 2026
fefa1a7
Changed layout in test from elk to dagre
pbrolin47 Aug 31, 2026
377aade
Corrected test
pbrolin47 Aug 31, 2026
37c505b
Merge branch 'claude/elk-default-flowchart-layout-4d2342' into perb/e…
pbrolin47 Aug 31, 2026
6485d92
Use fix of failing tsc-check from #8180
pbrolin47 Sep 1, 2026
20afb03
Merge branch 'develop' into perb/e2e-switch-layout-elk-dagre
ashish4mc Sep 1, 2026
22779d3
Merge branch 'develop' into claude/elk-default-flowchart-layout-4d2342
ashish4mc Sep 1, 2026
1634e09
Merge branch 'claude/elk-default-flowchart-layout-4d2342' into perb/e…
pbrolin47 Sep 1, 2026
c8a4b46
Merge branch 'develop' into claude/elk-default-flowchart-layout-4d2342
ashish4mc Sep 1, 2026
238c247
Merge branch 'claude/elk-default-flowchart-layout-4d2342' into perb/e…
pbrolin47 Sep 1, 2026
b993915
fix(elk): move small nodes onto the routed line instead of bending th…
knsv Sep 1, 2026
9018d1f
Merge pull request #8199 from mermaid-js/fix/state-diagram-elk
pbrolin47 Sep 2, 2026
1d01ace
Merge branch 'develop' into claude/elk-default-flowchart-layout-4d2342
pbrolin47 Sep 2, 2026
a240b8f
Addressed review comments
pbrolin47 Sep 2, 2026
b8e6f1b
Merge pull request #8182 from mermaid-js/perb/e2e-switch-layout-elk-d…
pbrolin47 Sep 2, 2026
2959713
Merge branch 'develop' into claude/elk-default-flowchart-layout-4d2342
knsv Sep 2, 2026
23a12a9
[autofix.ci] apply automated fixes
autofix-ci[bot] Sep 2, 2026
236a9e6
test: adapt develop's layout specs to the elk default
knsv Sep 2, 2026
780014f
address CodeRabbit review: docs accuracy, test assertions, catalogue …
knsv Sep 2, 2026
e52879a
[autofix.ci] apply automated fixes
autofix-ci[bot] Sep 2, 2026
8cc330d
address remaining review items: declare bundled deps, sanitize caveat…
knsv Sep 2, 2026
9b3fce0
Added dev-diags from findings in Argos
pbrolin47 Sep 2, 2026
d6a4fcc
Set default layout to dagre for state diagrams
pbrolin47 Sep 2, 2026
cf8d21e
fix: orient fork/join bars by flow direction under ELK layout
knsv Sep 2, 2026
3277552
Merge fork/join direction fix for ELK layout
knsv Sep 2, 2026
a378839
fix(er): stop lowering the edge group under ELK so edges paint above …
knsv Sep 2, 2026
4e00c5c
chore: changeset for ER/ELK edge paint-order fix
knsv Sep 2, 2026
fa6a87f
Merge ER edge paint-order fix for ELK layout
knsv Sep 2, 2026
a7831c5
fix(elk): keep group frames out to edge anchors on the frame border
knsv Sep 2, 2026
b9fa6de
Merge pull request #8204 from mermaid-js/bug/elk-state-composite-edge…
knsv Sep 2, 2026
0d75e52
Merge branch 'claude/elk-default-flowchart-layout-4d2342' of github.c…
knsv Sep 2, 2026
0320406
fix(elk): resolve cycle breaking for containers, not just the root graph
knsv Sep 3, 2026
ee33b4b
Set default layout to elk for state diagrams
pbrolin47 Sep 3, 2026
fe0e237
Merge pull request #8155 from mermaid-js/claude/elk-default-flowchart…
pbrolin47 Sep 3, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .build/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,9 @@ export const packageOptions = {
'mermaid-layout-elk': {
name: 'mermaid-layout-elk',
packageName: 'mermaid-layout-elk',
file: 'layouts.ts',
// Built from mermaid's own ELK source (path is relative to the package's
// `src`) so the plugin and the bundled layout are the same implementation.
file: '../../mermaid/src/rendering-util/layout-algorithms/elk/plugin.ts',
},
'mermaid-layout-tidy-tree': {
name: 'mermaid-layout-tidy-tree',
Expand Down
2 changes: 1 addition & 1 deletion .changeset/cluster-label-measurement.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ feat: `defaultMeasureLayout` accepts a `unwrapGroupLabels` option so a layout en

`insertCluster` paints a plain cluster label with an infinite width while the measurement pass wrapped it at 200px, so a layout that sizes compound nodes from the measured label sized them too narrow. Layouts now opt in explicitly; core no longer inspects the layout's name. Markdown cluster labels stay wrapped, since those are painted wrapped.

`@mermaid-js/layout-elk` opts in, which changes the size of labelled subgraphs in ELK-laid-out diagrams. Diagrams laid out with dagre are unaffected.
The bundled ELK layout opts in, which changes the size of labelled subgraphs in ELK-laid-out diagrams. Diagrams laid out with dagre are unaffected.
5 changes: 5 additions & 0 deletions .changeset/elk-composite-edge-anchor.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'mermaid': patch
---

fix: keep ELK subgraph frames out to the border anchor of edges that terminate on the group, so transitions to composite states no longer run along the cluster border
2 changes: 1 addition & 1 deletion .changeset/elk-container-algorithms.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
'@mermaid-js/layout-elk': minor
'mermaid': minor
---

feat: let a container pick its own ELK algorithm with `@{ algorithm: … }`, and add `elk.box` and `elk.rectpacking` to the selectable `layout` values.
Expand Down
19 changes: 19 additions & 0 deletions .changeset/elk-container-cycle-breaking.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
---
'mermaid': patch
---

fix(elk): a composite state or subgraph containing a loop now opens on its own start node.

Cycle breaking was resolved for the root graph but never passed to containers, so a
container laid out on its own fell back to ELK's default, `GREEDY`, while the root ran
whatever `elk.preset` asked for. The two then reversed different edges of the same cycle.

In a composite state that loops, greedy reverses the edge that turns an ordinary state
into a source, and sources sit on the first layer — so the diagram opened on that state
alongside its start circle instead of on the start circle alone. Dagre reverses the other
edge, which is why the two layout engines disagreed on the same diagram.

Containers now resolve cycle breaking from the preset exactly as the root does. Only
containers that actually contain a cycle change; an acyclic subgraph gives a cycle-breaking
strategy nothing to do. `preset: legacy` still reaches containers with `GREEDY`, so it keeps
reproducing the earlier rendering inside frames as well as outside them.
28 changes: 28 additions & 0 deletions .changeset/elk-default-layout.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
---
'mermaid': major
---

feat!: **ELK is now bundled with mermaid and is the default layout algorithm.**

ELK previously shipped as a separate `@mermaid-js/layout-elk` package that sites had to install and register. It is now part of mermaid itself and registered automatically, so `layout: elk` — and the `elk.stress`, `elk.force`, `elk.mrtree`, `elk.sporeOverlap`, `elk.box` and `elk.rectpacking` variants — work with no setup.

**This changes how existing diagrams look.** Flowchart, state, class, entity-relationship, requirement, use-case and agentflow diagrams that do not specify a `layout` are now laid out by ELK instead of dagre. To keep the previous layout, set dagre explicitly:

```yaml
---
config:
layout: dagre
---
```

or globally, `mermaid.initialize({ layout: 'dagre' })`.

Mindmap is unchanged: it keeps laying out with cose-bilkent unless a layout is explicitly requested (in the tiny build, which ships neither ELK nor cose-bilkent, it falls back to dagre).

Other notes:

- ELK is loaded as a separate chunk in the ESM builds, so it is only fetched when a diagram actually uses it. The single-file IIFE build (`mermaid.min.js`) inlines it and grows by roughly 500 kB gzipped.
- The **tiny** build deliberately omits ELK to stay small, and falls back to dagre for diagrams that ask for an ELK layout. Its size is unchanged.
- `@mermaid-js/layout-elk` is no longer needed on normal builds — existing `mermaid.registerLayoutLoaders(elkLayouts)` calls keep working and can be removed. It is still published, and remains the way to add ELK to the tiny build.
- `dist/mermaid.esm.min.mjs` now contains syntax that `es-module-lexer` (used by Vite) rejects with `content contains invalid JS syntax`. Bundler users are unaffected as long as they import the `mermaid` package specifier, which resolves to the core build; only builds that point Vite directly at that dist file need to switch to the package specifier or the core build.
- State diagrams now resolve their layout through the same registration check as every other diagram, so an unavailable layout falls back instead of failing to render.
5 changes: 5 additions & 0 deletions .changeset/elk-small-node-vertical-edges.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'mermaid': patch
---

fix: keep ELK edges vertical at small nodes — the node now moves onto the routed line instead of the edge bending toward the node's off-centre position
5 changes: 5 additions & 0 deletions .changeset/er-elk-edges-above-clusters.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'mermaid': patch
---

fix: render ER relationship edges above subgraph backgrounds under the ELK layout instead of hiding them behind the cluster rect
13 changes: 13 additions & 0 deletions .changeset/layout-elk-built-from-core.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
---
'@mermaid-js/layout-elk': minor
---

feat: this package is now built from mermaid's own ELK implementation instead of carrying its own copy, and is only needed for Mermaid builds that ship without ELK.

`mermaid` bundles ELK and registers it automatically, so most projects can drop the dependency and the `registerLayoutLoaders` call. The package remains published and fully functional for the **tiny** build (`mermaid.tiny.js`), which omits ELK to stay small and where registering this is the only way to get an ELK layout.

Because it is compiled from mermaid's ELK source rather than importing the whole `mermaid` entry point, the published bundle no longer drags in every diagram type, parser and KaTeX: the minified ESM payload drops from roughly **1.58 MB to 728 kB gzipped**. It stays self-contained, so it still loads from a CDN next to any Mermaid build with no import map.

The rendering utilities the ELK source reaches (`dompurify`, `katex`, `dayjs`, `dagre-d3-es`) are now declared in the package's `dependencies`, so the npm build (`.core.mjs`) resolves them through your package manager — they dedupe against the host's copies and show up in audits — instead of carrying invisible inlined copies.

> **Maintainers:** `peerDependencies.mermaid` still reads `^11.0.2`. It should be raised to the major that bundles ELK as part of the release.
3 changes: 2 additions & 1 deletion .esbuild/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,8 @@ export const getBuildConfig = (options: MermaidBuildOptions): BuildOptions => {
if (core) {
// Core build is used to generate file without bundled dependencies.
// This is used by downstream projects to bundle dependencies themselves.
// Ignore dependencies and any dependencies of dependencies
// Ignore dependencies and any dependencies of dependencies.
// A package may legitimately have none at all.
//
// peerDependencies must be external too. The consumer is the one that
// supplies them, so inlining one ships a second copy of that package —
Expand Down
20 changes: 14 additions & 6 deletions docs/config/layouts.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,27 @@ 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
- **elk** (default): [ELK (Eclipse Layout Kernel)](https://www.eclipse.org/elk/). Bundled with Mermaid; no setup required. Specific ELK algorithms can be selected as `elk.stress`, `elk.force`, `elk.mrtree`, `elk.sporeOverlap`, `elk.box`, and `elk.rectpacking`.
- **dagre**: Dagre layout for layered graphs
- **cose-bilkent**: Cose Bilkent layout for force-directed graphs
- **tidy-tree**: Tidy tree layout for hierarchical diagrams, from the [`@mermaid-js/layout-tidy-tree`](https://www.npmjs.com/package/@mermaid-js/layout-tidy-tree) package [Tidy Tree Configuration](/config/tidy-tree)

Mindmaps are the one diagram type not laid out with ELK by default; they use
cose-bilkent unless you ask for something else.

The **tiny** build omits ELK to stay small, and falls back to Dagre for
diagrams that request it.

## How to Use

You can specify the layout in your diagram's YAML config or initialization options. For example:
Since `elk` is the default, a diagram needs no configuration to use it. To pick
a different layout, set it in your diagram's YAML config or initialization
options. For example:

```mermaid-example
---
config:
layout: elk
layout: dagre
---
graph TD;
A-->B;
Expand All @@ -32,7 +40,7 @@ graph TD;
```mermaid
---
config:
layout: elk
layout: dagre
---
graph TD;
A-->B;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,28 +10,28 @@

# Interface: LayoutLoaderDefinition

Defined in: [packages/mermaid/src/rendering-util/render.ts:24](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/rendering-util/render.ts#L24)
Defined in: [packages/mermaid/src/rendering-util/render.ts:25](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/rendering-util/render.ts#L25)

## Properties

### algorithm?

> `optional` **algorithm**: `string`

Defined in: [packages/mermaid/src/rendering-util/render.ts:27](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/rendering-util/render.ts#L27)
Defined in: [packages/mermaid/src/rendering-util/render.ts:28](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/rendering-util/render.ts#L28)

---

### loader

> **loader**: `LayoutLoader`

Defined in: [packages/mermaid/src/rendering-util/render.ts:26](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/rendering-util/render.ts#L26)
Defined in: [packages/mermaid/src/rendering-util/render.ts:27](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/rendering-util/render.ts#L27)

---

### name

> **name**: `string`

Defined in: [packages/mermaid/src/rendering-util/render.ts:25](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/rendering-util/render.ts#L25)
Defined in: [packages/mermaid/src/rendering-util/render.ts:26](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/rendering-util/render.ts#L26)
Loading
Loading