Skip to content

Commit

Permalink
fixed evaluateAbsolutePosition for nested nodes
Browse files Browse the repository at this point in the history
  • Loading branch information
peterkogo committed Nov 4, 2024
1 parent 49e74dc commit 323e1b3
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 10 deletions.
7 changes: 7 additions & 0 deletions .changeset/wet-hounds-reply.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
'@xyflow/system': patch
'@xyflow/react': patch
'@xyflow/svelte': patch
---

Fix node intersections in nested flow.
15 changes: 5 additions & 10 deletions packages/system/src/utils/general.ts
Original file line number Diff line number Diff line change
Expand Up @@ -252,18 +252,13 @@ export function evaluateAbsolutePosition(
nodeLookup: NodeLookup,
nodeOrigin: NodeOrigin
): XYPosition {
let nextParentId: string | undefined = parentId;
const positionAbsolute = { ...position };

while (nextParentId) {
const parent = nodeLookup.get(nextParentId);
nextParentId = parent?.parentId;

if (parent) {
const origin = parent.origin || nodeOrigin;
positionAbsolute.x += parent.internals.positionAbsolute.x - (dimensions.width ?? 0) * origin[0];
positionAbsolute.y += parent.internals.positionAbsolute.y - (dimensions.height ?? 0) * origin[1];
}
const parent = nodeLookup.get(parentId);
if (parent) {
const origin = parent.origin || nodeOrigin;
positionAbsolute.x += parent.internals.positionAbsolute.x - (dimensions.width ?? 0) * origin[0];
positionAbsolute.y += parent.internals.positionAbsolute.y - (dimensions.height ?? 0) * origin[1];
}

return positionAbsolute;
Expand Down

0 comments on commit 323e1b3

Please sign in to comment.