MC-2542 Exposing calcIntersect function

This commit is contained in:
Knut Sveidqvist
2025-01-23 12:03:54 +01:00
parent fd8f95b628
commit d7535a9e4d
2 changed files with 33 additions and 0 deletions

View File

@@ -461,4 +461,5 @@ export default mermaid;
export { export {
calcIntersections, calcIntersections,
calcNodeIntersections, calcNodeIntersections,
calcIntersect,
} from './rendering-util/layout-algorithms/fixed/index.js'; } from './rendering-util/layout-algorithms/fixed/index.js';

View File

@@ -163,6 +163,38 @@ export const calcIntersections = (startNodeId, endNodeId, startNodeSize, endNode
return []; return [];
}; };
/**
* @param {string} nodeId
* @param {Pick<Node, 'shape' | 'id' | 'intersect' | 'x' | 'y' | 'width' | 'height'>} node
* @param {Point} point
* @returns {Promise<Point> | Point}
*/
export const calcIntersect = async (nodeId, point) => {
let node = nodeDB.get(nodeId);
if (!node) {
// CReate new nodes in order not to require a rendered diagram
const fakeParent = document.createElementNS('http://www.w3.org/2000/svg', 'g');
const parent = select(fakeParent);
node = Object.assign({}, point);
node.shape = 'rect';
await insertNode(parent, node, 'TB');
// Insert node will not give any widths as the element is not in the DOM
node.width = 50;
node.height = 50;
node.width = 50;
node.height = 50;
}
if (!node) {
throw new Error("Start node doesn't exist in the nodeDB");
}
const intersection = calcIntersectionPoint(node, point);
return intersection;
};
const doRender = async (_elem, data4Layout, siteConfig, positions) => { const doRender = async (_elem, data4Layout, siteConfig, positions) => {
const elem = _elem.insert('g').attr('class', 'root'); const elem = _elem.insert('g').attr('class', 'root');
elem.insert('g').attr('class', 'clusters'); elem.insert('g').attr('class', 'clusters');