From f1118df317e6210cec7fa363611b00cd20d621fc Mon Sep 17 00:00:00 2001 From: peterkogo Date: Thu, 19 Sep 2024 11:40:19 +0200 Subject: [PATCH 1/4] update absolute positions before initial fitView --- packages/svelte/src/lib/store/index.ts | 6 +++++- packages/system/src/utils/store.ts | 11 +++++++---- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/packages/svelte/src/lib/store/index.ts b/packages/svelte/src/lib/store/index.ts index 24279a45..9f8d1b98 100644 --- a/packages/svelte/src/lib/store/index.ts +++ b/packages/svelte/src/lib/store/index.ts @@ -19,7 +19,8 @@ import { type UpdateConnection, type ConnectionState, type NodeOrigin, - getFitViewNodes + getFitViewNodes, + updateAbsolutePositions } from '@xyflow/system'; import type { EdgeTypes, NodeTypes, Node, Edge, FitViewOptions } from '$lib/types'; @@ -96,6 +97,7 @@ export function createStore({ function updateNodeInternals(updates: Map) { const nodeLookup = get(store.nodeLookup); + const parentLookup = get(store.parentLookup); const { changes, updatedInternals } = updateNodeInternalsSystem( updates, nodeLookup, @@ -108,6 +110,8 @@ export function createStore({ return; } + updateAbsolutePositions(nodeLookup, parentLookup, { nodeOrigin, nodeExtent }); + if (!get(store.fitViewOnInitDone) && get(store.fitViewOnInit)) { const fitViewOptions = get(store.fitViewOptions); const fitViewOnInitDone = fitViewSync({ diff --git a/packages/system/src/utils/store.ts b/packages/system/src/utils/store.ts index 73b6afc9..ec55759a 100644 --- a/packages/system/src/utils/store.ts +++ b/packages/system/src/utils/store.ts @@ -61,11 +61,14 @@ export function updateAbsolutePositions( ) { const _options = mergeObjects(defaultOptions, options); for (const node of nodeLookup.values()) { - if (!node.parentId) { - continue; + if (node.parentId) { + updateChildNode(node, nodeLookup, parentLookup, _options); + } else { + const positionWithOrigin = getNodePositionWithOrigin(node, _options.nodeOrigin); + const extent = isCoordinateExtent(node.extent) ? node.extent : _options.nodeExtent; + const clampedPosition = clampPosition(positionWithOrigin, extent, getNodeDimensions(node)); + node.internals.positionAbsolute = clampedPosition; } - - updateChildNode(node, nodeLookup, parentLookup, _options); } } From b056564c9658bb43b882eebfad5a7e224717ffb5 Mon Sep 17 00:00:00 2001 From: peterkogo Date: Thu, 19 Sep 2024 11:45:33 +0200 Subject: [PATCH 2/4] added changesets --- .changeset/curly-cows-repeat.md | 7 +++++++ .changeset/cyan-frogs-lick.md | 6 ++++++ 2 files changed, 13 insertions(+) create mode 100644 .changeset/curly-cows-repeat.md create mode 100644 .changeset/cyan-frogs-lick.md diff --git a/.changeset/curly-cows-repeat.md b/.changeset/curly-cows-repeat.md new file mode 100644 index 00000000..e9aa2e5e --- /dev/null +++ b/.changeset/curly-cows-repeat.md @@ -0,0 +1,7 @@ +--- +'@xyflow/svelte': patch +'@xyflow/system': patch +'@xyflow/react': patch +--- + +Fix fitView not working correctly for nodeOrigin other than [0,0] diff --git a/.changeset/cyan-frogs-lick.md b/.changeset/cyan-frogs-lick.md new file mode 100644 index 00000000..238d073b --- /dev/null +++ b/.changeset/cyan-frogs-lick.md @@ -0,0 +1,6 @@ +--- +'@xyflow/svelte': patch +'@xyflow/react': patch +--- + +Improve fitView to resepct any clamped node positions based on nodeExtent From 340a54ff6b20f2c785d048ce16d932b6f382db9f Mon Sep 17 00:00:00 2001 From: Peter Kogo <7165378+peterkogo@users.noreply.github.com> Date: Thu, 19 Sep 2024 11:57:28 +0200 Subject: [PATCH 3/4] Update curly-cows-repeat.md --- .changeset/curly-cows-repeat.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.changeset/curly-cows-repeat.md b/.changeset/curly-cows-repeat.md index e9aa2e5e..513a1bf4 100644 --- a/.changeset/curly-cows-repeat.md +++ b/.changeset/curly-cows-repeat.md @@ -4,4 +4,4 @@ '@xyflow/react': patch --- -Fix fitView not working correctly for nodeOrigin other than [0,0] +Fix initial fitView not working correctly for nodeOrigin other than [0,0] From d05a297dacd9a0f5f9a0a68eee318464b6fa254f Mon Sep 17 00:00:00 2001 From: moklick Date: Mon, 23 Sep 2024 15:54:54 +0200 Subject: [PATCH 4/4] chore(changesets): cleanup --- .changeset/curly-cows-repeat.md | 2 +- .changeset/cyan-frogs-lick.md | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.changeset/curly-cows-repeat.md b/.changeset/curly-cows-repeat.md index 513a1bf4..87b3935f 100644 --- a/.changeset/curly-cows-repeat.md +++ b/.changeset/curly-cows-repeat.md @@ -4,4 +4,4 @@ '@xyflow/react': patch --- -Fix initial fitView not working correctly for nodeOrigin other than [0,0] +Fix initial `fitView` not working correctly for `nodeOrigin` other than [0,0] diff --git a/.changeset/cyan-frogs-lick.md b/.changeset/cyan-frogs-lick.md index 238d073b..11109aab 100644 --- a/.changeset/cyan-frogs-lick.md +++ b/.changeset/cyan-frogs-lick.md @@ -3,4 +3,4 @@ '@xyflow/react': patch --- -Improve fitView to resepct any clamped node positions based on nodeExtent +Improve `fitView` to respect clamped node positions based on `nodeExtent`