From 4e25bf5db9de8f673311e39673999adaf4be511b Mon Sep 17 00:00:00 2001 From: Knut Sveidqvist Date: Wed, 2 Oct 2024 21:06:01 +0200 Subject: [PATCH] Adding handling of self-loops into update position --- .../layout-algorithms/fixed/index.js | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/packages/mermaid/src/rendering-util/layout-algorithms/fixed/index.js b/packages/mermaid/src/rendering-util/layout-algorithms/fixed/index.js index 61f646024..fb7271793 100644 --- a/packages/mermaid/src/rendering-util/layout-algorithms/fixed/index.js +++ b/packages/mermaid/src/rendering-util/layout-algorithms/fixed/index.js @@ -94,6 +94,21 @@ const calcIntersections = (startNodeId, endNodeId, startNodeSize, endNodeSize) = const endIntersection = { x: endNodeSize.x, y: endNodeSize.x, pos: 'c' }; return [startIntersection, endIntersection]; } + + // Check for self loop + if (startNodeId === endNodeId) { + const intersection = calcIntersectionPoint(startNode, { + x: startNode.x + startNode.width / 2 + 20, + y: startNode.y + startNode.height / 2, + }); + + const forthY = startNode.height / 4; + return [ + { x: intersection.x, y: startNode.y - forthY, pos: 'r' }, + { x: intersection.x, y: startNode.y + forthY, pos: 'r' }, + ]; + } + const endNode = nodeDB.get(endNodeId); if (endNodeSize && endNode) { endNode.x = endNodeSize.x;