Merge pull request #7019 from mermaid-js/tmp-mindmap-elk

mindmap breaking issue in ELK layout
This commit is contained in:
Ashish Jain
2025-09-30 09:02:40 +00:00
committed by GitHub
3 changed files with 66 additions and 2 deletions

View File

@@ -0,0 +1,5 @@
---
'@mermaid': patch
---
fix: Mindmap breaking in ELK layout

View File

@@ -110,6 +110,48 @@
config: config:
layout: elk 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
</pre>
<pre id="diagram4" class="mermaid">
---
config:
layout: elk
---
flowchart
aid0
</pre
>
<pre id="diagram4" class="mermaid">
---
config:
layout: elk
---
mindmap
aid0
</pre>
<pre id="diagram4" class="mermaid">
---
config:
layout: ogdc
---
flowchart-elk TB flowchart-elk TB
c1-->a2 c1-->a2
subgraph one subgraph one

View File

@@ -67,7 +67,22 @@ export const render = async (
// Add the element to the DOM // Add the element to the DOM
if (!node.isGroup) { 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); graph.children.push(child);
nodeDb[node.id] = node; nodeDb[node.id] = node;
@@ -150,7 +165,7 @@ export const render = async (
domId: { node: () => any; attr: (arg0: string, arg1: string) => void }; domId: { node: () => any; attr: (arg0: string, arg1: string) => void };
}) { }) {
if (node) { if (node) {
nodeDb[node.id] = node; nodeDb[node.id] ??= {};
nodeDb[node.id].offset = { nodeDb[node.id].offset = {
posX: node.x + relX, posX: node.x + relX,
posY: node.y + relY, posY: node.y + relY,
@@ -860,11 +875,13 @@ export const render = async (
log.info('APA01 layout result:', JSON.stringify(g, null, 2)); log.info('APA01 layout result:', JSON.stringify(g, null, 2));
} catch (error) { } catch (error) {
log.error('APA01 ELK layout error:', error); log.error('APA01 ELK layout error:', error);
log.error('APA01 elkGraph that caused error:', JSON.stringify(elkGraph, null, 2));
throw error; throw error;
} }
// debugger; // debugger;
await drawNodes(0, 0, g.children, svg, subGraphsEl, 0); await drawNodes(0, 0, g.children, svg, subGraphsEl, 0);
g.edges?.map( g.edges?.map(
(edge: { (edge: {
sources: (string | number)[]; sources: (string | number)[];