From 358810b61b266ad0c74124388cfb51fa031d2a81 Mon Sep 17 00:00:00 2001 From: knsv Date: Fri, 5 Jun 2026 15:19:56 +0200 Subject: [PATCH 01/13] Use shared paint for Dagre layout --- .../functions/clearLayoutRenderState.md | 2 +- .../functions/createCommonLayoutRenderer.md | 2 +- .../mermaid/functions/defaultMeasureLayout.md | 2 +- .../mermaid/functions/paintLayoutData.md | 2 +- .../interfaces/CommonLayoutPaintContext.md | 14 +++++------ .../interfaces/CommonLayoutPaintOptions.md | 14 ++++++++--- .../interfaces/CommonLayoutRenderContext.md | 12 +++++----- .../CommonLayoutRendererDefinition.md | 14 +++++------ .../layout-algorithms/common/index.spec.ts | 19 ++++++++++++++- .../layout-algorithms/common/index.ts | 10 ++++++-- .../layout-algorithms/dagre/index.js | 11 ++++----- .../layout-algorithms/dagre/index.spec.js | 24 +++++++++++++++++++ 12 files changed, 90 insertions(+), 36 deletions(-) diff --git a/docs/config/setup/mermaid/functions/clearLayoutRenderState.md b/docs/config/setup/mermaid/functions/clearLayoutRenderState.md index 58f8c865183..2c93b004ed6 100644 --- a/docs/config/setup/mermaid/functions/clearLayoutRenderState.md +++ b/docs/config/setup/mermaid/functions/clearLayoutRenderState.md @@ -12,7 +12,7 @@ > **clearLayoutRenderState**(): `void` -Defined in: [packages/mermaid/src/rendering-util/layout-algorithms/common/index.ts:145](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/rendering-util/layout-algorithms/common/index.ts#L145) +Defined in: [packages/mermaid/src/rendering-util/layout-algorithms/common/index.ts:149](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/rendering-util/layout-algorithms/common/index.ts#L149) ## Returns diff --git a/docs/config/setup/mermaid/functions/createCommonLayoutRenderer.md b/docs/config/setup/mermaid/functions/createCommonLayoutRenderer.md index 7828e494254..58a60621517 100644 --- a/docs/config/setup/mermaid/functions/createCommonLayoutRenderer.md +++ b/docs/config/setup/mermaid/functions/createCommonLayoutRenderer.md @@ -12,7 +12,7 @@ > **createCommonLayoutRenderer**<`CoreResult`, `PreparedLayout`, `MeasureResult`>(`__namedParameters`): (`data4Layout`, `svg`, `helpers?`, `options?`, `positions?`) => `Promise`<`void`> -Defined in: [packages/mermaid/src/rendering-util/layout-algorithms/common/index.ts:88](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/rendering-util/layout-algorithms/common/index.ts#L88) +Defined in: [packages/mermaid/src/rendering-util/layout-algorithms/common/index.ts:92](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/rendering-util/layout-algorithms/common/index.ts#L92) ## Type Parameters diff --git a/docs/config/setup/mermaid/functions/defaultMeasureLayout.md b/docs/config/setup/mermaid/functions/defaultMeasureLayout.md index ebc8219b273..bec5a7b4d66 100644 --- a/docs/config/setup/mermaid/functions/defaultMeasureLayout.md +++ b/docs/config/setup/mermaid/functions/defaultMeasureLayout.md @@ -12,7 +12,7 @@ > **defaultMeasureLayout**(`data4Layout`, `__namedParameters`): `Promise`<{ `graph`: `Graph`; `groups`: { `clusters`: `D3Selection`<`SVGGElement`>; `edgeLabels`: `D3Selection`<`SVGGElement`>; `edgePaths`: `D3Selection`<`SVGGElement`>; `nodes`: `D3Selection`<`SVGGElement`>; `rootGroups`: `D3Selection`<`SVGGElement`>; }; `nodeElements`: `Map`<`string`, `D3Selection`<`SVGElement` | `SVGGElement`>>; }> -Defined in: [packages/mermaid/src/rendering-util/layout-algorithms/common/index.ts:152](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/rendering-util/layout-algorithms/common/index.ts#L152) +Defined in: [packages/mermaid/src/rendering-util/layout-algorithms/common/index.ts:156](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/rendering-util/layout-algorithms/common/index.ts#L156) ## Parameters diff --git a/docs/config/setup/mermaid/functions/paintLayoutData.md b/docs/config/setup/mermaid/functions/paintLayoutData.md index ad79a78340b..220d14c723c 100644 --- a/docs/config/setup/mermaid/functions/paintLayoutData.md +++ b/docs/config/setup/mermaid/functions/paintLayoutData.md @@ -12,7 +12,7 @@ > **paintLayoutData**(`data4Layout`, `__namedParameters`, `options`): `Promise`<`void`> -Defined in: [packages/mermaid/src/rendering-util/layout-algorithms/common/index.ts:159](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/rendering-util/layout-algorithms/common/index.ts#L159) +Defined in: [packages/mermaid/src/rendering-util/layout-algorithms/common/index.ts:163](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/rendering-util/layout-algorithms/common/index.ts#L163) ## Parameters diff --git a/docs/config/setup/mermaid/interfaces/CommonLayoutPaintContext.md b/docs/config/setup/mermaid/interfaces/CommonLayoutPaintContext.md index 76837f27ecb..3644c7aaddd 100644 --- a/docs/config/setup/mermaid/interfaces/CommonLayoutPaintContext.md +++ b/docs/config/setup/mermaid/interfaces/CommonLayoutPaintContext.md @@ -10,7 +10,7 @@ # Interface: CommonLayoutPaintContext\ -Defined in: [packages/mermaid/src/rendering-util/layout-algorithms/common/index.ts:46](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/rendering-util/layout-algorithms/common/index.ts#L46) +Defined in: [packages/mermaid/src/rendering-util/layout-algorithms/common/index.ts:49](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/rendering-util/layout-algorithms/common/index.ts#L49) ## Extends @@ -32,7 +32,7 @@ Defined in: [packages/mermaid/src/rendering-util/layout-algorithms/common/index. > **element**: `D3Selection`<`SVGElement`> -Defined in: [packages/mermaid/src/rendering-util/layout-algorithms/common/index.ts:39](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/rendering-util/layout-algorithms/common/index.ts#L39) +Defined in: [packages/mermaid/src/rendering-util/layout-algorithms/common/index.ts:42](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/rendering-util/layout-algorithms/common/index.ts#L42) #### Inherited from @@ -44,7 +44,7 @@ Defined in: [packages/mermaid/src/rendering-util/layout-algorithms/common/index. > `optional` **helpers**: `object` -Defined in: [packages/mermaid/src/rendering-util/layout-algorithms/common/index.ts:40](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/rendering-util/layout-algorithms/common/index.ts#L40) +Defined in: [packages/mermaid/src/rendering-util/layout-algorithms/common/index.ts:43](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/rendering-util/layout-algorithms/common/index.ts#L43) #### common @@ -492,7 +492,7 @@ The curve factory to use > **measure**: `MeasureResult` -Defined in: [packages/mermaid/src/rendering-util/layout-algorithms/common/index.ts:50](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/rendering-util/layout-algorithms/common/index.ts#L50) +Defined in: [packages/mermaid/src/rendering-util/layout-algorithms/common/index.ts:53](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/rendering-util/layout-algorithms/common/index.ts#L53) --- @@ -500,7 +500,7 @@ Defined in: [packages/mermaid/src/rendering-util/layout-algorithms/common/index. > `optional` **options**: [`RenderOptions`](RenderOptions.md) -Defined in: [packages/mermaid/src/rendering-util/layout-algorithms/common/index.ts:41](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/rendering-util/layout-algorithms/common/index.ts#L41) +Defined in: [packages/mermaid/src/rendering-util/layout-algorithms/common/index.ts:44](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/rendering-util/layout-algorithms/common/index.ts#L44) #### Inherited from @@ -512,7 +512,7 @@ Defined in: [packages/mermaid/src/rendering-util/layout-algorithms/common/index. > `optional` **positions**: `Positions` -Defined in: [packages/mermaid/src/rendering-util/layout-algorithms/common/index.ts:42](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/rendering-util/layout-algorithms/common/index.ts#L42) +Defined in: [packages/mermaid/src/rendering-util/layout-algorithms/common/index.ts:45](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/rendering-util/layout-algorithms/common/index.ts#L45) #### Inherited from @@ -524,7 +524,7 @@ Defined in: [packages/mermaid/src/rendering-util/layout-algorithms/common/index. > `optional` **preparedLayout**: `PreparedLayout` -Defined in: [packages/mermaid/src/rendering-util/layout-algorithms/common/index.ts:43](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/rendering-util/layout-algorithms/common/index.ts#L43) +Defined in: [packages/mermaid/src/rendering-util/layout-algorithms/common/index.ts:46](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/rendering-util/layout-algorithms/common/index.ts#L46) #### Inherited from diff --git a/docs/config/setup/mermaid/interfaces/CommonLayoutPaintOptions.md b/docs/config/setup/mermaid/interfaces/CommonLayoutPaintOptions.md index ef738b8a1b3..e2cf8cff09b 100644 --- a/docs/config/setup/mermaid/interfaces/CommonLayoutPaintOptions.md +++ b/docs/config/setup/mermaid/interfaces/CommonLayoutPaintOptions.md @@ -10,15 +10,23 @@ # Interface: CommonLayoutPaintOptions -Defined in: [packages/mermaid/src/rendering-util/layout-algorithms/common/index.ts:53](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/rendering-util/layout-algorithms/common/index.ts#L53) +Defined in: [packages/mermaid/src/rendering-util/layout-algorithms/common/index.ts:56](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/rendering-util/layout-algorithms/common/index.ts#L56) ## Properties +### clusterDb? + +> `optional` **clusterDb**: `ClusterDb` + +Defined in: [packages/mermaid/src/rendering-util/layout-algorithms/common/index.ts:57](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/rendering-util/layout-algorithms/common/index.ts#L57) + +--- + ### skipEdge()? > `optional` **skipEdge**: (`edge`) => `boolean` -Defined in: [packages/mermaid/src/rendering-util/layout-algorithms/common/index.ts:54](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/rendering-util/layout-algorithms/common/index.ts#L54) +Defined in: [packages/mermaid/src/rendering-util/layout-algorithms/common/index.ts:58](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/rendering-util/layout-algorithms/common/index.ts#L58) #### Parameters @@ -36,4 +44,4 @@ Defined in: [packages/mermaid/src/rendering-util/layout-algorithms/common/index. > `optional` **skipIntersect**: `boolean` | (`edge`) => `boolean` -Defined in: [packages/mermaid/src/rendering-util/layout-algorithms/common/index.ts:55](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/rendering-util/layout-algorithms/common/index.ts#L55) +Defined in: [packages/mermaid/src/rendering-util/layout-algorithms/common/index.ts:59](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/rendering-util/layout-algorithms/common/index.ts#L59) diff --git a/docs/config/setup/mermaid/interfaces/CommonLayoutRenderContext.md b/docs/config/setup/mermaid/interfaces/CommonLayoutRenderContext.md index 041b5c1f8f6..5953430c1a4 100644 --- a/docs/config/setup/mermaid/interfaces/CommonLayoutRenderContext.md +++ b/docs/config/setup/mermaid/interfaces/CommonLayoutRenderContext.md @@ -10,7 +10,7 @@ # Interface: CommonLayoutRenderContext\ -Defined in: [packages/mermaid/src/rendering-util/layout-algorithms/common/index.ts:38](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/rendering-util/layout-algorithms/common/index.ts#L38) +Defined in: [packages/mermaid/src/rendering-util/layout-algorithms/common/index.ts:41](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/rendering-util/layout-algorithms/common/index.ts#L41) ## Extended by @@ -28,7 +28,7 @@ Defined in: [packages/mermaid/src/rendering-util/layout-algorithms/common/index. > **element**: `D3Selection`<`SVGElement`> -Defined in: [packages/mermaid/src/rendering-util/layout-algorithms/common/index.ts:39](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/rendering-util/layout-algorithms/common/index.ts#L39) +Defined in: [packages/mermaid/src/rendering-util/layout-algorithms/common/index.ts:42](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/rendering-util/layout-algorithms/common/index.ts#L42) --- @@ -36,7 +36,7 @@ Defined in: [packages/mermaid/src/rendering-util/layout-algorithms/common/index. > `optional` **helpers**: `object` -Defined in: [packages/mermaid/src/rendering-util/layout-algorithms/common/index.ts:40](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/rendering-util/layout-algorithms/common/index.ts#L40) +Defined in: [packages/mermaid/src/rendering-util/layout-algorithms/common/index.ts:43](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/rendering-util/layout-algorithms/common/index.ts#L43) #### common @@ -480,7 +480,7 @@ The curve factory to use > `optional` **options**: [`RenderOptions`](RenderOptions.md) -Defined in: [packages/mermaid/src/rendering-util/layout-algorithms/common/index.ts:41](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/rendering-util/layout-algorithms/common/index.ts#L41) +Defined in: [packages/mermaid/src/rendering-util/layout-algorithms/common/index.ts:44](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/rendering-util/layout-algorithms/common/index.ts#L44) --- @@ -488,7 +488,7 @@ Defined in: [packages/mermaid/src/rendering-util/layout-algorithms/common/index. > `optional` **positions**: `Positions` -Defined in: [packages/mermaid/src/rendering-util/layout-algorithms/common/index.ts:42](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/rendering-util/layout-algorithms/common/index.ts#L42) +Defined in: [packages/mermaid/src/rendering-util/layout-algorithms/common/index.ts:45](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/rendering-util/layout-algorithms/common/index.ts#L45) --- @@ -496,4 +496,4 @@ Defined in: [packages/mermaid/src/rendering-util/layout-algorithms/common/index. > `optional` **preparedLayout**: `PreparedLayout` -Defined in: [packages/mermaid/src/rendering-util/layout-algorithms/common/index.ts:43](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/rendering-util/layout-algorithms/common/index.ts#L43) +Defined in: [packages/mermaid/src/rendering-util/layout-algorithms/common/index.ts:46](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/rendering-util/layout-algorithms/common/index.ts#L46) diff --git a/docs/config/setup/mermaid/interfaces/CommonLayoutRendererDefinition.md b/docs/config/setup/mermaid/interfaces/CommonLayoutRendererDefinition.md index 50f61f94af2..0abb767be5d 100644 --- a/docs/config/setup/mermaid/interfaces/CommonLayoutRendererDefinition.md +++ b/docs/config/setup/mermaid/interfaces/CommonLayoutRendererDefinition.md @@ -10,7 +10,7 @@ # Interface: CommonLayoutRendererDefinition\ -Defined in: [packages/mermaid/src/rendering-util/layout-algorithms/common/index.ts:58](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/rendering-util/layout-algorithms/common/index.ts#L58) +Defined in: [packages/mermaid/src/rendering-util/layout-algorithms/common/index.ts:62](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/rendering-util/layout-algorithms/common/index.ts#L62) ## Type Parameters @@ -32,7 +32,7 @@ Defined in: [packages/mermaid/src/rendering-util/layout-algorithms/common/index. > `optional` **afterPaint**: (`data4Layout`, `context`, `coreResult`) => `void` | `Promise`<`void`> -Defined in: [packages/mermaid/src/rendering-util/layout-algorithms/common/index.ts:80](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/rendering-util/layout-algorithms/common/index.ts#L80) +Defined in: [packages/mermaid/src/rendering-util/layout-algorithms/common/index.ts:84](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/rendering-util/layout-algorithms/common/index.ts#L84) #### Parameters @@ -58,7 +58,7 @@ Defined in: [packages/mermaid/src/rendering-util/layout-algorithms/common/index. > `optional` **measureLayout**: (`data4Layout`, `context`) => `Promise`<`MeasureResult`> -Defined in: [packages/mermaid/src/rendering-util/layout-algorithms/common/index.ts:67](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/rendering-util/layout-algorithms/common/index.ts#L67) +Defined in: [packages/mermaid/src/rendering-util/layout-algorithms/common/index.ts:71](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/rendering-util/layout-algorithms/common/index.ts#L71) #### Parameters @@ -80,7 +80,7 @@ Defined in: [packages/mermaid/src/rendering-util/layout-algorithms/common/index. > `optional` **paintLayout**: (`data4Layout`, `context`, `coreResult`) => `void` | `Promise`<`void`> -Defined in: [packages/mermaid/src/rendering-util/layout-algorithms/common/index.ts:75](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/rendering-util/layout-algorithms/common/index.ts#L75) +Defined in: [packages/mermaid/src/rendering-util/layout-algorithms/common/index.ts:79](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/rendering-util/layout-algorithms/common/index.ts#L79) #### Parameters @@ -106,7 +106,7 @@ Defined in: [packages/mermaid/src/rendering-util/layout-algorithms/common/index. > `optional` **paintOptions**: [`CommonLayoutPaintOptions`](CommonLayoutPaintOptions.md) -Defined in: [packages/mermaid/src/rendering-util/layout-algorithms/common/index.ts:85](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/rendering-util/layout-algorithms/common/index.ts#L85) +Defined in: [packages/mermaid/src/rendering-util/layout-algorithms/common/index.ts:89](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/rendering-util/layout-algorithms/common/index.ts#L89) --- @@ -114,7 +114,7 @@ Defined in: [packages/mermaid/src/rendering-util/layout-algorithms/common/index. > `optional` **prepareLayout**: (`data4Layout`, `context`) => `PreparedLayout` | `Promise`<`PreparedLayout`> -Defined in: [packages/mermaid/src/rendering-util/layout-algorithms/common/index.ts:63](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/rendering-util/layout-algorithms/common/index.ts#L63) +Defined in: [packages/mermaid/src/rendering-util/layout-algorithms/common/index.ts:67](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/rendering-util/layout-algorithms/common/index.ts#L67) #### Parameters @@ -136,7 +136,7 @@ Defined in: [packages/mermaid/src/rendering-util/layout-algorithms/common/index. > **runLayoutCore**: (`data4Layout`, `context`) => `CoreResult` | `Promise`<`CoreResult`> -Defined in: [packages/mermaid/src/rendering-util/layout-algorithms/common/index.ts:71](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/rendering-util/layout-algorithms/common/index.ts#L71) +Defined in: [packages/mermaid/src/rendering-util/layout-algorithms/common/index.ts:75](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/rendering-util/layout-algorithms/common/index.ts#L75) #### Parameters diff --git a/packages/mermaid/src/rendering-util/layout-algorithms/common/index.spec.ts b/packages/mermaid/src/rendering-util/layout-algorithms/common/index.spec.ts index b913264d5c3..5196ab8e501 100644 --- a/packages/mermaid/src/rendering-util/layout-algorithms/common/index.spec.ts +++ b/packages/mermaid/src/rendering-util/layout-algorithms/common/index.spec.ts @@ -310,8 +310,10 @@ describe('paintLayoutData', () => { edges: [layoutOnlyEdge, skippedEdge, renderEdge], }); const measured = measure(); + const clusterDb = new Map([[group.id, { node: group }]]); await paintLayoutData(data, { measure: measured } as never, { + clusterDb, skipEdge: (candidate) => candidate.id === skippedEdge.id, skipIntersect: (candidate) => candidate.id === renderEdge.id, }); @@ -323,7 +325,7 @@ describe('paintLayoutData', () => { expect(mocks.insertEdge).toHaveBeenCalledWith( measured.groups.edgePaths, { ...renderEdge }, - {}, + clusterDb, data.type, nodeA, nodeB, @@ -332,6 +334,21 @@ describe('paintLayoutData', () => { ); }); + it('positions pre-rendered cluster nodes without inserting another cluster', async () => { + const { paintLayoutData } = await import('./index.js'); + const clusterNode = node('G', { clusterNode: true, isGroup: true } as never); + const data = layout({ + nodes: [clusterNode], + edges: [], + }); + const measured = measure(); + + await paintLayoutData(data, { measure: measured } as never); + + expect(mocks.insertCluster).not.toHaveBeenCalled(); + expect(mocks.positionNode).toHaveBeenCalledWith(clusterNode); + }); + it('inserts and positions edge labels after drawing labelled edges', async () => { const { paintLayoutData } = await import('./index.js'); const labelledEdge = edge('labelled', { label: 'Yes', x: 0, y: 0 } as Partial); diff --git a/packages/mermaid/src/rendering-util/layout-algorithms/common/index.ts b/packages/mermaid/src/rendering-util/layout-algorithms/common/index.ts index 55762f31bee..6d1e679e8c2 100644 --- a/packages/mermaid/src/rendering-util/layout-algorithms/common/index.ts +++ b/packages/mermaid/src/rendering-util/layout-algorithms/common/index.ts @@ -29,12 +29,15 @@ type RenderedEdge = Edge & { endLabelRight?: string; }; type EdgeRenderPath = Parameters[0]; +type ClusterDb = Map>; interface EdgeRenderPaths { originalPath?: EdgeRenderPath; updatedPath?: EdgeRenderPath; } +const EMPTY_CLUSTER_DB: ClusterDb = new Map(); + export interface CommonLayoutRenderContext { element: D3Selection; helpers?: InternalHelpers; @@ -51,6 +54,7 @@ export interface CommonLayoutPaintContext< } export interface CommonLayoutPaintOptions { + clusterDb?: ClusterDb; skipEdge?: (edge: Edge) => boolean; skipIntersect?: boolean | ((edge: Edge) => boolean); } @@ -183,7 +187,9 @@ async function paintLayoutNode( groups: CommonLayoutMeasure['groups'], node: LayoutData['nodes'][number] ): Promise { - if (node.isGroup) { + if ((node as { clusterNode?: boolean }).clusterNode) { + positionNode(node); + } else if (node.isGroup) { await insertCluster(groups.clusters, node); } else { positionNode(node); @@ -214,7 +220,7 @@ async function paintLayoutEdge( const paths = insertEdge( groups.edgePaths, { ...edge }, - {}, + options.clusterDb ?? EMPTY_CLUSTER_DB, data4Layout.type, getRenderedNode(edge.start, nodeById), getRenderedNode(edge.end, nodeById), diff --git a/packages/mermaid/src/rendering-util/layout-algorithms/dagre/index.js b/packages/mermaid/src/rendering-util/layout-algorithms/dagre/index.js index 0d1381788fb..6862fccbb28 100644 --- a/packages/mermaid/src/rendering-util/layout-algorithms/dagre/index.js +++ b/packages/mermaid/src/rendering-util/layout-algorithms/dagre/index.js @@ -46,6 +46,7 @@ const DAGRE_NODE_LAYOUT_PROPERTIES = [ 'intersect', 'calcIntersect', 'diff', + 'clusterNode', ]; // Use dagre's dummy self-loop placement as a hint, so loops are not always forced above the node. @@ -399,7 +400,7 @@ const measureDagreGraph = async ({ return { elem, graph, - groups: { clusters, edgePaths }, + groups: { clusters, edgePaths, edgeLabels, nodes, rootGroups: elem }, diagramType, id, mergeSelfLoops, @@ -739,13 +740,11 @@ export const runDagreLayoutCore = (_data4Layout, context) => { return measuredLayout; }; -export const paintDagreLayout = async (_data4Layout, { measure }, coreResult) => { - await paintDagreLayoutCore(coreResult ?? measure); -}; - export const render = createCommonLayoutRenderer({ prepareLayout: prepareLayoutForDagre, measureLayout: measureDagreLayout, runLayoutCore: runDagreLayoutCore, - paintLayout: paintDagreLayout, + paintOptions: { + clusterDb, + }, }); diff --git a/packages/mermaid/src/rendering-util/layout-algorithms/dagre/index.spec.js b/packages/mermaid/src/rendering-util/layout-algorithms/dagre/index.spec.js index 0af9cfb3eb8..92e23e58e27 100644 --- a/packages/mermaid/src/rendering-util/layout-algorithms/dagre/index.spec.js +++ b/packages/mermaid/src/rendering-util/layout-algorithms/dagre/index.spec.js @@ -457,4 +457,28 @@ C --> C` restoreDom(); } }); + + it('renders a flowchart subgraph through the shared paint path', async () => { + const restoreDom = setupDom(); + + try { + const { svg } = await mermaidAPI.render( + 'shared-paint-subgraph-test', + `flowchart TD +subgraph clusterA[Cluster A] +A --> B +end +clusterA --> C` + ); + const dom = new JSDOM(svg); + + expect(dom.window.document.querySelectorAll('.cluster')).toHaveLength(1); + expect(dom.window.document.querySelectorAll('.node')).toHaveLength(3); + expect(dom.window.document.querySelectorAll('.edgePaths path.flowchart-link')).toHaveLength( + 2 + ); + } finally { + restoreDom(); + } + }); }); From 876ab0aad4191a5fa4a4f8660434ff524a56f7eb Mon Sep 17 00:00:00 2001 From: knsv Date: Fri, 5 Jun 2026 15:27:26 +0200 Subject: [PATCH 02/13] Share Dagre node measurement helpers --- .../mermaid/src/rendering-util/createGraph.ts | 80 ++++++++++++++----- .../layout-algorithms/dagre/index.js | 19 +++-- 2 files changed, 72 insertions(+), 27 deletions(-) diff --git a/packages/mermaid/src/rendering-util/createGraph.ts b/packages/mermaid/src/rendering-util/createGraph.ts index cf7b4b424c2..f0723fcc878 100644 --- a/packages/mermaid/src/rendering-util/createGraph.ts +++ b/packages/mermaid/src/rendering-util/createGraph.ts @@ -1,6 +1,6 @@ import type { Selection } from 'd3'; import * as graphlib from 'dagre-d3-es/src/graphlib/index.js'; -import type { LayoutData } from './types.js'; +import type { ClusterNode, LayoutData, NonClusterNode, ShapeRenderOptions } from './types.js'; import { getConfig } from '../diagram-api/diagramAPI.js'; import { hasEdgeLabel, insertEdgeLabel } from './rendering-elements/edges.js'; import { insertNode } from './rendering-elements/nodes.js'; @@ -14,6 +14,56 @@ type D3Selection = Selection< unknown >; +interface LayoutElementGroups { + clusters: D3Selection; + edgePaths: D3Selection; + edgeLabels: D3Selection; + nodes: D3Selection; + rootGroups: D3Selection; +} + +export interface CreateLayoutElementGroupsOptions { + edgePathsClass?: string; +} + +export function createLayoutElementGroups( + element: D3Selection, + { edgePathsClass = 'edges edgePath' }: CreateLayoutElementGroupsOptions = {} +): LayoutElementGroups { + const rootGroups = element.insert('g').attr('class', 'root'); + const clusters = rootGroups.insert('g').attr('class', 'clusters'); + const edgePaths = rootGroups.insert('g').attr('class', edgePathsClass); + const edgeLabels = rootGroups.insert('g').attr('class', 'edgeLabels'); + const nodes = rootGroups.insert('g').attr('class', 'nodes'); + + return { clusters, edgePaths, edgeLabels, nodes, rootGroups }; +} + +export async function measureGroupLabel( + nodesGroup: D3Selection, + node: ClusterNode +): Promise { + if (node.label) { + const { shapeSvg, bbox } = await labelHelper(nodesGroup, node); + node.labelBBox = { width: bbox.width, height: bbox.height }; + shapeSvg.remove(); + } else { + node.labelBBox = { width: 0, height: 0 }; + } +} + +export async function insertMeasuredNode( + nodesGroup: D3Selection, + node: NonClusterNode, + renderOptions: ShapeRenderOptions +): Promise> { + const childNodeEl = await insertNode(nodesGroup, node, renderOptions); + const boundingBox = childNodeEl.node()?.getBBox() ?? { width: 0, height: 0 }; + node.width = boundingBox.width; + node.height = boundingBox.height; + return childNodeEl as D3Selection; +} + /** * Creates a graph by merging the graph construction and DOM element insertion. * @@ -46,12 +96,8 @@ export async function createGraphWithElements( }); const edgesToProcess = [...data4Layout.edges]; const config = getConfig(); - // Create groups for clusters, edge paths, edge labels, and nodes. - const rootGroups = element.insert('g').attr('class', 'root'); - const clusters = rootGroups.insert('g').attr('class', 'clusters'); - const edgePaths = rootGroups.insert('g').attr('class', 'edges edgePath'); - const edgeLabels = rootGroups.insert('g').attr('class', 'edgeLabels'); - const nodesGroup = rootGroups.insert('g').attr('class', 'nodes'); + const groups = createLayoutElementGroups(element); + const { edgeLabels, nodes: nodesGroup } = groups; const nodeElements = new Map>(); @@ -67,22 +113,16 @@ export async function createGraphWithElements( data4Layout.nodes.map(async (node) => { if (node.isGroup) { if (hasDom) { - if (node.label) { - const { shapeSvg, bbox } = await labelHelper(nodesGroup, node); - node.labelBBox = { width: bbox.width, height: bbox.height }; - shapeSvg.remove(); - } else { - node.labelBBox = { width: 0, height: 0 }; - } + await measureGroupLabel(nodesGroup, node); } graph.setNode(node.id, { ...node }); } else { if (hasDom) { - const childNodeEl = await insertNode(nodesGroup, node, { config, dir: node.dir }); - const boundingBox = childNodeEl.node()?.getBBox() ?? { width: 0, height: 0 }; - nodeElements.set(node.id, childNodeEl as D3Selection); - node.width = boundingBox.width; - node.height = boundingBox.height; + const childNodeEl = await insertMeasuredNode(nodesGroup, node, { + config, + dir: node.dir, + }); + nodeElements.set(node.id, childNodeEl); } graph.setNode(node.id, { ...node }); } @@ -114,7 +154,7 @@ export async function createGraphWithElements( return { graph, - groups: { clusters, edgePaths, edgeLabels, nodes: nodesGroup, rootGroups }, + groups, nodeElements, }; } diff --git a/packages/mermaid/src/rendering-util/layout-algorithms/dagre/index.js b/packages/mermaid/src/rendering-util/layout-algorithms/dagre/index.js index 6862fccbb28..4f47f303262 100644 --- a/packages/mermaid/src/rendering-util/layout-algorithms/dagre/index.js +++ b/packages/mermaid/src/rendering-util/layout-algorithms/dagre/index.js @@ -1,6 +1,7 @@ import { layout as dagreLayout } from 'dagre-d3-es/src/dagre/index.js'; import * as graphlibJson from 'dagre-d3-es/src/graphlib/json.js'; import * as graphlib from 'dagre-d3-es/src/graphlib/index.js'; +import { createLayoutElementGroups, insertMeasuredNode } from '../../createGraph.js'; import { createCommonLayoutRenderer } from '../common/index.js'; import { updateNodeBounds } from '../../rendering-elements/shapes/util.js'; import { @@ -9,7 +10,7 @@ import { findNonClusterChild, sortNodesByHierarchy, } from './mermaid-graphlib.js'; -import { insertNode, positionNode, setNodeElem } from '../../rendering-elements/nodes.js'; +import { positionNode, setNodeElem } from '../../rendering-elements/nodes.js'; import { insertCluster } from '../../rendering-elements/clusters.js'; import { insertEdgeLabel, positionEdgeLabel, insertEdge } from '../../rendering-elements/edges.js'; import { log } from '../../../logger.js'; @@ -260,7 +261,15 @@ const measureDagreGraph = async ({ const dir = graph.graph().rankdir; log.trace('Dir in recursive render - dir:', dir); - const elem = _elem.insert('g').attr('class', 'root'); + const { + clusters, + edgePaths, + edgeLabels, + nodes, + rootGroups: elem, + } = createLayoutElementGroups(_elem, { + edgePathsClass: 'edgePaths', + }); if (!graph.nodes()) { log.info('No nodes found for', graph); } else { @@ -269,10 +278,6 @@ const measureDagreGraph = async ({ if (graph.edges().length > 0) { log.info('Recursive edges', graph.edge(graph.edges()[0])); } - const clusters = elem.insert('g').attr('class', 'clusters'); - const edgePaths = elem.insert('g').attr('class', 'edgePaths'); - const edgeLabels = elem.insert('g').attr('class', 'edgeLabels'); - const nodes = elem.insert('g').attr('class', 'nodes'); const mergeSelfLoops = shouldMergeSelfLoopSegments(diagramType); // Insert nodes, this will insert them into the dom and each node will get a size. The size is updated @@ -354,7 +359,7 @@ const measureDagreGraph = async ({ // insertCluster(clusters, graph.node(v)); } else { log.trace('Node - the non recursive path XAX', v, nodes, graph.node(v), dir); - await insertNode(nodes, graph.node(v), { config: siteConfig, dir }); + await insertMeasuredNode(nodes, graph.node(v), { config: siteConfig, dir }); } } }) From 83fadb5c3c1df9dacc38f5c5beed21c156db1bce Mon Sep 17 00:00:00 2001 From: knsv Date: Tue, 9 Jun 2026 11:50:07 +0200 Subject: [PATCH 03/13] Fix Dagre shared paint cluster handling --- .../layout-algorithms/common/index.spec.ts | 36 ++++++++++++ .../layout-algorithms/common/index.ts | 30 ++++++++-- .../layout-algorithms/dagre/index.js | 3 + .../layout-algorithms/dagre/index.spec.js | 58 +++++++++++++++++++ 4 files changed, 123 insertions(+), 4 deletions(-) diff --git a/packages/mermaid/src/rendering-util/layout-algorithms/common/index.spec.ts b/packages/mermaid/src/rendering-util/layout-algorithms/common/index.spec.ts index 5196ab8e501..ae1dfde7ce8 100644 --- a/packages/mermaid/src/rendering-util/layout-algorithms/common/index.spec.ts +++ b/packages/mermaid/src/rendering-util/layout-algorithms/common/index.spec.ts @@ -349,6 +349,42 @@ describe('paintLayoutData', () => { expect(mocks.positionNode).toHaveBeenCalledWith(clusterNode); }); + it('lets layout algorithms decide which group nodes are clusters', async () => { + const { paintLayoutData } = await import('./index.js'); + const leafGroup = node('G', { isGroup: true, shape: 'rectWithTitle' }); + const data = layout({ + nodes: [leafGroup], + edges: [], + }); + const measured = measure(); + + await paintLayoutData(data, { measure: measured } as never, { + isCluster: () => false, + }); + + expect(mocks.insertCluster).not.toHaveBeenCalled(); + expect(mocks.positionNode).toHaveBeenCalledWith(leafGroup); + }); + + it('lets layout algorithms skip nodes that were already painted elsewhere', async () => { + const { paintLayoutData } = await import('./index.js'); + const rootNode = node('root'); + const extractedNode = node('nested'); + const data = layout({ + nodes: [rootNode, extractedNode], + edges: [], + }); + const measured = measure(); + + await paintLayoutData(data, { measure: measured } as never, { + skipNode: (candidate) => candidate.id === extractedNode.id, + }); + + expect(mocks.positionNode).toHaveBeenCalledTimes(1); + expect(mocks.positionNode).toHaveBeenCalledWith(rootNode); + expect(mocks.positionNode).not.toHaveBeenCalledWith(extractedNode); + }); + it('inserts and positions edge labels after drawing labelled edges', async () => { const { paintLayoutData } = await import('./index.js'); const labelledEdge = edge('labelled', { label: 'Yes', x: 0, y: 0 } as Partial); diff --git a/packages/mermaid/src/rendering-util/layout-algorithms/common/index.ts b/packages/mermaid/src/rendering-util/layout-algorithms/common/index.ts index 6d1e679e8c2..b9b1c1f4b46 100644 --- a/packages/mermaid/src/rendering-util/layout-algorithms/common/index.ts +++ b/packages/mermaid/src/rendering-util/layout-algorithms/common/index.ts @@ -55,6 +55,14 @@ export interface CommonLayoutPaintContext< export interface CommonLayoutPaintOptions { clusterDb?: ClusterDb; + skipNode?: ( + node: LayoutData['nodes'][number], + context: CommonLayoutPaintContext + ) => boolean; + isCluster?: ( + node: LayoutData['nodes'][number], + context: CommonLayoutPaintContext + ) => boolean; skipEdge?: (edge: Edge) => boolean; skipIntersect?: boolean | ((edge: Edge) => boolean); } @@ -162,14 +170,18 @@ export async function defaultMeasureLayout( export async function paintLayoutData( data4Layout: LayoutData, - { measure }: CommonLayoutPaintContext, + context: CommonLayoutPaintContext, options: CommonLayoutPaintOptions = {} ): Promise { + const { measure } = context; const { groups } = measure; // Render clusters and position nodes; this also populates node.intersect on shapes. for (const node of data4Layout.nodes) { - await paintLayoutNode(groups, node); + if (options.skipNode?.(node, context)) { + continue; + } + await paintLayoutNode(groups, node, context, options); } const nodeById = buildNodeLookup(data4Layout.nodes); @@ -185,17 +197,27 @@ export async function paintLayoutData( async function paintLayoutNode( groups: CommonLayoutMeasure['groups'], - node: LayoutData['nodes'][number] + node: LayoutData['nodes'][number], + context: CommonLayoutPaintContext, + options: CommonLayoutPaintOptions ): Promise { if ((node as { clusterNode?: boolean }).clusterNode) { positionNode(node); - } else if (node.isGroup) { + } else if (shouldPaintAsCluster(node, context, options)) { await insertCluster(groups.clusters, node); } else { positionNode(node); } } +function shouldPaintAsCluster( + node: LayoutData['nodes'][number], + context: CommonLayoutPaintContext, + options: CommonLayoutPaintOptions +): boolean { + return options.isCluster?.(node, context) ?? Boolean(node.isGroup); +} + function buildNodeLookup(nodes: LayoutData['nodes']): Map { const nodeById = new Map(); for (const node of nodes) { diff --git a/packages/mermaid/src/rendering-util/layout-algorithms/dagre/index.js b/packages/mermaid/src/rendering-util/layout-algorithms/dagre/index.js index 6862fccbb28..2fca133f5e7 100644 --- a/packages/mermaid/src/rendering-util/layout-algorithms/dagre/index.js +++ b/packages/mermaid/src/rendering-util/layout-algorithms/dagre/index.js @@ -746,5 +746,8 @@ export const render = createCommonLayoutRenderer({ runLayoutCore: runDagreLayoutCore, paintOptions: { clusterDb, + skipNode: (node, { measure }) => !measure.graph.hasNode(node.id), + isCluster: (node, { measure }) => + measure.graph.hasNode(node.id) && (measure.graph.children(node.id) ?? []).length > 0, }, }); diff --git a/packages/mermaid/src/rendering-util/layout-algorithms/dagre/index.spec.js b/packages/mermaid/src/rendering-util/layout-algorithms/dagre/index.spec.js index 92e23e58e27..76e2e51a559 100644 --- a/packages/mermaid/src/rendering-util/layout-algorithms/dagre/index.spec.js +++ b/packages/mermaid/src/rendering-util/layout-algorithms/dagre/index.spec.js @@ -481,4 +481,62 @@ clusterA --> C` restoreDom(); } }); + + it('renders hand-drawn class diagrams with nested namespaces', async () => { + const restoreDom = setupDom(); + + try { + const dotNotation = await mermaidAPI.render( + 'class-nested-namespace-dot-test', + `%%{init: {"look": "handDrawn", "htmlLabels": true}}%% +classDiagram +namespace Company.Engineering.Backend { + class Developer { + +writeCode() + } +} +namespace Company.Engineering.Frontend { + class Designer { + +createMockup() + } +} +namespace Company.Engineering { + class TechLead { + +planSprint() + } +} +TechLead --> Developer : leads +TechLead --> Designer : leads` + ); + const syntactic = await mermaidAPI.render( + 'class-nested-namespace-syntax-test', + `%%{init: {"look": "handDrawn", "htmlLabels": true}}%% +classDiagram +namespace Platform { + namespace Auth { + class UserService { + +login() + +logout() + } + } + namespace Data { + class Repository { + +find() + +save() + } + } + class Gateway { + +route() + } +} +Gateway --> UserService : delegates +Gateway --> Repository : delegates` + ); + + expect(new JSDOM(dotNotation.svg).window.document.querySelector('svg')).toBeTruthy(); + expect(new JSDOM(syntactic.svg).window.document.querySelector('svg')).toBeTruthy(); + } finally { + restoreDom(); + } + }); }); From 5b1516a05936aad965a6192529cae61e0c564b75 Mon Sep 17 00:00:00 2001 From: knsv Date: Tue, 9 Jun 2026 13:00:12 +0200 Subject: [PATCH 04/13] Fix common paint cluster type narrowing --- .../rendering-util/layout-algorithms/common/index.spec.ts | 2 +- .../src/rendering-util/layout-algorithms/common/index.ts | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/packages/mermaid/src/rendering-util/layout-algorithms/common/index.spec.ts b/packages/mermaid/src/rendering-util/layout-algorithms/common/index.spec.ts index ae1dfde7ce8..4a1e64def98 100644 --- a/packages/mermaid/src/rendering-util/layout-algorithms/common/index.spec.ts +++ b/packages/mermaid/src/rendering-util/layout-algorithms/common/index.spec.ts @@ -351,7 +351,7 @@ describe('paintLayoutData', () => { it('lets layout algorithms decide which group nodes are clusters', async () => { const { paintLayoutData } = await import('./index.js'); - const leafGroup = node('G', { isGroup: true, shape: 'rectWithTitle' }); + const leafGroup = node('G', { isGroup: true, shape: 'roundedWithTitle' }); const data = layout({ nodes: [leafGroup], edges: [], diff --git a/packages/mermaid/src/rendering-util/layout-algorithms/common/index.ts b/packages/mermaid/src/rendering-util/layout-algorithms/common/index.ts index b9b1c1f4b46..6fa57400ca6 100644 --- a/packages/mermaid/src/rendering-util/layout-algorithms/common/index.ts +++ b/packages/mermaid/src/rendering-util/layout-algorithms/common/index.ts @@ -17,7 +17,7 @@ import { } from '../../rendering-elements/edges.js'; import insertMarkers from '../../rendering-elements/markers.js'; import { clear as clearNodes, positionNode } from '../../rendering-elements/nodes.js'; -import type { LayoutData, Edge } from '../../types.js'; +import type { LayoutData, Edge, ClusterNode } from '../../types.js'; import type { RenderOptions } from '../../render.js'; import { clear as clearGraphlib } from '../dagre/mermaid-graphlib.js'; @@ -214,8 +214,8 @@ function shouldPaintAsCluster( node: LayoutData['nodes'][number], context: CommonLayoutPaintContext, options: CommonLayoutPaintOptions -): boolean { - return options.isCluster?.(node, context) ?? Boolean(node.isGroup); +): node is ClusterNode { + return node.isGroup === true && (options.isCluster?.(node, context) ?? true); } function buildNodeLookup(nodes: LayoutData['nodes']): Map { From b7f72b47d494b3eca5c89f59d1d27e842b50fbc9 Mon Sep 17 00:00:00 2001 From: knsv Date: Tue, 9 Jun 2026 13:06:05 +0200 Subject: [PATCH 05/13] Sync generated common layout docs --- .../functions/clearLayoutRenderState.md | 2 +- .../functions/createCommonLayoutRenderer.md | 2 +- .../mermaid/functions/defaultMeasureLayout.md | 2 +- .../mermaid/functions/paintLayoutData.md | 6 +-- .../interfaces/CommonLayoutPaintOptions.md | 48 ++++++++++++++++++- .../CommonLayoutRendererDefinition.md | 14 +++--- 6 files changed, 59 insertions(+), 15 deletions(-) diff --git a/docs/config/setup/mermaid/functions/clearLayoutRenderState.md b/docs/config/setup/mermaid/functions/clearLayoutRenderState.md index 2c93b004ed6..7693435a948 100644 --- a/docs/config/setup/mermaid/functions/clearLayoutRenderState.md +++ b/docs/config/setup/mermaid/functions/clearLayoutRenderState.md @@ -12,7 +12,7 @@ > **clearLayoutRenderState**(): `void` -Defined in: [packages/mermaid/src/rendering-util/layout-algorithms/common/index.ts:149](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/rendering-util/layout-algorithms/common/index.ts#L149) +Defined in: [packages/mermaid/src/rendering-util/layout-algorithms/common/index.ts:157](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/rendering-util/layout-algorithms/common/index.ts#L157) ## Returns diff --git a/docs/config/setup/mermaid/functions/createCommonLayoutRenderer.md b/docs/config/setup/mermaid/functions/createCommonLayoutRenderer.md index 58a60621517..99fccb28eea 100644 --- a/docs/config/setup/mermaid/functions/createCommonLayoutRenderer.md +++ b/docs/config/setup/mermaid/functions/createCommonLayoutRenderer.md @@ -12,7 +12,7 @@ > **createCommonLayoutRenderer**<`CoreResult`, `PreparedLayout`, `MeasureResult`>(`__namedParameters`): (`data4Layout`, `svg`, `helpers?`, `options?`, `positions?`) => `Promise`<`void`> -Defined in: [packages/mermaid/src/rendering-util/layout-algorithms/common/index.ts:92](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/rendering-util/layout-algorithms/common/index.ts#L92) +Defined in: [packages/mermaid/src/rendering-util/layout-algorithms/common/index.ts:100](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/rendering-util/layout-algorithms/common/index.ts#L100) ## Type Parameters diff --git a/docs/config/setup/mermaid/functions/defaultMeasureLayout.md b/docs/config/setup/mermaid/functions/defaultMeasureLayout.md index bec5a7b4d66..ddf66067151 100644 --- a/docs/config/setup/mermaid/functions/defaultMeasureLayout.md +++ b/docs/config/setup/mermaid/functions/defaultMeasureLayout.md @@ -12,7 +12,7 @@ > **defaultMeasureLayout**(`data4Layout`, `__namedParameters`): `Promise`<{ `graph`: `Graph`; `groups`: { `clusters`: `D3Selection`<`SVGGElement`>; `edgeLabels`: `D3Selection`<`SVGGElement`>; `edgePaths`: `D3Selection`<`SVGGElement`>; `nodes`: `D3Selection`<`SVGGElement`>; `rootGroups`: `D3Selection`<`SVGGElement`>; }; `nodeElements`: `Map`<`string`, `D3Selection`<`SVGElement` | `SVGGElement`>>; }> -Defined in: [packages/mermaid/src/rendering-util/layout-algorithms/common/index.ts:156](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/rendering-util/layout-algorithms/common/index.ts#L156) +Defined in: [packages/mermaid/src/rendering-util/layout-algorithms/common/index.ts:164](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/rendering-util/layout-algorithms/common/index.ts#L164) ## Parameters diff --git a/docs/config/setup/mermaid/functions/paintLayoutData.md b/docs/config/setup/mermaid/functions/paintLayoutData.md index 220d14c723c..e0b16a5a9f2 100644 --- a/docs/config/setup/mermaid/functions/paintLayoutData.md +++ b/docs/config/setup/mermaid/functions/paintLayoutData.md @@ -10,9 +10,9 @@ # Function: paintLayoutData() -> **paintLayoutData**(`data4Layout`, `__namedParameters`, `options`): `Promise`<`void`> +> **paintLayoutData**(`data4Layout`, `context`, `options`): `Promise`<`void`> -Defined in: [packages/mermaid/src/rendering-util/layout-algorithms/common/index.ts:163](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/rendering-util/layout-algorithms/common/index.ts#L163) +Defined in: [packages/mermaid/src/rendering-util/layout-algorithms/common/index.ts:171](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/rendering-util/layout-algorithms/common/index.ts#L171) ## Parameters @@ -20,7 +20,7 @@ Defined in: [packages/mermaid/src/rendering-util/layout-algorithms/common/index. [`LayoutData`](../interfaces/LayoutData.md) -### \_\_namedParameters +### context [`CommonLayoutPaintContext`](../interfaces/CommonLayoutPaintContext.md)<`unknown`, { `graph`: `Graph`; `groups`: { `clusters`: `D3Selection`<`SVGGElement`>; `edgeLabels`: `D3Selection`<`SVGGElement`>; `edgePaths`: `D3Selection`<`SVGGElement`>; `nodes`: `D3Selection`<`SVGGElement`>; `rootGroups`: `D3Selection`<`SVGGElement`>; }; `nodeElements`: `Map`<`string`, `D3Selection`<`SVGElement` | `SVGGElement`>>; }> diff --git a/docs/config/setup/mermaid/interfaces/CommonLayoutPaintOptions.md b/docs/config/setup/mermaid/interfaces/CommonLayoutPaintOptions.md index e2cf8cff09b..cae1d66d34e 100644 --- a/docs/config/setup/mermaid/interfaces/CommonLayoutPaintOptions.md +++ b/docs/config/setup/mermaid/interfaces/CommonLayoutPaintOptions.md @@ -22,11 +22,33 @@ Defined in: [packages/mermaid/src/rendering-util/layout-algorithms/common/index. --- +### isCluster()? + +> `optional` **isCluster**: (`node`, `context`) => `boolean` + +Defined in: [packages/mermaid/src/rendering-util/layout-algorithms/common/index.ts:62](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/rendering-util/layout-algorithms/common/index.ts#L62) + +#### Parameters + +##### node + +`Node` + +##### context + +[`CommonLayoutPaintContext`](CommonLayoutPaintContext.md)<`unknown`, { `graph`: `Graph`; `groups`: { `clusters`: `D3Selection`<`SVGGElement`>; `edgeLabels`: `D3Selection`<`SVGGElement`>; `edgePaths`: `D3Selection`<`SVGGElement`>; `nodes`: `D3Selection`<`SVGGElement`>; `rootGroups`: `D3Selection`<`SVGGElement`>; }; `nodeElements`: `Map`<`string`, `D3Selection`<`SVGElement` | `SVGGElement`>>; }> + +#### Returns + +`boolean` + +--- + ### skipEdge()? > `optional` **skipEdge**: (`edge`) => `boolean` -Defined in: [packages/mermaid/src/rendering-util/layout-algorithms/common/index.ts:58](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/rendering-util/layout-algorithms/common/index.ts#L58) +Defined in: [packages/mermaid/src/rendering-util/layout-algorithms/common/index.ts:66](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/rendering-util/layout-algorithms/common/index.ts#L66) #### Parameters @@ -44,4 +66,26 @@ Defined in: [packages/mermaid/src/rendering-util/layout-algorithms/common/index. > `optional` **skipIntersect**: `boolean` | (`edge`) => `boolean` -Defined in: [packages/mermaid/src/rendering-util/layout-algorithms/common/index.ts:59](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/rendering-util/layout-algorithms/common/index.ts#L59) +Defined in: [packages/mermaid/src/rendering-util/layout-algorithms/common/index.ts:67](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/rendering-util/layout-algorithms/common/index.ts#L67) + +--- + +### skipNode()? + +> `optional` **skipNode**: (`node`, `context`) => `boolean` + +Defined in: [packages/mermaid/src/rendering-util/layout-algorithms/common/index.ts:58](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/rendering-util/layout-algorithms/common/index.ts#L58) + +#### Parameters + +##### node + +`Node` + +##### context + +[`CommonLayoutPaintContext`](CommonLayoutPaintContext.md)<`unknown`, { `graph`: `Graph`; `groups`: { `clusters`: `D3Selection`<`SVGGElement`>; `edgeLabels`: `D3Selection`<`SVGGElement`>; `edgePaths`: `D3Selection`<`SVGGElement`>; `nodes`: `D3Selection`<`SVGGElement`>; `rootGroups`: `D3Selection`<`SVGGElement`>; }; `nodeElements`: `Map`<`string`, `D3Selection`<`SVGElement` | `SVGGElement`>>; }> + +#### Returns + +`boolean` diff --git a/docs/config/setup/mermaid/interfaces/CommonLayoutRendererDefinition.md b/docs/config/setup/mermaid/interfaces/CommonLayoutRendererDefinition.md index 0abb767be5d..f571d7e7469 100644 --- a/docs/config/setup/mermaid/interfaces/CommonLayoutRendererDefinition.md +++ b/docs/config/setup/mermaid/interfaces/CommonLayoutRendererDefinition.md @@ -10,7 +10,7 @@ # Interface: CommonLayoutRendererDefinition\ -Defined in: [packages/mermaid/src/rendering-util/layout-algorithms/common/index.ts:62](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/rendering-util/layout-algorithms/common/index.ts#L62) +Defined in: [packages/mermaid/src/rendering-util/layout-algorithms/common/index.ts:70](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/rendering-util/layout-algorithms/common/index.ts#L70) ## Type Parameters @@ -32,7 +32,7 @@ Defined in: [packages/mermaid/src/rendering-util/layout-algorithms/common/index. > `optional` **afterPaint**: (`data4Layout`, `context`, `coreResult`) => `void` | `Promise`<`void`> -Defined in: [packages/mermaid/src/rendering-util/layout-algorithms/common/index.ts:84](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/rendering-util/layout-algorithms/common/index.ts#L84) +Defined in: [packages/mermaid/src/rendering-util/layout-algorithms/common/index.ts:92](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/rendering-util/layout-algorithms/common/index.ts#L92) #### Parameters @@ -58,7 +58,7 @@ Defined in: [packages/mermaid/src/rendering-util/layout-algorithms/common/index. > `optional` **measureLayout**: (`data4Layout`, `context`) => `Promise`<`MeasureResult`> -Defined in: [packages/mermaid/src/rendering-util/layout-algorithms/common/index.ts:71](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/rendering-util/layout-algorithms/common/index.ts#L71) +Defined in: [packages/mermaid/src/rendering-util/layout-algorithms/common/index.ts:79](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/rendering-util/layout-algorithms/common/index.ts#L79) #### Parameters @@ -80,7 +80,7 @@ Defined in: [packages/mermaid/src/rendering-util/layout-algorithms/common/index. > `optional` **paintLayout**: (`data4Layout`, `context`, `coreResult`) => `void` | `Promise`<`void`> -Defined in: [packages/mermaid/src/rendering-util/layout-algorithms/common/index.ts:79](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/rendering-util/layout-algorithms/common/index.ts#L79) +Defined in: [packages/mermaid/src/rendering-util/layout-algorithms/common/index.ts:87](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/rendering-util/layout-algorithms/common/index.ts#L87) #### Parameters @@ -106,7 +106,7 @@ Defined in: [packages/mermaid/src/rendering-util/layout-algorithms/common/index. > `optional` **paintOptions**: [`CommonLayoutPaintOptions`](CommonLayoutPaintOptions.md) -Defined in: [packages/mermaid/src/rendering-util/layout-algorithms/common/index.ts:89](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/rendering-util/layout-algorithms/common/index.ts#L89) +Defined in: [packages/mermaid/src/rendering-util/layout-algorithms/common/index.ts:97](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/rendering-util/layout-algorithms/common/index.ts#L97) --- @@ -114,7 +114,7 @@ Defined in: [packages/mermaid/src/rendering-util/layout-algorithms/common/index. > `optional` **prepareLayout**: (`data4Layout`, `context`) => `PreparedLayout` | `Promise`<`PreparedLayout`> -Defined in: [packages/mermaid/src/rendering-util/layout-algorithms/common/index.ts:67](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/rendering-util/layout-algorithms/common/index.ts#L67) +Defined in: [packages/mermaid/src/rendering-util/layout-algorithms/common/index.ts:75](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/rendering-util/layout-algorithms/common/index.ts#L75) #### Parameters @@ -136,7 +136,7 @@ Defined in: [packages/mermaid/src/rendering-util/layout-algorithms/common/index. > **runLayoutCore**: (`data4Layout`, `context`) => `CoreResult` | `Promise`<`CoreResult`> -Defined in: [packages/mermaid/src/rendering-util/layout-algorithms/common/index.ts:75](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/rendering-util/layout-algorithms/common/index.ts#L75) +Defined in: [packages/mermaid/src/rendering-util/layout-algorithms/common/index.ts:83](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/rendering-util/layout-algorithms/common/index.ts#L83) #### Parameters From a1afff974f13b1917405ab38f35a2a7157f6a997 Mon Sep 17 00:00:00 2001 From: "autofix-ci[bot]" <114827586+autofix-ci[bot]@users.noreply.github.com> Date: Tue, 9 Jun 2026 11:07:06 +0000 Subject: [PATCH 06/13] [autofix.ci] apply automated fixes --- .../functions/clearLayoutRenderState.md | 2 +- .../functions/createCommonLayoutRenderer.md | 2 +- .../mermaid/functions/defaultMeasureLayout.md | 2 +- .../mermaid/functions/paintLayoutData.md | 6 +-- .../interfaces/CommonLayoutPaintOptions.md | 48 ++++++++++++++++++- .../CommonLayoutRendererDefinition.md | 14 +++--- 6 files changed, 59 insertions(+), 15 deletions(-) diff --git a/docs/config/setup/mermaid/functions/clearLayoutRenderState.md b/docs/config/setup/mermaid/functions/clearLayoutRenderState.md index 2c93b004ed6..7693435a948 100644 --- a/docs/config/setup/mermaid/functions/clearLayoutRenderState.md +++ b/docs/config/setup/mermaid/functions/clearLayoutRenderState.md @@ -12,7 +12,7 @@ > **clearLayoutRenderState**(): `void` -Defined in: [packages/mermaid/src/rendering-util/layout-algorithms/common/index.ts:149](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/rendering-util/layout-algorithms/common/index.ts#L149) +Defined in: [packages/mermaid/src/rendering-util/layout-algorithms/common/index.ts:157](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/rendering-util/layout-algorithms/common/index.ts#L157) ## Returns diff --git a/docs/config/setup/mermaid/functions/createCommonLayoutRenderer.md b/docs/config/setup/mermaid/functions/createCommonLayoutRenderer.md index 58a60621517..99fccb28eea 100644 --- a/docs/config/setup/mermaid/functions/createCommonLayoutRenderer.md +++ b/docs/config/setup/mermaid/functions/createCommonLayoutRenderer.md @@ -12,7 +12,7 @@ > **createCommonLayoutRenderer**<`CoreResult`, `PreparedLayout`, `MeasureResult`>(`__namedParameters`): (`data4Layout`, `svg`, `helpers?`, `options?`, `positions?`) => `Promise`<`void`> -Defined in: [packages/mermaid/src/rendering-util/layout-algorithms/common/index.ts:92](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/rendering-util/layout-algorithms/common/index.ts#L92) +Defined in: [packages/mermaid/src/rendering-util/layout-algorithms/common/index.ts:100](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/rendering-util/layout-algorithms/common/index.ts#L100) ## Type Parameters diff --git a/docs/config/setup/mermaid/functions/defaultMeasureLayout.md b/docs/config/setup/mermaid/functions/defaultMeasureLayout.md index bec5a7b4d66..ddf66067151 100644 --- a/docs/config/setup/mermaid/functions/defaultMeasureLayout.md +++ b/docs/config/setup/mermaid/functions/defaultMeasureLayout.md @@ -12,7 +12,7 @@ > **defaultMeasureLayout**(`data4Layout`, `__namedParameters`): `Promise`<{ `graph`: `Graph`; `groups`: { `clusters`: `D3Selection`<`SVGGElement`>; `edgeLabels`: `D3Selection`<`SVGGElement`>; `edgePaths`: `D3Selection`<`SVGGElement`>; `nodes`: `D3Selection`<`SVGGElement`>; `rootGroups`: `D3Selection`<`SVGGElement`>; }; `nodeElements`: `Map`<`string`, `D3Selection`<`SVGElement` | `SVGGElement`>>; }> -Defined in: [packages/mermaid/src/rendering-util/layout-algorithms/common/index.ts:156](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/rendering-util/layout-algorithms/common/index.ts#L156) +Defined in: [packages/mermaid/src/rendering-util/layout-algorithms/common/index.ts:164](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/rendering-util/layout-algorithms/common/index.ts#L164) ## Parameters diff --git a/docs/config/setup/mermaid/functions/paintLayoutData.md b/docs/config/setup/mermaid/functions/paintLayoutData.md index 220d14c723c..e0b16a5a9f2 100644 --- a/docs/config/setup/mermaid/functions/paintLayoutData.md +++ b/docs/config/setup/mermaid/functions/paintLayoutData.md @@ -10,9 +10,9 @@ # Function: paintLayoutData() -> **paintLayoutData**(`data4Layout`, `__namedParameters`, `options`): `Promise`<`void`> +> **paintLayoutData**(`data4Layout`, `context`, `options`): `Promise`<`void`> -Defined in: [packages/mermaid/src/rendering-util/layout-algorithms/common/index.ts:163](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/rendering-util/layout-algorithms/common/index.ts#L163) +Defined in: [packages/mermaid/src/rendering-util/layout-algorithms/common/index.ts:171](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/rendering-util/layout-algorithms/common/index.ts#L171) ## Parameters @@ -20,7 +20,7 @@ Defined in: [packages/mermaid/src/rendering-util/layout-algorithms/common/index. [`LayoutData`](../interfaces/LayoutData.md) -### \_\_namedParameters +### context [`CommonLayoutPaintContext`](../interfaces/CommonLayoutPaintContext.md)<`unknown`, { `graph`: `Graph`; `groups`: { `clusters`: `D3Selection`<`SVGGElement`>; `edgeLabels`: `D3Selection`<`SVGGElement`>; `edgePaths`: `D3Selection`<`SVGGElement`>; `nodes`: `D3Selection`<`SVGGElement`>; `rootGroups`: `D3Selection`<`SVGGElement`>; }; `nodeElements`: `Map`<`string`, `D3Selection`<`SVGElement` | `SVGGElement`>>; }> diff --git a/docs/config/setup/mermaid/interfaces/CommonLayoutPaintOptions.md b/docs/config/setup/mermaid/interfaces/CommonLayoutPaintOptions.md index e2cf8cff09b..cae1d66d34e 100644 --- a/docs/config/setup/mermaid/interfaces/CommonLayoutPaintOptions.md +++ b/docs/config/setup/mermaid/interfaces/CommonLayoutPaintOptions.md @@ -22,11 +22,33 @@ Defined in: [packages/mermaid/src/rendering-util/layout-algorithms/common/index. --- +### isCluster()? + +> `optional` **isCluster**: (`node`, `context`) => `boolean` + +Defined in: [packages/mermaid/src/rendering-util/layout-algorithms/common/index.ts:62](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/rendering-util/layout-algorithms/common/index.ts#L62) + +#### Parameters + +##### node + +`Node` + +##### context + +[`CommonLayoutPaintContext`](CommonLayoutPaintContext.md)<`unknown`, { `graph`: `Graph`; `groups`: { `clusters`: `D3Selection`<`SVGGElement`>; `edgeLabels`: `D3Selection`<`SVGGElement`>; `edgePaths`: `D3Selection`<`SVGGElement`>; `nodes`: `D3Selection`<`SVGGElement`>; `rootGroups`: `D3Selection`<`SVGGElement`>; }; `nodeElements`: `Map`<`string`, `D3Selection`<`SVGElement` | `SVGGElement`>>; }> + +#### Returns + +`boolean` + +--- + ### skipEdge()? > `optional` **skipEdge**: (`edge`) => `boolean` -Defined in: [packages/mermaid/src/rendering-util/layout-algorithms/common/index.ts:58](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/rendering-util/layout-algorithms/common/index.ts#L58) +Defined in: [packages/mermaid/src/rendering-util/layout-algorithms/common/index.ts:66](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/rendering-util/layout-algorithms/common/index.ts#L66) #### Parameters @@ -44,4 +66,26 @@ Defined in: [packages/mermaid/src/rendering-util/layout-algorithms/common/index. > `optional` **skipIntersect**: `boolean` | (`edge`) => `boolean` -Defined in: [packages/mermaid/src/rendering-util/layout-algorithms/common/index.ts:59](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/rendering-util/layout-algorithms/common/index.ts#L59) +Defined in: [packages/mermaid/src/rendering-util/layout-algorithms/common/index.ts:67](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/rendering-util/layout-algorithms/common/index.ts#L67) + +--- + +### skipNode()? + +> `optional` **skipNode**: (`node`, `context`) => `boolean` + +Defined in: [packages/mermaid/src/rendering-util/layout-algorithms/common/index.ts:58](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/rendering-util/layout-algorithms/common/index.ts#L58) + +#### Parameters + +##### node + +`Node` + +##### context + +[`CommonLayoutPaintContext`](CommonLayoutPaintContext.md)<`unknown`, { `graph`: `Graph`; `groups`: { `clusters`: `D3Selection`<`SVGGElement`>; `edgeLabels`: `D3Selection`<`SVGGElement`>; `edgePaths`: `D3Selection`<`SVGGElement`>; `nodes`: `D3Selection`<`SVGGElement`>; `rootGroups`: `D3Selection`<`SVGGElement`>; }; `nodeElements`: `Map`<`string`, `D3Selection`<`SVGElement` | `SVGGElement`>>; }> + +#### Returns + +`boolean` diff --git a/docs/config/setup/mermaid/interfaces/CommonLayoutRendererDefinition.md b/docs/config/setup/mermaid/interfaces/CommonLayoutRendererDefinition.md index 0abb767be5d..f571d7e7469 100644 --- a/docs/config/setup/mermaid/interfaces/CommonLayoutRendererDefinition.md +++ b/docs/config/setup/mermaid/interfaces/CommonLayoutRendererDefinition.md @@ -10,7 +10,7 @@ # Interface: CommonLayoutRendererDefinition\ -Defined in: [packages/mermaid/src/rendering-util/layout-algorithms/common/index.ts:62](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/rendering-util/layout-algorithms/common/index.ts#L62) +Defined in: [packages/mermaid/src/rendering-util/layout-algorithms/common/index.ts:70](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/rendering-util/layout-algorithms/common/index.ts#L70) ## Type Parameters @@ -32,7 +32,7 @@ Defined in: [packages/mermaid/src/rendering-util/layout-algorithms/common/index. > `optional` **afterPaint**: (`data4Layout`, `context`, `coreResult`) => `void` | `Promise`<`void`> -Defined in: [packages/mermaid/src/rendering-util/layout-algorithms/common/index.ts:84](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/rendering-util/layout-algorithms/common/index.ts#L84) +Defined in: [packages/mermaid/src/rendering-util/layout-algorithms/common/index.ts:92](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/rendering-util/layout-algorithms/common/index.ts#L92) #### Parameters @@ -58,7 +58,7 @@ Defined in: [packages/mermaid/src/rendering-util/layout-algorithms/common/index. > `optional` **measureLayout**: (`data4Layout`, `context`) => `Promise`<`MeasureResult`> -Defined in: [packages/mermaid/src/rendering-util/layout-algorithms/common/index.ts:71](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/rendering-util/layout-algorithms/common/index.ts#L71) +Defined in: [packages/mermaid/src/rendering-util/layout-algorithms/common/index.ts:79](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/rendering-util/layout-algorithms/common/index.ts#L79) #### Parameters @@ -80,7 +80,7 @@ Defined in: [packages/mermaid/src/rendering-util/layout-algorithms/common/index. > `optional` **paintLayout**: (`data4Layout`, `context`, `coreResult`) => `void` | `Promise`<`void`> -Defined in: [packages/mermaid/src/rendering-util/layout-algorithms/common/index.ts:79](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/rendering-util/layout-algorithms/common/index.ts#L79) +Defined in: [packages/mermaid/src/rendering-util/layout-algorithms/common/index.ts:87](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/rendering-util/layout-algorithms/common/index.ts#L87) #### Parameters @@ -106,7 +106,7 @@ Defined in: [packages/mermaid/src/rendering-util/layout-algorithms/common/index. > `optional` **paintOptions**: [`CommonLayoutPaintOptions`](CommonLayoutPaintOptions.md) -Defined in: [packages/mermaid/src/rendering-util/layout-algorithms/common/index.ts:89](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/rendering-util/layout-algorithms/common/index.ts#L89) +Defined in: [packages/mermaid/src/rendering-util/layout-algorithms/common/index.ts:97](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/rendering-util/layout-algorithms/common/index.ts#L97) --- @@ -114,7 +114,7 @@ Defined in: [packages/mermaid/src/rendering-util/layout-algorithms/common/index. > `optional` **prepareLayout**: (`data4Layout`, `context`) => `PreparedLayout` | `Promise`<`PreparedLayout`> -Defined in: [packages/mermaid/src/rendering-util/layout-algorithms/common/index.ts:67](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/rendering-util/layout-algorithms/common/index.ts#L67) +Defined in: [packages/mermaid/src/rendering-util/layout-algorithms/common/index.ts:75](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/rendering-util/layout-algorithms/common/index.ts#L75) #### Parameters @@ -136,7 +136,7 @@ Defined in: [packages/mermaid/src/rendering-util/layout-algorithms/common/index. > **runLayoutCore**: (`data4Layout`, `context`) => `CoreResult` | `Promise`<`CoreResult`> -Defined in: [packages/mermaid/src/rendering-util/layout-algorithms/common/index.ts:75](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/rendering-util/layout-algorithms/common/index.ts#L75) +Defined in: [packages/mermaid/src/rendering-util/layout-algorithms/common/index.ts:83](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/rendering-util/layout-algorithms/common/index.ts#L83) #### Parameters From 20f034c336ff755d690b2ee4408f7b0620c70005 Mon Sep 17 00:00:00 2001 From: knsv Date: Tue, 9 Jun 2026 14:37:56 +0200 Subject: [PATCH 07/13] Fix dagre shared paint graph-backed rendering --- .../functions/clearLayoutRenderState.md | 2 +- .../functions/createCommonLayoutRenderer.md | 2 +- .../mermaid/functions/defaultMeasureLayout.md | 2 +- .../mermaid/functions/paintLayoutData.md | 2 +- .../interfaces/CommonLayoutPaintOptions.md | 56 +++++++++++- .../CommonLayoutRendererDefinition.md | 14 +-- .../layout-algorithms/common/index.spec.ts | 30 +++++++ .../layout-algorithms/common/index.ts | 27 ++++-- .../layout-algorithms/dagre/index.js | 12 +++ .../layout-algorithms/dagre/index.spec.js | 89 +++++++++++++++++++ 10 files changed, 214 insertions(+), 22 deletions(-) diff --git a/docs/config/setup/mermaid/functions/clearLayoutRenderState.md b/docs/config/setup/mermaid/functions/clearLayoutRenderState.md index 7693435a948..aea439a7c6b 100644 --- a/docs/config/setup/mermaid/functions/clearLayoutRenderState.md +++ b/docs/config/setup/mermaid/functions/clearLayoutRenderState.md @@ -12,7 +12,7 @@ > **clearLayoutRenderState**(): `void` -Defined in: [packages/mermaid/src/rendering-util/layout-algorithms/common/index.ts:157](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/rendering-util/layout-algorithms/common/index.ts#L157) +Defined in: [packages/mermaid/src/rendering-util/layout-algorithms/common/index.ts:166](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/rendering-util/layout-algorithms/common/index.ts#L166) ## Returns diff --git a/docs/config/setup/mermaid/functions/createCommonLayoutRenderer.md b/docs/config/setup/mermaid/functions/createCommonLayoutRenderer.md index 99fccb28eea..487cab2b403 100644 --- a/docs/config/setup/mermaid/functions/createCommonLayoutRenderer.md +++ b/docs/config/setup/mermaid/functions/createCommonLayoutRenderer.md @@ -12,7 +12,7 @@ > **createCommonLayoutRenderer**<`CoreResult`, `PreparedLayout`, `MeasureResult`>(`__namedParameters`): (`data4Layout`, `svg`, `helpers?`, `options?`, `positions?`) => `Promise`<`void`> -Defined in: [packages/mermaid/src/rendering-util/layout-algorithms/common/index.ts:100](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/rendering-util/layout-algorithms/common/index.ts#L100) +Defined in: [packages/mermaid/src/rendering-util/layout-algorithms/common/index.ts:109](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/rendering-util/layout-algorithms/common/index.ts#L109) ## Type Parameters diff --git a/docs/config/setup/mermaid/functions/defaultMeasureLayout.md b/docs/config/setup/mermaid/functions/defaultMeasureLayout.md index ddf66067151..22cc4431a02 100644 --- a/docs/config/setup/mermaid/functions/defaultMeasureLayout.md +++ b/docs/config/setup/mermaid/functions/defaultMeasureLayout.md @@ -12,7 +12,7 @@ > **defaultMeasureLayout**(`data4Layout`, `__namedParameters`): `Promise`<{ `graph`: `Graph`; `groups`: { `clusters`: `D3Selection`<`SVGGElement`>; `edgeLabels`: `D3Selection`<`SVGGElement`>; `edgePaths`: `D3Selection`<`SVGGElement`>; `nodes`: `D3Selection`<`SVGGElement`>; `rootGroups`: `D3Selection`<`SVGGElement`>; }; `nodeElements`: `Map`<`string`, `D3Selection`<`SVGElement` | `SVGGElement`>>; }> -Defined in: [packages/mermaid/src/rendering-util/layout-algorithms/common/index.ts:164](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/rendering-util/layout-algorithms/common/index.ts#L164) +Defined in: [packages/mermaid/src/rendering-util/layout-algorithms/common/index.ts:173](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/rendering-util/layout-algorithms/common/index.ts#L173) ## Parameters diff --git a/docs/config/setup/mermaid/functions/paintLayoutData.md b/docs/config/setup/mermaid/functions/paintLayoutData.md index e0b16a5a9f2..5b8faec326c 100644 --- a/docs/config/setup/mermaid/functions/paintLayoutData.md +++ b/docs/config/setup/mermaid/functions/paintLayoutData.md @@ -12,7 +12,7 @@ > **paintLayoutData**(`data4Layout`, `context`, `options`): `Promise`<`void`> -Defined in: [packages/mermaid/src/rendering-util/layout-algorithms/common/index.ts:171](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/rendering-util/layout-algorithms/common/index.ts#L171) +Defined in: [packages/mermaid/src/rendering-util/layout-algorithms/common/index.ts:180](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/rendering-util/layout-algorithms/common/index.ts#L180) ## Parameters diff --git a/docs/config/setup/mermaid/interfaces/CommonLayoutPaintOptions.md b/docs/config/setup/mermaid/interfaces/CommonLayoutPaintOptions.md index cae1d66d34e..2f3ca8d6b87 100644 --- a/docs/config/setup/mermaid/interfaces/CommonLayoutPaintOptions.md +++ b/docs/config/setup/mermaid/interfaces/CommonLayoutPaintOptions.md @@ -22,11 +22,59 @@ Defined in: [packages/mermaid/src/rendering-util/layout-algorithms/common/index. --- +### getEdgeNode()? + +> `optional` **getEdgeNode**: (`id`, `edge`, `context`) => `object` | `Node` | `undefined` + +Defined in: [packages/mermaid/src/rendering-util/layout-algorithms/common/index.ts:62](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/rendering-util/layout-algorithms/common/index.ts#L62) + +#### Parameters + +##### id + +`string` | `undefined` + +##### edge + +`Edge` + +##### context + +[`CommonLayoutPaintContext`](CommonLayoutPaintContext.md)<`unknown`, { `graph`: `Graph`; `groups`: { `clusters`: `D3Selection`<`SVGGElement`>; `edgeLabels`: `D3Selection`<`SVGGElement`>; `edgePaths`: `D3Selection`<`SVGGElement`>; `nodes`: `D3Selection`<`SVGGElement`>; `rootGroups`: `D3Selection`<`SVGGElement`>; }; `nodeElements`: `Map`<`string`, `D3Selection`<`SVGElement` | `SVGGElement`>>; }> + +#### Returns + +`object` | `Node` | `undefined` + +--- + +### getNodes()? + +> `optional` **getNodes**: (`data4Layout`, `context`) => `Iterable`<`Node`> + +Defined in: [packages/mermaid/src/rendering-util/layout-algorithms/common/index.ts:58](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/rendering-util/layout-algorithms/common/index.ts#L58) + +#### Parameters + +##### data4Layout + +[`LayoutData`](LayoutData.md) + +##### context + +[`CommonLayoutPaintContext`](CommonLayoutPaintContext.md)<`unknown`, { `graph`: `Graph`; `groups`: { `clusters`: `D3Selection`<`SVGGElement`>; `edgeLabels`: `D3Selection`<`SVGGElement`>; `edgePaths`: `D3Selection`<`SVGGElement`>; `nodes`: `D3Selection`<`SVGGElement`>; `rootGroups`: `D3Selection`<`SVGGElement`>; }; `nodeElements`: `Map`<`string`, `D3Selection`<`SVGElement` | `SVGGElement`>>; }> + +#### Returns + +`Iterable`<`Node`> + +--- + ### isCluster()? > `optional` **isCluster**: (`node`, `context`) => `boolean` -Defined in: [packages/mermaid/src/rendering-util/layout-algorithms/common/index.ts:62](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/rendering-util/layout-algorithms/common/index.ts#L62) +Defined in: [packages/mermaid/src/rendering-util/layout-algorithms/common/index.ts:71](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/rendering-util/layout-algorithms/common/index.ts#L71) #### Parameters @@ -48,7 +96,7 @@ Defined in: [packages/mermaid/src/rendering-util/layout-algorithms/common/index. > `optional` **skipEdge**: (`edge`) => `boolean` -Defined in: [packages/mermaid/src/rendering-util/layout-algorithms/common/index.ts:66](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/rendering-util/layout-algorithms/common/index.ts#L66) +Defined in: [packages/mermaid/src/rendering-util/layout-algorithms/common/index.ts:75](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/rendering-util/layout-algorithms/common/index.ts#L75) #### Parameters @@ -66,7 +114,7 @@ Defined in: [packages/mermaid/src/rendering-util/layout-algorithms/common/index. > `optional` **skipIntersect**: `boolean` | (`edge`) => `boolean` -Defined in: [packages/mermaid/src/rendering-util/layout-algorithms/common/index.ts:67](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/rendering-util/layout-algorithms/common/index.ts#L67) +Defined in: [packages/mermaid/src/rendering-util/layout-algorithms/common/index.ts:76](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/rendering-util/layout-algorithms/common/index.ts#L76) --- @@ -74,7 +122,7 @@ Defined in: [packages/mermaid/src/rendering-util/layout-algorithms/common/index. > `optional` **skipNode**: (`node`, `context`) => `boolean` -Defined in: [packages/mermaid/src/rendering-util/layout-algorithms/common/index.ts:58](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/rendering-util/layout-algorithms/common/index.ts#L58) +Defined in: [packages/mermaid/src/rendering-util/layout-algorithms/common/index.ts:67](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/rendering-util/layout-algorithms/common/index.ts#L67) #### Parameters diff --git a/docs/config/setup/mermaid/interfaces/CommonLayoutRendererDefinition.md b/docs/config/setup/mermaid/interfaces/CommonLayoutRendererDefinition.md index f571d7e7469..5237a251240 100644 --- a/docs/config/setup/mermaid/interfaces/CommonLayoutRendererDefinition.md +++ b/docs/config/setup/mermaid/interfaces/CommonLayoutRendererDefinition.md @@ -10,7 +10,7 @@ # Interface: CommonLayoutRendererDefinition\ -Defined in: [packages/mermaid/src/rendering-util/layout-algorithms/common/index.ts:70](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/rendering-util/layout-algorithms/common/index.ts#L70) +Defined in: [packages/mermaid/src/rendering-util/layout-algorithms/common/index.ts:79](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/rendering-util/layout-algorithms/common/index.ts#L79) ## Type Parameters @@ -32,7 +32,7 @@ Defined in: [packages/mermaid/src/rendering-util/layout-algorithms/common/index. > `optional` **afterPaint**: (`data4Layout`, `context`, `coreResult`) => `void` | `Promise`<`void`> -Defined in: [packages/mermaid/src/rendering-util/layout-algorithms/common/index.ts:92](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/rendering-util/layout-algorithms/common/index.ts#L92) +Defined in: [packages/mermaid/src/rendering-util/layout-algorithms/common/index.ts:101](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/rendering-util/layout-algorithms/common/index.ts#L101) #### Parameters @@ -58,7 +58,7 @@ Defined in: [packages/mermaid/src/rendering-util/layout-algorithms/common/index. > `optional` **measureLayout**: (`data4Layout`, `context`) => `Promise`<`MeasureResult`> -Defined in: [packages/mermaid/src/rendering-util/layout-algorithms/common/index.ts:79](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/rendering-util/layout-algorithms/common/index.ts#L79) +Defined in: [packages/mermaid/src/rendering-util/layout-algorithms/common/index.ts:88](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/rendering-util/layout-algorithms/common/index.ts#L88) #### Parameters @@ -80,7 +80,7 @@ Defined in: [packages/mermaid/src/rendering-util/layout-algorithms/common/index. > `optional` **paintLayout**: (`data4Layout`, `context`, `coreResult`) => `void` | `Promise`<`void`> -Defined in: [packages/mermaid/src/rendering-util/layout-algorithms/common/index.ts:87](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/rendering-util/layout-algorithms/common/index.ts#L87) +Defined in: [packages/mermaid/src/rendering-util/layout-algorithms/common/index.ts:96](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/rendering-util/layout-algorithms/common/index.ts#L96) #### Parameters @@ -106,7 +106,7 @@ Defined in: [packages/mermaid/src/rendering-util/layout-algorithms/common/index. > `optional` **paintOptions**: [`CommonLayoutPaintOptions`](CommonLayoutPaintOptions.md) -Defined in: [packages/mermaid/src/rendering-util/layout-algorithms/common/index.ts:97](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/rendering-util/layout-algorithms/common/index.ts#L97) +Defined in: [packages/mermaid/src/rendering-util/layout-algorithms/common/index.ts:106](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/rendering-util/layout-algorithms/common/index.ts#L106) --- @@ -114,7 +114,7 @@ Defined in: [packages/mermaid/src/rendering-util/layout-algorithms/common/index. > `optional` **prepareLayout**: (`data4Layout`, `context`) => `PreparedLayout` | `Promise`<`PreparedLayout`> -Defined in: [packages/mermaid/src/rendering-util/layout-algorithms/common/index.ts:75](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/rendering-util/layout-algorithms/common/index.ts#L75) +Defined in: [packages/mermaid/src/rendering-util/layout-algorithms/common/index.ts:84](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/rendering-util/layout-algorithms/common/index.ts#L84) #### Parameters @@ -136,7 +136,7 @@ Defined in: [packages/mermaid/src/rendering-util/layout-algorithms/common/index. > **runLayoutCore**: (`data4Layout`, `context`) => `CoreResult` | `Promise`<`CoreResult`> -Defined in: [packages/mermaid/src/rendering-util/layout-algorithms/common/index.ts:83](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/rendering-util/layout-algorithms/common/index.ts#L83) +Defined in: [packages/mermaid/src/rendering-util/layout-algorithms/common/index.ts:92](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/rendering-util/layout-algorithms/common/index.ts#L92) #### Parameters diff --git a/packages/mermaid/src/rendering-util/layout-algorithms/common/index.spec.ts b/packages/mermaid/src/rendering-util/layout-algorithms/common/index.spec.ts index 4a1e64def98..0bcfb335350 100644 --- a/packages/mermaid/src/rendering-util/layout-algorithms/common/index.spec.ts +++ b/packages/mermaid/src/rendering-util/layout-algorithms/common/index.spec.ts @@ -385,6 +385,36 @@ describe('paintLayoutData', () => { expect(mocks.positionNode).not.toHaveBeenCalledWith(extractedNode); }); + it('lets layout algorithms provide graph-backed paint nodes and edge endpoints', async () => { + const { paintLayoutData } = await import('./index.js'); + const nodeB = node('B'); + const graphOnlyNode = node('dummy'); + const renderEdge = edge('render', { start: graphOnlyNode.id, end: nodeB.id }); + const data = layout({ + nodes: [nodeB], + edges: [renderEdge], + }); + const measured = measure(); + + await paintLayoutData(data, { measure: measured } as never, { + getNodes: () => [graphOnlyNode, nodeB], + getEdgeNode: (id) => (id === graphOnlyNode.id ? graphOnlyNode : undefined), + }); + + expect(mocks.positionNode).toHaveBeenNthCalledWith(1, graphOnlyNode); + expect(mocks.positionNode).toHaveBeenNthCalledWith(2, nodeB); + expect(mocks.insertEdge).toHaveBeenCalledWith( + measured.groups.edgePaths, + { ...renderEdge }, + expect.any(Map), + data.type, + graphOnlyNode, + nodeB, + data.diagramId, + false + ); + }); + it('inserts and positions edge labels after drawing labelled edges', async () => { const { paintLayoutData } = await import('./index.js'); const labelledEdge = edge('labelled', { label: 'Yes', x: 0, y: 0 } as Partial); diff --git a/packages/mermaid/src/rendering-util/layout-algorithms/common/index.ts b/packages/mermaid/src/rendering-util/layout-algorithms/common/index.ts index 6fa57400ca6..e1a4822e47f 100644 --- a/packages/mermaid/src/rendering-util/layout-algorithms/common/index.ts +++ b/packages/mermaid/src/rendering-util/layout-algorithms/common/index.ts @@ -55,6 +55,15 @@ export interface CommonLayoutPaintContext< export interface CommonLayoutPaintOptions { clusterDb?: ClusterDb; + getNodes?: ( + data4Layout: LayoutData, + context: CommonLayoutPaintContext + ) => Iterable; + getEdgeNode?: ( + id: string | undefined, + edge: Edge, + context: CommonLayoutPaintContext + ) => LayoutData['nodes'][number] | object | undefined; skipNode?: ( node: LayoutData['nodes'][number], context: CommonLayoutPaintContext @@ -177,7 +186,7 @@ export async function paintLayoutData( const { groups } = measure; // Render clusters and position nodes; this also populates node.intersect on shapes. - for (const node of data4Layout.nodes) { + for (const node of options.getNodes?.(data4Layout, context) ?? data4Layout.nodes) { if (options.skipNode?.(node, context)) { continue; } @@ -191,7 +200,7 @@ export async function paintLayoutData( continue; } - await paintLayoutEdge(groups, edge, nodeById, data4Layout, options); + await paintLayoutEdge(groups, edge, nodeById, data4Layout, options, context); } } @@ -237,15 +246,16 @@ async function paintLayoutEdge( edge: Edge, nodeById: Map, data4Layout: LayoutData, - options: CommonLayoutPaintOptions + options: CommonLayoutPaintOptions, + context: CommonLayoutPaintContext ): Promise { const paths = insertEdge( groups.edgePaths, { ...edge }, options.clusterDb ?? EMPTY_CLUSTER_DB, data4Layout.type, - getRenderedNode(edge.start, nodeById), - getRenderedNode(edge.end, nodeById), + getRenderedNode(edge.start, edge, nodeById, context, options), + getRenderedNode(edge.end, edge, nodeById, context, options), data4Layout.diagramId, shouldSkipIntersect(edge, options) ) as EdgeRenderPaths | undefined; @@ -260,9 +270,12 @@ async function paintLayoutEdge( function getRenderedNode( id: string | undefined, - nodeById: Map + edge: Edge, + nodeById: Map, + context: CommonLayoutPaintContext, + options: CommonLayoutPaintOptions ): LayoutData['nodes'][number] | object { - return id ? (nodeById.get(id) ?? {}) : {}; + return options.getEdgeNode?.(id, edge, context) ?? (id ? (nodeById.get(id) ?? {}) : {}); } function shouldSkipIntersect(edge: Edge, options: CommonLayoutPaintOptions): boolean { diff --git a/packages/mermaid/src/rendering-util/layout-algorithms/dagre/index.js b/packages/mermaid/src/rendering-util/layout-algorithms/dagre/index.js index 2fca133f5e7..91e06b91ccd 100644 --- a/packages/mermaid/src/rendering-util/layout-algorithms/dagre/index.js +++ b/packages/mermaid/src/rendering-util/layout-algorithms/dagre/index.js @@ -740,12 +740,24 @@ export const runDagreLayoutCore = (_data4Layout, context) => { return measuredLayout; }; +const getDagrePaintNodes = (data4Layout, { measure }) => { + const nodeById = new Map(data4Layout.nodes.map((node) => [node.id, node])); + return sortNodesByHierarchy(measure.graph) + .map((nodeId) => nodeById.get(nodeId) ?? measure.graph.node(nodeId)) + .filter(Boolean); +}; + +const getDagreEdgeNode = (nodeId, _edge, { measure }) => + nodeId ? measure.graph.node(nodeId) : undefined; + export const render = createCommonLayoutRenderer({ prepareLayout: prepareLayoutForDagre, measureLayout: measureDagreLayout, runLayoutCore: runDagreLayoutCore, paintOptions: { clusterDb, + getNodes: getDagrePaintNodes, + getEdgeNode: getDagreEdgeNode, skipNode: (node, { measure }) => !measure.graph.hasNode(node.id), isCluster: (node, { measure }) => measure.graph.hasNode(node.id) && (measure.graph.children(node.id) ?? []).length > 0, diff --git a/packages/mermaid/src/rendering-util/layout-algorithms/dagre/index.spec.js b/packages/mermaid/src/rendering-util/layout-algorithms/dagre/index.spec.js index 76e2e51a559..043898d48b5 100644 --- a/packages/mermaid/src/rendering-util/layout-algorithms/dagre/index.spec.js +++ b/packages/mermaid/src/rendering-util/layout-algorithms/dagre/index.spec.js @@ -40,6 +40,19 @@ const setupDom = () => { }; }; +const getCyclicPaths = (document) => + [...document.querySelectorAll('.edgePaths path')].filter((path) => + path.getAttribute('data-id')?.includes('cyclic-special') + ); + +const expectFinitePaths = (paths) => { + for (const path of paths) { + const pathData = path.getAttribute('d'); + expect(pathData).toBeTruthy(); + expect(pathData).not.toMatch(/NaN|undefined/); + } +}; + describe('getEdgesToRender', () => { beforeAll(async () => { await mermaid.registerExternalDiagrams([]); @@ -458,6 +471,82 @@ C --> C` } }); + it('keeps reverse-order nested flowchart subgraphs visible through shared paint', async () => { + const restoreDom = setupDom(); + + try { + const { svg } = await mermaidAPI.render( + 'reverse-order-subgraph-test', + `flowchart LR + a -->b + subgraph A + B + end + subgraph B + b + end` + ); + const dom = new JSDOM(svg); + const clusters = [...dom.window.document.querySelectorAll('.cluster')]; + + expect(clusters).toHaveLength(2); + expect(clusters.map((cluster) => cluster.id)).toEqual( + expect.arrayContaining([ + expect.stringContaining('reverse-order-subgraph-test-A'), + expect.stringContaining('reverse-order-subgraph-test-B'), + ]) + ); + } finally { + restoreDom(); + } + }); + + it('renders recursive ER relationships with their dagre self-loop segments', async () => { + const restoreDom = setupDom(); + + try { + const { svg } = await mermaidAPI.render( + 'er-recursive-self-loop-test', + `erDiagram + CUSTOMER ||..o{ CUSTOMER : refers + CUSTOMER ||--o{ ORDER : places + ORDER ||--|{ LINE-ITEM : contains` + ); + const dom = new JSDOM(svg); + const cyclicPaths = getCyclicPaths(dom.window.document); + + expect(cyclicPaths).toHaveLength(3); + expectFinitePaths(cyclicPaths); + } finally { + restoreDom(); + } + }); + + it('renders class self-loops with multiplicity terminal labels', async () => { + const restoreDom = setupDom(); + + try { + const { svg } = await mermaidAPI.render( + 'class-recursive-self-loop-test', + `classDiagram + class SelfReferential{ + +int id + +int self_referential_id + +SelfReferential referenced + } + SelfReferential "1" --> "0..1" SelfReferential : referenced` + ); + const dom = new JSDOM(svg); + const cyclicPaths = getCyclicPaths(dom.window.document); + + expect(cyclicPaths).toHaveLength(3); + expectFinitePaths(cyclicPaths); + expect(dom.window.document.querySelectorAll('.edgeTerminals')).toHaveLength(2); + } finally { + restoreDom(); + } + }); + it('renders a flowchart subgraph through the shared paint path', async () => { const restoreDom = setupDom(); From 693d18b9fce3888da994bbc492d30d04d592d840 Mon Sep 17 00:00:00 2001 From: knsv Date: Tue, 9 Jun 2026 15:33:31 +0200 Subject: [PATCH 08/13] Fix dagre ER and class self-loop rendering --- .../layout-algorithms/dagre/index.js | 26 ++-- .../layout-algorithms/dagre/index.spec.js | 129 ++++++++++++++---- 2 files changed, 116 insertions(+), 39 deletions(-) diff --git a/packages/mermaid/src/rendering-util/layout-algorithms/dagre/index.js b/packages/mermaid/src/rendering-util/layout-algorithms/dagre/index.js index 91e06b91ccd..98f4ee504dc 100644 --- a/packages/mermaid/src/rendering-util/layout-algorithms/dagre/index.js +++ b/packages/mermaid/src/rendering-util/layout-algorithms/dagre/index.js @@ -32,10 +32,12 @@ const getDefaultSelfLoopSide = (rankdir = 'TB') => { } }; -// Class diagrams also use dagre, but self-referential multiplicity labels rely on -// the existing segmented self-loop rendering path for terminal label placement. const shouldMergeSelfLoopSegments = (diagramType) => - diagramType === 'flowchart' || diagramType === 'flowchart-v2' || diagramType === 'stateDiagram'; + diagramType === 'flowchart' || + diagramType === 'flowchart-v2' || + diagramType === 'stateDiagram' || + diagramType === 'er' || + diagramType === 'classDiagram'; const DAGRE_NODE_LAYOUT_PROPERTIES = [ 'x', @@ -460,13 +462,15 @@ export const applyDagreLayoutResult = (data4Layout, measuredLayout) => { const nodeById = new Map(data4Layout.nodes.map((node) => [node.id, node])); sortNodesByHierarchy(graph).forEach((nodeId) => { - const targetNode = nodeById.get(nodeId); - if (!targetNode) { + const dagreNode = normalizeDagreNode(graph, nodeId, subGraphTitleTotalMargin); + if (!dagreNode) { return; } - const dagreNode = normalizeDagreNode(graph, nodeId, subGraphTitleTotalMargin); - if (dagreNode) { + applyDagreNodeLayout(graph.node(nodeId), dagreNode); + + const targetNode = nodeById.get(nodeId); + if (targetNode) { applyDagreNodeLayout(targetNode, dagreNode); } }); @@ -740,12 +744,10 @@ export const runDagreLayoutCore = (_data4Layout, context) => { return measuredLayout; }; -const getDagrePaintNodes = (data4Layout, { measure }) => { - const nodeById = new Map(data4Layout.nodes.map((node) => [node.id, node])); - return sortNodesByHierarchy(measure.graph) - .map((nodeId) => nodeById.get(nodeId) ?? measure.graph.node(nodeId)) +const getDagrePaintNodes = (_data4Layout, { measure }) => + sortNodesByHierarchy(measure.graph) + .map((nodeId) => measure.graph.node(nodeId)) .filter(Boolean); -}; const getDagreEdgeNode = (nodeId, _edge, { measure }) => nodeId ? measure.graph.node(nodeId) : undefined; diff --git a/packages/mermaid/src/rendering-util/layout-algorithms/dagre/index.spec.js b/packages/mermaid/src/rendering-util/layout-algorithms/dagre/index.spec.js index 043898d48b5..61b44856b88 100644 --- a/packages/mermaid/src/rendering-util/layout-algorithms/dagre/index.spec.js +++ b/packages/mermaid/src/rendering-util/layout-algorithms/dagre/index.spec.js @@ -17,6 +17,7 @@ const setupDom = () => { const oldDocument = globalThis.document; const oldMutationObserver = globalThis.MutationObserver; const dom = new JSDOM('
', { + url: 'http://localhost/', resources: 'usable', beforeParse(window) { window.Element.prototype.getBBox = () => ({ @@ -101,6 +102,8 @@ describe('getEdgesToRender', () => { expect(data4Layout.nodes[0]).toMatchObject({ x: 10, y: 25, width: 30, height: 40 }); expect(data4Layout.nodes[1]).toMatchObject({ x: 100, y: 125, width: 30, height: 40 }); + expect(graph.node('A')).toMatchObject({ x: 10, y: 25, width: 30, height: 40 }); + expect(graph.node('B')).toMatchObject({ x: 100, y: 125, width: 30, height: 40 }); expect(data4Layout.edges).toEqual([ expect.objectContaining({ id: 'A-B', @@ -501,50 +504,122 @@ C --> C` } }); - it('renders recursive ER relationships with their dagre self-loop segments', async () => { + it('renders a recursive ER relationship as one logical self-loop path', async () => { const restoreDom = setupDom(); try { const { svg } = await mermaidAPI.render( 'er-recursive-self-loop-test', `erDiagram - CUSTOMER ||..o{ CUSTOMER : refers - CUSTOMER ||--o{ ORDER : places - ORDER ||--|{ LINE-ITEM : contains` + CUSTOMER ||..o{ CUSTOMER : refers` ); const dom = new JSDOM(svg); const cyclicPaths = getCyclicPaths(dom.window.document); + const relationshipPaths = dom.window.document.querySelectorAll( + '.edgePaths path.relationshipLine' + ); - expect(cyclicPaths).toHaveLength(3); - expectFinitePaths(cyclicPaths); + expect(cyclicPaths).toHaveLength(0); + expect(relationshipPaths).toHaveLength(1); + expect(relationshipPaths[0].getAttribute('data-id')).not.toContain('cyclic-special'); + expect(relationshipPaths[0].getAttribute('id')).toContain('entity-CUSTOMER-0'); + expect(relationshipPaths[0].getAttribute('id')).not.toContain('cyclic-special'); + expectFinitePaths(relationshipPaths); } finally { restoreDom(); } }); - it('renders class self-loops with multiplicity terminal labels', async () => { - const restoreDom = setupDom(); + it('preserves class self-loop multiplicity terminal labels when merging', () => { + const graph = new Graph({ multigraph: true, compound: true }); + graph.setNode('SelfReferential', { + id: 'SelfReferential', + x: 50, + y: 50, + width: 100, + height: 60, + }); + graph.setNode('SelfReferential---SelfReferential---1', { + id: 'SelfReferential---SelfReferential---1', + x: 120, + y: 50, + }); + graph.setNode('SelfReferential---SelfReferential---2', { + id: 'SelfReferential---SelfReferential---2', + x: 120, + y: 90, + }); - try { - const { svg } = await mermaidAPI.render( - 'class-recursive-self-loop-test', - `classDiagram - class SelfReferential{ - +int id - +int self_referential_id - +SelfReferential referenced - } - SelfReferential "1" --> "0..1" SelfReferential : referenced` - ); - const dom = new JSDOM(svg); - const cyclicPaths = getCyclicPaths(dom.window.document); + const originalEdge = { + id: 'SelfReferential-SelfReferential', + start: 'SelfReferential', + end: 'SelfReferential', + label: 'referenced', + arrowTypeStart: 'none', + arrowTypeEnd: 'extension', + startLabelRight: '1', + endLabelLeft: '0..1', + }; + const segment1 = { + ...originalEdge, + id: 'SelfReferential-cyclic-special-1', + selfLoop: { id: originalEdge.id, order: 0 }, + originalEdge, + points: [], + }; + const segmentMid = { + ...originalEdge, + id: 'SelfReferential-cyclic-special-mid', + selfLoop: { id: originalEdge.id, order: 1 }, + originalEdge, + points: [], + width: 52, + height: 14, + labelStyle: 'label-style', + }; + const segment2 = { + ...originalEdge, + id: 'SelfReferential-cyclic-special-2', + selfLoop: { id: originalEdge.id, order: 2 }, + originalEdge, + points: [], + }; - expect(cyclicPaths).toHaveLength(3); - expectFinitePaths(cyclicPaths); - expect(dom.window.document.querySelectorAll('.edgeTerminals')).toHaveLength(2); - } finally { - restoreDom(); - } + graph.setEdge( + 'SelfReferential', + 'SelfReferential---SelfReferential---1', + segment1, + 'SelfReferential-cyclic-special-0' + ); + graph.setEdge( + 'SelfReferential---SelfReferential---1', + 'SelfReferential---SelfReferential---2', + segmentMid, + 'SelfReferential-cyclic-special-1' + ); + graph.setEdge( + 'SelfReferential---SelfReferential---2', + 'SelfReferential', + segment2, + 'SelfReferential-cyclic-special-2' + ); + + const edgesToRender = getEdgesToRender(graph); + + expect(edgesToRender).toHaveLength(1); + expect(edgesToRender[0].edge).toMatchObject({ + id: 'SelfReferential-SelfReferential', + start: 'SelfReferential', + end: 'SelfReferential', + label: 'referenced', + arrowTypeStart: 'none', + arrowTypeEnd: 'extension', + startLabelRight: '1', + endLabelLeft: '0..1', + labelStyle: 'label-style', + }); + expect(edgesToRender[0].edge.selfLoop).toBeUndefined(); + expect(edgesToRender[0].edge.originalEdge).toBeUndefined(); }); it('renders a flowchart subgraph through the shared paint path', async () => { From 2ef8ca9bcb51f8190bad921c75b436d2b68a17e7 Mon Sep 17 00:00:00 2001 From: knsv Date: Tue, 9 Jun 2026 16:39:50 +0200 Subject: [PATCH 09/13] Fix class diagram dagre self-loop routing --- packages/mermaid/src/defaultConfig.ts | 1 + .../diagram-api/diagram-orchestration.spec.ts | 6 ++++ packages/mermaid/src/mermaidAPI.spec.ts | 2 +- .../layout-algorithms/dagre/index.js | 17 +++++++--- .../layout-algorithms/dagre/index.spec.js | 32 +++++++++++++++++++ 5 files changed, 53 insertions(+), 5 deletions(-) diff --git a/packages/mermaid/src/defaultConfig.ts b/packages/mermaid/src/defaultConfig.ts index d23a0bead4d..0d5abd61695 100644 --- a/packages/mermaid/src/defaultConfig.ts +++ b/packages/mermaid/src/defaultConfig.ts @@ -57,6 +57,7 @@ const config: RequiredDeep = { }, }, class: { + ...defaultConfigJson.class, hideEmptyMembersBox: false, hierarchicalNamespaces: true, }, diff --git a/packages/mermaid/src/diagram-api/diagram-orchestration.spec.ts b/packages/mermaid/src/diagram-api/diagram-orchestration.spec.ts index 652a5926cd0..317dbb12015 100644 --- a/packages/mermaid/src/diagram-api/diagram-orchestration.spec.ts +++ b/packages/mermaid/src/diagram-api/diagram-orchestration.spec.ts @@ -76,6 +76,12 @@ describe('diagram-orchestration', () => { ); }); + it('should detect class diagram v2 when dagre-wrapper is the class renderer', () => { + expect(detectType('classDiagram', { class: { defaultRenderer: 'dagre-wrapper' } })).toBe( + 'classDiagram' + ); + }); + it('should not detect flowchart if pie contains flowchart', () => { expect( detectType(`pie title: "flowchart" diff --git a/packages/mermaid/src/mermaidAPI.spec.ts b/packages/mermaid/src/mermaidAPI.spec.ts index ffcf69e1733..a24b98ee942 100644 --- a/packages/mermaid/src/mermaidAPI.spec.ts +++ b/packages/mermaid/src/mermaidAPI.spec.ts @@ -846,7 +846,7 @@ graph TD;A--x|text including URL space|B;`) // We have to have both the specific textDiagramType and the expected type name because the expected type may be slightly different from what is put in the diagram text (ex: in -v2 diagrams) const diagramTypesAndExpectations = [ // { textDiagramType: 'C4Context', expectedType: 'c4' }, TODO : setAccTitle not called in C4 jison parser - { textDiagramType: 'classDiagram', expectedType: 'class' }, + { textDiagramType: 'classDiagram', expectedType: 'classDiagram' }, { textDiagramType: 'classDiagram-v2', expectedType: 'classDiagram' }, { textDiagramType: 'erDiagram', expectedType: 'er' }, { textDiagramType: 'graph', expectedType: 'flowchart-v2' }, diff --git a/packages/mermaid/src/rendering-util/layout-algorithms/dagre/index.js b/packages/mermaid/src/rendering-util/layout-algorithms/dagre/index.js index 98f4ee504dc..c56ec8dc169 100644 --- a/packages/mermaid/src/rendering-util/layout-algorithms/dagre/index.js +++ b/packages/mermaid/src/rendering-util/layout-algorithms/dagre/index.js @@ -384,10 +384,19 @@ const measureDagreGraph = async ({ if (edge.selfLoop.order !== 1) { return; } - const segmentId = edge.id; - edge.id = edge.selfLoop.id; - await insertEdgeLabel(edgeLabels, edge); - edge.id = segmentId; + const labelEdge = { + ...edge.originalEdge, + ...edge, + id: edge.selfLoop.id, + startLabelLeft: edge.originalEdge?.startLabelLeft ?? edge.startLabelLeft, + startLabelRight: edge.originalEdge?.startLabelRight ?? edge.startLabelRight, + endLabelLeft: edge.originalEdge?.endLabelLeft ?? edge.endLabelLeft, + endLabelRight: edge.originalEdge?.endLabelRight ?? edge.endLabelRight, + }; + await insertEdgeLabel(edgeLabels, labelEdge); + edge.width = labelEdge.width; + edge.height = labelEdge.height; + edge.labelStyle = labelEdge.labelStyle; return; } await insertEdgeLabel(edgeLabels, edge); diff --git a/packages/mermaid/src/rendering-util/layout-algorithms/dagre/index.spec.js b/packages/mermaid/src/rendering-util/layout-algorithms/dagre/index.spec.js index 61b44856b88..84984fbcfa0 100644 --- a/packages/mermaid/src/rendering-util/layout-algorithms/dagre/index.spec.js +++ b/packages/mermaid/src/rendering-util/layout-algorithms/dagre/index.spec.js @@ -622,6 +622,38 @@ C --> C` expect(edgesToRender[0].edge.originalEdge).toBeUndefined(); }); + it('renders a recursive class relationship as one path with multiplicity labels', async () => { + const restoreDom = setupDom(); + + try { + const { svg } = await mermaidAPI.render( + 'class-self-loop-shared-paint-test', + `classDiagram +class SelfReferential{ + +int id + +int self_referential_id + +SelfReferential referenced +} +SelfReferential "1" --> "0..1" SelfReferential : referenced` + ); + const dom = new JSDOM(svg); + const document = dom.window.document; + const cyclicPaths = getCyclicPaths(document); + const edgePaths = document.querySelectorAll('.edgePaths path[data-edge="true"]'); + const terminalLabels = [...document.querySelectorAll('.edgeTerminals')].map((label) => + label.textContent?.trim() + ); + + expect(cyclicPaths).toHaveLength(0); + expect(edgePaths).toHaveLength(1); + expect(terminalLabels).toContain('1'); + expect(terminalLabels).toContain('0..1'); + expectFinitePaths(edgePaths); + } finally { + restoreDom(); + } + }); + it('renders a flowchart subgraph through the shared paint path', async () => { const restoreDom = setupDom(); From e8ea3d152baa7d8d2edf7fed60ee2238dcbc3e47 Mon Sep 17 00:00:00 2001 From: "autofix-ci[bot]" <114827586+autofix-ci[bot]@users.noreply.github.com> Date: Tue, 9 Jun 2026 14:46:04 +0000 Subject: [PATCH 10/13] [autofix.ci] apply automated fixes --- docs/config/setup/defaultConfig/variables/configKeys.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/config/setup/defaultConfig/variables/configKeys.md b/docs/config/setup/defaultConfig/variables/configKeys.md index b2c3830d17d..281c7c7df97 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:335](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/defaultConfig.ts#L335) +Defined in: [packages/mermaid/src/defaultConfig.ts:336](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/defaultConfig.ts#L336) From 5c3a7b4327db0ff586f63bb990bc27a9eb793b79 Mon Sep 17 00:00:00 2001 From: knsv Date: Tue, 9 Jun 2026 17:15:07 +0200 Subject: [PATCH 11/13] Restore class diagram node padding defaults --- packages/mermaid/src/config.spec.ts | 7 +++++++ packages/mermaid/src/defaultConfig.ts | 2 +- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/packages/mermaid/src/config.spec.ts b/packages/mermaid/src/config.spec.ts index 408cea9cc18..7a3b6bae186 100644 --- a/packages/mermaid/src/config.spec.ts +++ b/packages/mermaid/src/config.spec.ts @@ -63,6 +63,13 @@ describe('when working with site config', () => { expect(config.elk?.nodePlacementAlignment).toBe('NONE'); }); + it('should default class diagrams to dagre-wrapper without forcing class padding', () => { + const config = configApi.getConfig(); + + expect(config.class?.defaultRenderer).toBe('dagre-wrapper'); + expect(config.class?.padding).toBeUndefined(); + }); + it('should retain railroad directives after sanitization', () => { configApi.saveConfigFromInitialize({}); configApi.addDirective({ diff --git a/packages/mermaid/src/defaultConfig.ts b/packages/mermaid/src/defaultConfig.ts index 0d5abd61695..7ceebd825ac 100644 --- a/packages/mermaid/src/defaultConfig.ts +++ b/packages/mermaid/src/defaultConfig.ts @@ -57,7 +57,7 @@ const config: RequiredDeep = { }, }, class: { - ...defaultConfigJson.class, + defaultRenderer: defaultConfigJson.class.defaultRenderer, hideEmptyMembersBox: false, hierarchicalNamespaces: true, }, From c7308a330f4742a1fda58fc60baff9d69b52dda6 Mon Sep 17 00:00:00 2001 From: knsv Date: Tue, 9 Jun 2026 17:29:50 +0200 Subject: [PATCH 12/13] Fix class renderer default for docs runtime --- packages/mermaid/src/defaultConfig.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/mermaid/src/defaultConfig.ts b/packages/mermaid/src/defaultConfig.ts index 7ceebd825ac..d405da53294 100644 --- a/packages/mermaid/src/defaultConfig.ts +++ b/packages/mermaid/src/defaultConfig.ts @@ -57,7 +57,7 @@ const config: RequiredDeep = { }, }, class: { - defaultRenderer: defaultConfigJson.class.defaultRenderer, + defaultRenderer: 'dagre-wrapper', hideEmptyMembersBox: false, hierarchicalNamespaces: true, }, From cdfc0ea65f47bc8f9605a2a646ed87c25a692216 Mon Sep 17 00:00:00 2001 From: Knut Sveidqvist Date: Wed, 10 Jun 2026 13:01:28 +0000 Subject: [PATCH 13/13] Address review feedback: changeset for class default renderer, paint cleanups - Add changeset documenting the class.defaultRenderer switch to the unified (dagre-wrapper) renderer - Drop the shared EMPTY_CLUSTER_DB singleton in favor of a fresh Map per paint call to avoid a mutable module-level default - Document why class.padding is intentionally left undefined in defaultConfig - Add hand-drawn self-referential class diagram e2e snapshot test --- .changeset/class-default-unified-renderer.md | 12 ++++++++++++ .../class/classDiagram-handDrawn-v3.spec.js | 15 +++++++++++++++ .../setup/defaultConfig/variables/configKeys.md | 2 +- .../mermaid/functions/clearLayoutRenderState.md | 2 +- .../functions/createCommonLayoutRenderer.md | 2 +- .../mermaid/functions/defaultMeasureLayout.md | 2 +- .../setup/mermaid/functions/paintLayoutData.md | 2 +- .../interfaces/CommonLayoutPaintContext.md | 14 +++++++------- .../interfaces/CommonLayoutPaintOptions.md | 16 ++++++++-------- .../interfaces/CommonLayoutRenderContext.md | 12 ++++++------ .../interfaces/CommonLayoutRendererDefinition.md | 14 +++++++------- packages/mermaid/src/defaultConfig.ts | 3 +++ .../layout-algorithms/common/index.ts | 4 +--- 13 files changed, 64 insertions(+), 36 deletions(-) create mode 100644 .changeset/class-default-unified-renderer.md diff --git a/.changeset/class-default-unified-renderer.md b/.changeset/class-default-unified-renderer.md new file mode 100644 index 00000000000..882824f8f27 --- /dev/null +++ b/.changeset/class-default-unified-renderer.md @@ -0,0 +1,12 @@ +--- +'mermaid': minor +--- + +feat: route `classDiagram` to the unified (v2) renderer by default + +`class.defaultRenderer` now defaults to `dagre-wrapper`, so plain `classDiagram` +documents (without the `-v2` suffix) render through the unified renderer and the +shared dagre layout/paint pipeline instead of the legacy class renderer. Set +`class: { defaultRenderer: 'dagre-d3' }` in the config to restore the legacy +renderer. Self-referential edges in class and ER diagrams now render as compact +merged self-loops. diff --git a/cypress/integration/rendering/class/classDiagram-handDrawn-v3.spec.js b/cypress/integration/rendering/class/classDiagram-handDrawn-v3.spec.js index d4009d518bb..f67fd219b36 100644 --- a/cypress/integration/rendering/class/classDiagram-handDrawn-v3.spec.js +++ b/cypress/integration/rendering/class/classDiagram-handDrawn-v3.spec.js @@ -1137,4 +1137,19 @@ class C13["With Città foreign language"] { class: { hierarchicalNamespaces: false } } ); }); + + it('HD: should render a self-referential class diagram with multiplicity labels', () => { + imgSnapshotTest( + ` + classDiagram + class SelfReferential{ + +int id + +int self_referential_id + +SelfReferential referenced + } + SelfReferential "1" --> "0..1" SelfReferential : referenced + `, + { logLevel: 1, htmlLabels: true, look: 'handDrawn' } + ); + }); }); diff --git a/docs/config/setup/defaultConfig/variables/configKeys.md b/docs/config/setup/defaultConfig/variables/configKeys.md index 281c7c7df97..2dab82bd45a 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:336](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/defaultConfig.ts#L336) +Defined in: [packages/mermaid/src/defaultConfig.ts:339](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/defaultConfig.ts#L339) diff --git a/docs/config/setup/mermaid/functions/clearLayoutRenderState.md b/docs/config/setup/mermaid/functions/clearLayoutRenderState.md index aea439a7c6b..ce3c3278b65 100644 --- a/docs/config/setup/mermaid/functions/clearLayoutRenderState.md +++ b/docs/config/setup/mermaid/functions/clearLayoutRenderState.md @@ -12,7 +12,7 @@ > **clearLayoutRenderState**(): `void` -Defined in: [packages/mermaid/src/rendering-util/layout-algorithms/common/index.ts:166](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/rendering-util/layout-algorithms/common/index.ts#L166) +Defined in: [packages/mermaid/src/rendering-util/layout-algorithms/common/index.ts:164](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/rendering-util/layout-algorithms/common/index.ts#L164) ## Returns diff --git a/docs/config/setup/mermaid/functions/createCommonLayoutRenderer.md b/docs/config/setup/mermaid/functions/createCommonLayoutRenderer.md index 487cab2b403..53cc4d59136 100644 --- a/docs/config/setup/mermaid/functions/createCommonLayoutRenderer.md +++ b/docs/config/setup/mermaid/functions/createCommonLayoutRenderer.md @@ -12,7 +12,7 @@ > **createCommonLayoutRenderer**<`CoreResult`, `PreparedLayout`, `MeasureResult`>(`__namedParameters`): (`data4Layout`, `svg`, `helpers?`, `options?`, `positions?`) => `Promise`<`void`> -Defined in: [packages/mermaid/src/rendering-util/layout-algorithms/common/index.ts:109](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/rendering-util/layout-algorithms/common/index.ts#L109) +Defined in: [packages/mermaid/src/rendering-util/layout-algorithms/common/index.ts:107](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/rendering-util/layout-algorithms/common/index.ts#L107) ## Type Parameters diff --git a/docs/config/setup/mermaid/functions/defaultMeasureLayout.md b/docs/config/setup/mermaid/functions/defaultMeasureLayout.md index 22cc4431a02..f592ecdd7f4 100644 --- a/docs/config/setup/mermaid/functions/defaultMeasureLayout.md +++ b/docs/config/setup/mermaid/functions/defaultMeasureLayout.md @@ -12,7 +12,7 @@ > **defaultMeasureLayout**(`data4Layout`, `__namedParameters`): `Promise`<{ `graph`: `Graph`; `groups`: { `clusters`: `D3Selection`<`SVGGElement`>; `edgeLabels`: `D3Selection`<`SVGGElement`>; `edgePaths`: `D3Selection`<`SVGGElement`>; `nodes`: `D3Selection`<`SVGGElement`>; `rootGroups`: `D3Selection`<`SVGGElement`>; }; `nodeElements`: `Map`<`string`, `D3Selection`<`SVGElement` | `SVGGElement`>>; }> -Defined in: [packages/mermaid/src/rendering-util/layout-algorithms/common/index.ts:173](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/rendering-util/layout-algorithms/common/index.ts#L173) +Defined in: [packages/mermaid/src/rendering-util/layout-algorithms/common/index.ts:171](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/rendering-util/layout-algorithms/common/index.ts#L171) ## Parameters diff --git a/docs/config/setup/mermaid/functions/paintLayoutData.md b/docs/config/setup/mermaid/functions/paintLayoutData.md index 5b8faec326c..f6ba605061d 100644 --- a/docs/config/setup/mermaid/functions/paintLayoutData.md +++ b/docs/config/setup/mermaid/functions/paintLayoutData.md @@ -12,7 +12,7 @@ > **paintLayoutData**(`data4Layout`, `context`, `options`): `Promise`<`void`> -Defined in: [packages/mermaid/src/rendering-util/layout-algorithms/common/index.ts:180](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/rendering-util/layout-algorithms/common/index.ts#L180) +Defined in: [packages/mermaid/src/rendering-util/layout-algorithms/common/index.ts:178](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/rendering-util/layout-algorithms/common/index.ts#L178) ## Parameters diff --git a/docs/config/setup/mermaid/interfaces/CommonLayoutPaintContext.md b/docs/config/setup/mermaid/interfaces/CommonLayoutPaintContext.md index 3644c7aaddd..ea206843c64 100644 --- a/docs/config/setup/mermaid/interfaces/CommonLayoutPaintContext.md +++ b/docs/config/setup/mermaid/interfaces/CommonLayoutPaintContext.md @@ -10,7 +10,7 @@ # Interface: CommonLayoutPaintContext\ -Defined in: [packages/mermaid/src/rendering-util/layout-algorithms/common/index.ts:49](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/rendering-util/layout-algorithms/common/index.ts#L49) +Defined in: [packages/mermaid/src/rendering-util/layout-algorithms/common/index.ts:47](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/rendering-util/layout-algorithms/common/index.ts#L47) ## Extends @@ -32,7 +32,7 @@ Defined in: [packages/mermaid/src/rendering-util/layout-algorithms/common/index. > **element**: `D3Selection`<`SVGElement`> -Defined in: [packages/mermaid/src/rendering-util/layout-algorithms/common/index.ts:42](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/rendering-util/layout-algorithms/common/index.ts#L42) +Defined in: [packages/mermaid/src/rendering-util/layout-algorithms/common/index.ts:40](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/rendering-util/layout-algorithms/common/index.ts#L40) #### Inherited from @@ -44,7 +44,7 @@ Defined in: [packages/mermaid/src/rendering-util/layout-algorithms/common/index. > `optional` **helpers**: `object` -Defined in: [packages/mermaid/src/rendering-util/layout-algorithms/common/index.ts:43](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/rendering-util/layout-algorithms/common/index.ts#L43) +Defined in: [packages/mermaid/src/rendering-util/layout-algorithms/common/index.ts:41](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/rendering-util/layout-algorithms/common/index.ts#L41) #### common @@ -492,7 +492,7 @@ The curve factory to use > **measure**: `MeasureResult` -Defined in: [packages/mermaid/src/rendering-util/layout-algorithms/common/index.ts:53](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/rendering-util/layout-algorithms/common/index.ts#L53) +Defined in: [packages/mermaid/src/rendering-util/layout-algorithms/common/index.ts:51](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/rendering-util/layout-algorithms/common/index.ts#L51) --- @@ -500,7 +500,7 @@ Defined in: [packages/mermaid/src/rendering-util/layout-algorithms/common/index. > `optional` **options**: [`RenderOptions`](RenderOptions.md) -Defined in: [packages/mermaid/src/rendering-util/layout-algorithms/common/index.ts:44](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/rendering-util/layout-algorithms/common/index.ts#L44) +Defined in: [packages/mermaid/src/rendering-util/layout-algorithms/common/index.ts:42](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/rendering-util/layout-algorithms/common/index.ts#L42) #### Inherited from @@ -512,7 +512,7 @@ Defined in: [packages/mermaid/src/rendering-util/layout-algorithms/common/index. > `optional` **positions**: `Positions` -Defined in: [packages/mermaid/src/rendering-util/layout-algorithms/common/index.ts:45](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/rendering-util/layout-algorithms/common/index.ts#L45) +Defined in: [packages/mermaid/src/rendering-util/layout-algorithms/common/index.ts:43](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/rendering-util/layout-algorithms/common/index.ts#L43) #### Inherited from @@ -524,7 +524,7 @@ Defined in: [packages/mermaid/src/rendering-util/layout-algorithms/common/index. > `optional` **preparedLayout**: `PreparedLayout` -Defined in: [packages/mermaid/src/rendering-util/layout-algorithms/common/index.ts:46](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/rendering-util/layout-algorithms/common/index.ts#L46) +Defined in: [packages/mermaid/src/rendering-util/layout-algorithms/common/index.ts:44](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/rendering-util/layout-algorithms/common/index.ts#L44) #### Inherited from diff --git a/docs/config/setup/mermaid/interfaces/CommonLayoutPaintOptions.md b/docs/config/setup/mermaid/interfaces/CommonLayoutPaintOptions.md index 2f3ca8d6b87..e16aaf0503a 100644 --- a/docs/config/setup/mermaid/interfaces/CommonLayoutPaintOptions.md +++ b/docs/config/setup/mermaid/interfaces/CommonLayoutPaintOptions.md @@ -10,7 +10,7 @@ # Interface: CommonLayoutPaintOptions -Defined in: [packages/mermaid/src/rendering-util/layout-algorithms/common/index.ts:56](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/rendering-util/layout-algorithms/common/index.ts#L56) +Defined in: [packages/mermaid/src/rendering-util/layout-algorithms/common/index.ts:54](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/rendering-util/layout-algorithms/common/index.ts#L54) ## Properties @@ -18,7 +18,7 @@ Defined in: [packages/mermaid/src/rendering-util/layout-algorithms/common/index. > `optional` **clusterDb**: `ClusterDb` -Defined in: [packages/mermaid/src/rendering-util/layout-algorithms/common/index.ts:57](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/rendering-util/layout-algorithms/common/index.ts#L57) +Defined in: [packages/mermaid/src/rendering-util/layout-algorithms/common/index.ts:55](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/rendering-util/layout-algorithms/common/index.ts#L55) --- @@ -26,7 +26,7 @@ Defined in: [packages/mermaid/src/rendering-util/layout-algorithms/common/index. > `optional` **getEdgeNode**: (`id`, `edge`, `context`) => `object` | `Node` | `undefined` -Defined in: [packages/mermaid/src/rendering-util/layout-algorithms/common/index.ts:62](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/rendering-util/layout-algorithms/common/index.ts#L62) +Defined in: [packages/mermaid/src/rendering-util/layout-algorithms/common/index.ts:60](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/rendering-util/layout-algorithms/common/index.ts#L60) #### Parameters @@ -52,7 +52,7 @@ Defined in: [packages/mermaid/src/rendering-util/layout-algorithms/common/index. > `optional` **getNodes**: (`data4Layout`, `context`) => `Iterable`<`Node`> -Defined in: [packages/mermaid/src/rendering-util/layout-algorithms/common/index.ts:58](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/rendering-util/layout-algorithms/common/index.ts#L58) +Defined in: [packages/mermaid/src/rendering-util/layout-algorithms/common/index.ts:56](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/rendering-util/layout-algorithms/common/index.ts#L56) #### Parameters @@ -74,7 +74,7 @@ Defined in: [packages/mermaid/src/rendering-util/layout-algorithms/common/index. > `optional` **isCluster**: (`node`, `context`) => `boolean` -Defined in: [packages/mermaid/src/rendering-util/layout-algorithms/common/index.ts:71](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/rendering-util/layout-algorithms/common/index.ts#L71) +Defined in: [packages/mermaid/src/rendering-util/layout-algorithms/common/index.ts:69](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/rendering-util/layout-algorithms/common/index.ts#L69) #### Parameters @@ -96,7 +96,7 @@ Defined in: [packages/mermaid/src/rendering-util/layout-algorithms/common/index. > `optional` **skipEdge**: (`edge`) => `boolean` -Defined in: [packages/mermaid/src/rendering-util/layout-algorithms/common/index.ts:75](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/rendering-util/layout-algorithms/common/index.ts#L75) +Defined in: [packages/mermaid/src/rendering-util/layout-algorithms/common/index.ts:73](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/rendering-util/layout-algorithms/common/index.ts#L73) #### Parameters @@ -114,7 +114,7 @@ Defined in: [packages/mermaid/src/rendering-util/layout-algorithms/common/index. > `optional` **skipIntersect**: `boolean` | (`edge`) => `boolean` -Defined in: [packages/mermaid/src/rendering-util/layout-algorithms/common/index.ts:76](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/rendering-util/layout-algorithms/common/index.ts#L76) +Defined in: [packages/mermaid/src/rendering-util/layout-algorithms/common/index.ts:74](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/rendering-util/layout-algorithms/common/index.ts#L74) --- @@ -122,7 +122,7 @@ Defined in: [packages/mermaid/src/rendering-util/layout-algorithms/common/index. > `optional` **skipNode**: (`node`, `context`) => `boolean` -Defined in: [packages/mermaid/src/rendering-util/layout-algorithms/common/index.ts:67](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/rendering-util/layout-algorithms/common/index.ts#L67) +Defined in: [packages/mermaid/src/rendering-util/layout-algorithms/common/index.ts:65](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/rendering-util/layout-algorithms/common/index.ts#L65) #### Parameters diff --git a/docs/config/setup/mermaid/interfaces/CommonLayoutRenderContext.md b/docs/config/setup/mermaid/interfaces/CommonLayoutRenderContext.md index 5953430c1a4..644a84cfa11 100644 --- a/docs/config/setup/mermaid/interfaces/CommonLayoutRenderContext.md +++ b/docs/config/setup/mermaid/interfaces/CommonLayoutRenderContext.md @@ -10,7 +10,7 @@ # Interface: CommonLayoutRenderContext\ -Defined in: [packages/mermaid/src/rendering-util/layout-algorithms/common/index.ts:41](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/rendering-util/layout-algorithms/common/index.ts#L41) +Defined in: [packages/mermaid/src/rendering-util/layout-algorithms/common/index.ts:39](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/rendering-util/layout-algorithms/common/index.ts#L39) ## Extended by @@ -28,7 +28,7 @@ Defined in: [packages/mermaid/src/rendering-util/layout-algorithms/common/index. > **element**: `D3Selection`<`SVGElement`> -Defined in: [packages/mermaid/src/rendering-util/layout-algorithms/common/index.ts:42](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/rendering-util/layout-algorithms/common/index.ts#L42) +Defined in: [packages/mermaid/src/rendering-util/layout-algorithms/common/index.ts:40](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/rendering-util/layout-algorithms/common/index.ts#L40) --- @@ -36,7 +36,7 @@ Defined in: [packages/mermaid/src/rendering-util/layout-algorithms/common/index. > `optional` **helpers**: `object` -Defined in: [packages/mermaid/src/rendering-util/layout-algorithms/common/index.ts:43](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/rendering-util/layout-algorithms/common/index.ts#L43) +Defined in: [packages/mermaid/src/rendering-util/layout-algorithms/common/index.ts:41](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/rendering-util/layout-algorithms/common/index.ts#L41) #### common @@ -480,7 +480,7 @@ The curve factory to use > `optional` **options**: [`RenderOptions`](RenderOptions.md) -Defined in: [packages/mermaid/src/rendering-util/layout-algorithms/common/index.ts:44](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/rendering-util/layout-algorithms/common/index.ts#L44) +Defined in: [packages/mermaid/src/rendering-util/layout-algorithms/common/index.ts:42](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/rendering-util/layout-algorithms/common/index.ts#L42) --- @@ -488,7 +488,7 @@ Defined in: [packages/mermaid/src/rendering-util/layout-algorithms/common/index. > `optional` **positions**: `Positions` -Defined in: [packages/mermaid/src/rendering-util/layout-algorithms/common/index.ts:45](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/rendering-util/layout-algorithms/common/index.ts#L45) +Defined in: [packages/mermaid/src/rendering-util/layout-algorithms/common/index.ts:43](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/rendering-util/layout-algorithms/common/index.ts#L43) --- @@ -496,4 +496,4 @@ Defined in: [packages/mermaid/src/rendering-util/layout-algorithms/common/index. > `optional` **preparedLayout**: `PreparedLayout` -Defined in: [packages/mermaid/src/rendering-util/layout-algorithms/common/index.ts:46](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/rendering-util/layout-algorithms/common/index.ts#L46) +Defined in: [packages/mermaid/src/rendering-util/layout-algorithms/common/index.ts:44](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/rendering-util/layout-algorithms/common/index.ts#L44) diff --git a/docs/config/setup/mermaid/interfaces/CommonLayoutRendererDefinition.md b/docs/config/setup/mermaid/interfaces/CommonLayoutRendererDefinition.md index 5237a251240..9f5d055b95c 100644 --- a/docs/config/setup/mermaid/interfaces/CommonLayoutRendererDefinition.md +++ b/docs/config/setup/mermaid/interfaces/CommonLayoutRendererDefinition.md @@ -10,7 +10,7 @@ # Interface: CommonLayoutRendererDefinition\ -Defined in: [packages/mermaid/src/rendering-util/layout-algorithms/common/index.ts:79](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/rendering-util/layout-algorithms/common/index.ts#L79) +Defined in: [packages/mermaid/src/rendering-util/layout-algorithms/common/index.ts:77](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/rendering-util/layout-algorithms/common/index.ts#L77) ## Type Parameters @@ -32,7 +32,7 @@ Defined in: [packages/mermaid/src/rendering-util/layout-algorithms/common/index. > `optional` **afterPaint**: (`data4Layout`, `context`, `coreResult`) => `void` | `Promise`<`void`> -Defined in: [packages/mermaid/src/rendering-util/layout-algorithms/common/index.ts:101](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/rendering-util/layout-algorithms/common/index.ts#L101) +Defined in: [packages/mermaid/src/rendering-util/layout-algorithms/common/index.ts:99](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/rendering-util/layout-algorithms/common/index.ts#L99) #### Parameters @@ -58,7 +58,7 @@ Defined in: [packages/mermaid/src/rendering-util/layout-algorithms/common/index. > `optional` **measureLayout**: (`data4Layout`, `context`) => `Promise`<`MeasureResult`> -Defined in: [packages/mermaid/src/rendering-util/layout-algorithms/common/index.ts:88](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/rendering-util/layout-algorithms/common/index.ts#L88) +Defined in: [packages/mermaid/src/rendering-util/layout-algorithms/common/index.ts:86](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/rendering-util/layout-algorithms/common/index.ts#L86) #### Parameters @@ -80,7 +80,7 @@ Defined in: [packages/mermaid/src/rendering-util/layout-algorithms/common/index. > `optional` **paintLayout**: (`data4Layout`, `context`, `coreResult`) => `void` | `Promise`<`void`> -Defined in: [packages/mermaid/src/rendering-util/layout-algorithms/common/index.ts:96](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/rendering-util/layout-algorithms/common/index.ts#L96) +Defined in: [packages/mermaid/src/rendering-util/layout-algorithms/common/index.ts:94](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/rendering-util/layout-algorithms/common/index.ts#L94) #### Parameters @@ -106,7 +106,7 @@ Defined in: [packages/mermaid/src/rendering-util/layout-algorithms/common/index. > `optional` **paintOptions**: [`CommonLayoutPaintOptions`](CommonLayoutPaintOptions.md) -Defined in: [packages/mermaid/src/rendering-util/layout-algorithms/common/index.ts:106](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/rendering-util/layout-algorithms/common/index.ts#L106) +Defined in: [packages/mermaid/src/rendering-util/layout-algorithms/common/index.ts:104](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/rendering-util/layout-algorithms/common/index.ts#L104) --- @@ -114,7 +114,7 @@ Defined in: [packages/mermaid/src/rendering-util/layout-algorithms/common/index. > `optional` **prepareLayout**: (`data4Layout`, `context`) => `PreparedLayout` | `Promise`<`PreparedLayout`> -Defined in: [packages/mermaid/src/rendering-util/layout-algorithms/common/index.ts:84](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/rendering-util/layout-algorithms/common/index.ts#L84) +Defined in: [packages/mermaid/src/rendering-util/layout-algorithms/common/index.ts:82](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/rendering-util/layout-algorithms/common/index.ts#L82) #### Parameters @@ -136,7 +136,7 @@ Defined in: [packages/mermaid/src/rendering-util/layout-algorithms/common/index. > **runLayoutCore**: (`data4Layout`, `context`) => `CoreResult` | `Promise`<`CoreResult`> -Defined in: [packages/mermaid/src/rendering-util/layout-algorithms/common/index.ts:92](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/rendering-util/layout-algorithms/common/index.ts#L92) +Defined in: [packages/mermaid/src/rendering-util/layout-algorithms/common/index.ts:90](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/rendering-util/layout-algorithms/common/index.ts#L90) #### Parameters diff --git a/packages/mermaid/src/defaultConfig.ts b/packages/mermaid/src/defaultConfig.ts index d405da53294..aca8d168674 100644 --- a/packages/mermaid/src/defaultConfig.ts +++ b/packages/mermaid/src/defaultConfig.ts @@ -60,6 +60,9 @@ const config: RequiredDeep = { defaultRenderer: 'dagre-wrapper', hideEmptyMembersBox: false, hierarchicalNamespaces: true, + // `padding` is intentionally left undefined so the unified (v2) renderer keeps + // its own node sizing — setting the schema default of 5 here would change class + // node dimensions. }, gantt: { ...defaultConfigJson.gantt, diff --git a/packages/mermaid/src/rendering-util/layout-algorithms/common/index.ts b/packages/mermaid/src/rendering-util/layout-algorithms/common/index.ts index e1a4822e47f..100b979a89b 100644 --- a/packages/mermaid/src/rendering-util/layout-algorithms/common/index.ts +++ b/packages/mermaid/src/rendering-util/layout-algorithms/common/index.ts @@ -36,8 +36,6 @@ interface EdgeRenderPaths { updatedPath?: EdgeRenderPath; } -const EMPTY_CLUSTER_DB: ClusterDb = new Map(); - export interface CommonLayoutRenderContext { element: D3Selection; helpers?: InternalHelpers; @@ -252,7 +250,7 @@ async function paintLayoutEdge( const paths = insertEdge( groups.edgePaths, { ...edge }, - options.clusterDb ?? EMPTY_CLUSTER_DB, + options.clusterDb ?? new Map(), data4Layout.type, getRenderedNode(edge.start, edge, nodeById, context, options), getRenderedNode(edge.end, edge, nodeById, context, options),