From 62f887b3c3146d1a55858b8f7f3b877332a51ca1 Mon Sep 17 00:00:00 2001 From: Knut Sveidqvist Date: Wed, 28 Aug 2024 11:45:20 +0200 Subject: [PATCH] Alana version 11.0.2-b.5, Updated calcIntersections allowing mouse coordinates --- cypress/platform/knsv-pos.html | 15 ++++++----- packages/mermaid/package.json | 2 +- .../layout-algorithms/fixed/index.js | 25 +++++++++++++------ 3 files changed, 28 insertions(+), 14 deletions(-) diff --git a/cypress/platform/knsv-pos.html b/cypress/platform/knsv-pos.html index 1b6dc5504..a39b2fd2d 100644 --- a/cypress/platform/knsv-pos.html +++ b/cypress/platform/knsv-pos.html @@ -188,12 +188,15 @@ // }; const { svg } = await mermaid.render('the-id-of-the-svg', code, undefined, positions); - // if (window?.calcIntersections) { - // console.log('Intersections', window.calcIntersections(positions, 'T', 'U')); - // } else { - // console.error('calcIntersections not found'); - // } - console.log(JSON.stringify(positions)); + if (window?.calcIntersections) { + console.log( + 'Intersections', + calcIntersections('T', undefined, positions.nodes['T'], { x: 200, y: 200 }) + ); + } else { + console.error('calcIntersections not found'); + } + // console.log(JSON.stringify(positions)); const elem = document.querySelector('#diagram'); elem.innerHTML = svg; diff --git a/packages/mermaid/package.json b/packages/mermaid/package.json index f87597a85..b4088e4f5 100644 --- a/packages/mermaid/package.json +++ b/packages/mermaid/package.json @@ -1,6 +1,6 @@ { "name": "@mermaid-chart/mermaid", - "version": "11.0.2-b.4", + "version": "11.0.2-b.5", "description": "Markdown-ish syntax for generating flowcharts, mindmaps, sequence diagrams, class diagrams, gantt charts, git graphs and more.", "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 568fc4082..442084ee7 100644 --- a/packages/mermaid/src/rendering-util/layout-algorithms/fixed/index.js +++ b/packages/mermaid/src/rendering-util/layout-algorithms/fixed/index.js @@ -45,7 +45,7 @@ const calcIntersectionPoint = (node, point) => { return { x: intersection.x, y: intersection.y, pos }; }; -const calcIntersections = (points, startNodeId, endNodeId, startNodeSize, endNodeSize) => { +const calcIntersections = (startNodeId, endNodeId, startNodeSize, endNodeSize) => { const startNode = nodeDB.get(startNodeId); if (startNodeSize) { startNode.x = startNodeSize.x; @@ -53,18 +53,29 @@ const calcIntersections = (points, startNodeId, endNodeId, startNodeSize, endNod startNode.width = startNodeSize.width; startNode.height = startNodeSize.height; } + + // If no end node it provided but you have an endNode size + // We are adding an edge to a new node + if (!endNodeId && endNodeSize) { + const startIntersection = calcIntersectionPoint(startNode, { + x: endNodeSize.x, + y: endNodeSize.y, + }); + const endIntersection = { x: endNodeSize.x, y: endNodeSize.x, pos: 'c' }; + return [startIntersection, endIntersection]; + } const endNode = nodeDB.get(endNodeId); - if (endNodeSize) { + if (endNodeSize && endNode) { endNode.x = endNodeSize.x; endNode.y = endNodeSize.y; endNode.width = endNodeSize.width; endNode.height = endNodeSize.height; + // Get the intersections + const startIntersection = calcIntersectionPoint(startNode, { x: endNode.x, y: endNode.y }); + const endIntersection = calcIntersectionPoint(endNode, { x: startNode.x, y: startNode.y }); + return [startIntersection, endIntersection]; } - // Get the intersections - const startIntersection = calcIntersectionPoint(startNode, { x: endNode.x, y: endNode.y }); - const endIntersection = calcIntersectionPoint(endNode, { x: startNode.x, y: startNode.y }); - - return [startIntersection, endIntersection]; + return []; }; const doRender = async (_elem, data4Layout, siteConfig, positions) => {