From ea69d26a607769f47cb9dcf275c7cdb4e0e0fd56 Mon Sep 17 00:00:00 2001 From: Knut Sveidqvist Date: Mon, 10 Jun 2024 13:50:06 +0200 Subject: [PATCH 1/6] #5237 Fix for incorrect handling of self loops with elk layout --- packages/mermaid-layout-elk/src/find-common-ancestor.ts | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/packages/mermaid-layout-elk/src/find-common-ancestor.ts b/packages/mermaid-layout-elk/src/find-common-ancestor.ts index ebdc01cf7..83990b2f3 100644 --- a/packages/mermaid-layout-elk/src/find-common-ancestor.ts +++ b/packages/mermaid-layout-elk/src/find-common-ancestor.ts @@ -7,6 +7,11 @@ export const findCommonAncestor = (id1: string, id2: string, treeData: TreeData) const { parentById } = treeData; const visited = new Set(); let currentId = id1; + + if (id1 === id2) { + return parentById[id1] || 'root'; + } + while (currentId) { visited.add(currentId); if (currentId === id2) { From aaa4e8a794a8a3f2e81a3acbe3180a905b271dec Mon Sep 17 00:00:00 2001 From: Knut Sveidqvist Date: Mon, 10 Jun 2024 13:55:12 +0200 Subject: [PATCH 2/6] test commit --- cypress/platform/knsv2.html | 40 +++++++++++++++++++++++++++++++------ 1 file changed, 34 insertions(+), 6 deletions(-) diff --git a/cypress/platform/knsv2.html b/cypress/platform/knsv2.html index b2598bfbc..bb035bd39 100644 --- a/cypress/platform/knsv2.html +++ b/cypress/platform/knsv2.html @@ -76,6 +76,23 @@
+flowchart LR
+ subgraph Apa["Apa"]
+        A["Start"]
+        B["This is B"]
+  end
+    A --> B & C["C"]
+    Apa --> C
+      
+
+flowchart LR
+ subgraph Apa["Apa"]
+    B --> B &   C
+  end
+      
+
 stateDiagram
 direction LR
       state Gorilla0 {
@@ -88,7 +105,7 @@ direction LR
       A0 --> C0
       
-
+    
 flowchart LR
     subgraph Gorilla
       subgraph Apa
@@ -101,6 +118,17 @@ flowchart LR
       
+flowchart LR
+ subgraph Apa["Apa"]
+        A["Start"]
+        B["This is B"]
+  end
+    A --> B & C["C"]
+    Apa --> C
+
+      
+
       %%{init: {"layout": "dagre", "mergeEdges": false} }%%
 flowchart LR
       A ==> B(This is B)
@@ -123,7 +151,7 @@ flowchart LR
     if_state --> True : if n >= 0
       
-
+    
       %%{init: {"layout": "elk", "mergeEdges": false, "elk.nodePlacement.strategy": "SIMPLE"} }%%
       stateDiagram
     state if_state <<choice>>
@@ -217,18 +245,18 @@ stateDiagram-v2