From 2415e8652a1b0b648a31a7a086d3d359a7a757a9 Mon Sep 17 00:00:00 2001 From: Knut Sveidqvist Date: Thu, 15 Aug 2024 12:05:59 +0200 Subject: [PATCH] Updated intersection calculations , Mermaid version 11.0.0-b.64 --- packages/mermaid/package.json | 2 +- .../layout-algorithms/fixed/index.js | 21 +++++++++++++++++-- .../rendering-elements/edges.js | 9 ++++++++ 3 files changed, 29 insertions(+), 3 deletions(-) diff --git a/packages/mermaid/package.json b/packages/mermaid/package.json index a79120aa9..ca271004a 100644 --- a/packages/mermaid/package.json +++ b/packages/mermaid/package.json @@ -1,6 +1,6 @@ { "name": "@mermaid-chart/mermaid", - "version": "11.0.0-b.63", + "version": "11.0.0-b.64", "description": "Markdown-ish syntax for generating flowcharts, sequence diagrams, class diagrams, gantt charts and git graphs.", "type": "module", "module": "./dist/mermaid.core.mjs", 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 f8b9b5dca..83e6e506e 100644 --- a/packages/mermaid/src/rendering-util/layout-algorithms/fixed/index.js +++ b/packages/mermaid/src/rendering-util/layout-algorithms/fixed/index.js @@ -28,12 +28,29 @@ const fixInterSections = (points, startNodeId, endNodeId) => { return fixedPoints; }; +const calcIntersectionPoint = (node, point) => { + const intersection = node.intersect(point); + const dx = intersection.x - node.x; + const dy = intersection.y - node.y; + + let pos = 'l'; + + // Determine the position of the intersection relative to the node + if (Math.abs(dx) > Math.abs(dy)) { + pos = dx > 0 ? 'r' : 'l'; // Right or left + } else { + pos = dy > 0 ? 'b' : 't'; // Bottom or top + } + + return { x: intersection.x, y: intersection.y, pos }; +}; + const calcIntersections = (points, startNodeId, endNodeId) => { const startNode = nodeDB.get(startNodeId); const endNode = nodeDB.get(endNodeId); // Get the intersections - const startIntersection = startNode.intersect({ x: endNode.x, y: endNode.y }); - const endIntersection = endNode.intersect({ x: startNode.x, y: startNode.y }); + const startIntersection = calcIntersectionPoint(startNode, { x: endNode.x, y: endNode.y }); + const endIntersection = calcIntersectionPoint(endNode, { x: startNode.x, y: startNode.y }); return [startIntersection, endIntersection]; }; diff --git a/packages/mermaid/src/rendering-util/rendering-elements/edges.js b/packages/mermaid/src/rendering-util/rendering-elements/edges.js index aab71df0c..2b00e7486 100644 --- a/packages/mermaid/src/rendering-util/rendering-elements/edges.js +++ b/packages/mermaid/src/rendering-util/rendering-elements/edges.js @@ -554,6 +554,15 @@ export const insertEdge = function (elem, edge, clusterDb, diagramType, startNod // .attr('cx', point.x) // .attr('cy', point.y); // }); + // lineData.forEach((point) => { + // elem + // .append('circle') + // .style('stroke', 'blue') + // .style('fill', 'blue') + // .attr('r', 3) + // .attr('cx', point.x) + // .attr('cy', point.y); + // }); let url = ''; if (getConfig().flowchart.arrowMarkerAbsolute || getConfig().state.arrowMarkerAbsolute) {