From 18fd67300f6b802bfa419fe6825eafa14e19c15a Mon Sep 17 00:00:00 2001 From: Feroz Mujawar Date: Tue, 29 Oct 2024 14:23:37 +0530 Subject: [PATCH 1/2] fix intersection required object read from db while resizing node --- .../layout-algorithms/fixed/index.js | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) 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 aa668d834..30d428431 100644 --- a/packages/mermaid/src/rendering-util/layout-algorithms/fixed/index.js +++ b/packages/mermaid/src/rendering-util/layout-algorithms/fixed/index.js @@ -75,14 +75,23 @@ const calcIntersectionPoint = (node, point) => { * @param {Pick} _node2 * @returns {Promise | IntersectionPoint[]} */ -export const calcNodeIntersections = async (_node1, _node2) => { +export const calcNodeIntersections = async (targetNodeId, _node1, _node2) => { // 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); - const node1 = Object.assign({}, _node1); - const node2 = Object.assign({}, _node2); - await insertNode(parent, node1, 'TB'); - await insertNode(parent, node2, 'TB'); + let node1 = Object.assign({}, _node1); + let node2 = Object.assign({}, _node2); + + if (!targetNodeId || targetNodeId === _node1.id) { + await insertNode(parent, node1, 'TB'); + } else { + node1 = Object.assign({}, nodeDB.get(_node1.id)); + } + if (!targetNodeId || targetNodeId === _node2.id) { + await insertNode(parent, node2, 'TB'); + } else { + node2 = Object.assign({}, nodeDB.get(_node2.id)); + } // Insert node will not give any widths as the element is not in the DOM node1.width = _node1.width || 50; From ddeab2f70532c67de5223cf07f107700431d4a95 Mon Sep 17 00:00:00 2001 From: Feroz Mujawar Date: Mon, 11 Nov 2024 14:34:54 +0530 Subject: [PATCH 2/2] lint fix --- docs/config/setup/modules/mermaid.md | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/docs/config/setup/modules/mermaid.md b/docs/config/setup/modules/mermaid.md index 016831724..2e35de817 100644 --- a/docs/config/setup/modules/mermaid.md +++ b/docs/config/setup/modules/mermaid.md @@ -118,20 +118,21 @@ If the start node doesn't exist in the nodeDB (e.g. `render` hasn't been called #### Defined in -[packages/mermaid/src/rendering-util/layout-algorithms/fixed/index.js:106](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/rendering-util/layout-algorithms/fixed/index.js#L106) +[packages/mermaid/src/rendering-util/layout-algorithms/fixed/index.js:115](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/rendering-util/layout-algorithms/fixed/index.js#L115) --- ### calcNodeIntersections -▸ **calcNodeIntersections**(`_node1`, `_node2`): `IntersectionPoint`\[] | `Promise`<`IntersectionPoint`\[]> +▸ **calcNodeIntersections**(`targetNodeId`, `_node1`, `_node2`): `IntersectionPoint`\[] | `Promise`<`IntersectionPoint`\[]> #### Parameters -| Name | Type | -| :------- | :------------------------------------------------------------------------------------------------ | -| `_node1` | `Pick`<`Node`, `"width"` \| `"height"` \| `"x"` \| `"y"` \| `"id"` \| `"shape"` \| `"intersect"`> | -| `_node2` | `Pick`<`Node`, `"width"` \| `"height"` \| `"x"` \| `"y"` \| `"id"` \| `"shape"` \| `"intersect"`> | +| Name | Type | +| :------------- | :------------------------------------------------------------------------------------------------ | +| `targetNodeId` | `any` | +| `_node1` | `Pick`<`Node`, `"width"` \| `"height"` \| `"x"` \| `"y"` \| `"id"` \| `"shape"` \| `"intersect"`> | +| `_node2` | `Pick`<`Node`, `"width"` \| `"height"` \| `"x"` \| `"y"` \| `"id"` \| `"shape"` \| `"intersect"`> | #### Returns