From 6ae5fe7f17fdc9dd6a16bbcaba9544875ba1ba16 Mon Sep 17 00:00:00 2001 From: Knut Sveidqvist Date: Wed, 19 Jun 2024 12:24:29 +0200 Subject: [PATCH] #5237 Fixing self-loops --- .../dagre/mermaid-graphlib.js | 28 +++++++++++++++---- 1 file changed, 22 insertions(+), 6 deletions(-) diff --git a/packages/mermaid/src/rendering-util/layout-algorithms/dagre/mermaid-graphlib.js b/packages/mermaid/src/rendering-util/layout-algorithms/dagre/mermaid-graphlib.js index 8de8316cb..ac834b8f5 100644 --- a/packages/mermaid/src/rendering-util/layout-algorithms/dagre/mermaid-graphlib.js +++ b/packages/mermaid/src/rendering-util/layout-algorithms/dagre/mermaid-graphlib.js @@ -314,26 +314,42 @@ export const adjustClustersAndEdges = (graph, depth) => { v = getAnchorId(e.v); w = getAnchorId(e.w); graph.removeEdge(e.v, e.w, e.name); - const specialId = e.w + '---' + e.v; - graph.setNode(specialId, { - domId: specialId, - id: specialId, + const specialId1 = e.w + '---' + e.v + '---1'; + const specialId2 = e.w + '---' + e.v + '---2'; + graph.setNode(specialId1, { + domId: specialId1, + id: specialId1, labelStyle: '', label: edge.label, padding: 0, shape: 'labelRect', style: '', + width: 10, + height: 10, + }); + graph.setNode(specialId2, { + domId: specialId2, + id: specialId2, + labelStyle: '', + padding: 0, + shape: 'labelRect', + style: '', + width: 10, + height: 10, }); const edge1 = structuredClone(edge); + const edgeMid = structuredClone(edge); const edge2 = structuredClone(edge); edge1.label = ''; edge1.arrowTypeEnd = 'none'; + edgeMid.arrowTypeEnd = 'none'; edge2.label = ''; edge1.fromCluster = e.v; edge2.toCluster = e.v; - graph.setEdge(v, specialId, edge1, e.name + '-cyclic-special'); - graph.setEdge(specialId, w, edge2, e.name + '-cyclic-special'); + graph.setEdge(v, specialId1, edge1, e.name + '-cyclic-special'); + graph.setEdge(specialId1, specialId2, edgeMid, e.name + '-cyclic-special'); + graph.setEdge(specialId2, w, edge2, e.name + '-cyclic-special'); } else if (clusterDb[e.v] || clusterDb[e.w]) { log.warn('Fixing and trixing - removing XXX', e.v, e.w, e.name); v = getAnchorId(e.v);