diff --git a/.changeset/slow-lemons-know.md b/.changeset/slow-lemons-know.md new file mode 100644 index 000000000..49eb48543 --- /dev/null +++ b/.changeset/slow-lemons-know.md @@ -0,0 +1,5 @@ +--- +'@mermaid': patch +--- + +fix: Mindmap breaking in ELK layout diff --git a/cypress/platform/knsv2.html b/cypress/platform/knsv2.html index 7ac7aeac8..90f40003a 100644 --- a/cypress/platform/knsv2.html +++ b/cypress/platform/knsv2.html @@ -110,6 +110,48 @@ config: layout: elk --- + mindmap + root((mindmap)) + Origins + Long history + ::icon(fa fa-book) + Popularisation + British popular psychology author Tony Buzan + Research + On effectiveness<br/>and features + On Automatic creation + Uses + Creative techniques + Strategic planning + Argument mapping + Tools + id)I am a cloud( + id))I am a bang(( + Tools + +
+ --- + config: + layout: elk + --- + flowchart + aid0 ++
+ --- + config: + layout: elk + --- + mindmap + aid0 + ++
+ ---
+ config:
+ layout: ogdc
+ ---
flowchart-elk TB
c1-->a2
subgraph one
diff --git a/packages/mermaid-layout-elk/src/render.ts b/packages/mermaid-layout-elk/src/render.ts
index 4680b0c68..2cb12e035 100644
--- a/packages/mermaid-layout-elk/src/render.ts
+++ b/packages/mermaid-layout-elk/src/render.ts
@@ -67,7 +67,22 @@ export const render = async (
// Add the element to the DOM
if (!node.isGroup) {
- const child = node as NodeWithVertex;
+ // const child = node as NodeWithVertex;
+ const child: NodeWithVertex = {
+ id: node.id,
+ width: node.width,
+ height: node.height,
+ // Store the original node data for later use
+ label: node.label,
+ isGroup: node.isGroup,
+ shape: node.shape,
+ padding: node.padding,
+ cssClasses: node.cssClasses,
+ cssStyles: node.cssStyles,
+ look: node.look,
+ // Include parentId for subgraph processing
+ parentId: node.parentId,
+ };
graph.children.push(child);
nodeDb[node.id] = node;
@@ -150,7 +165,7 @@ export const render = async (
domId: { node: () => any; attr: (arg0: string, arg1: string) => void };
}) {
if (node) {
- nodeDb[node.id] = node;
+ nodeDb[node.id] ??= {};
nodeDb[node.id].offset = {
posX: node.x + relX,
posY: node.y + relY,
@@ -860,11 +875,13 @@ export const render = async (
log.info('APA01 layout result:', JSON.stringify(g, null, 2));
} catch (error) {
log.error('APA01 ELK layout error:', error);
+ log.error('APA01 elkGraph that caused error:', JSON.stringify(elkGraph, null, 2));
throw error;
}
// debugger;
await drawNodes(0, 0, g.children, svg, subGraphsEl, 0);
+
g.edges?.map(
(edge: {
sources: (string | number)[];