From e03d6c23ec4353b84ee41892f88105ee0683dc27 Mon Sep 17 00:00:00 2001 From: moklick Date: Thu, 16 Jun 2022 11:59:52 +0200 Subject: [PATCH] fix(selection): only calculate selection box if selected nodes > 0 --- example/src/Layouting/index.tsx | 9 ++++++++- src/utils/graph.ts | 4 ++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/example/src/Layouting/index.tsx b/example/src/Layouting/index.tsx index 88170feb..8e4ce5bf 100644 --- a/example/src/Layouting/index.tsx +++ b/example/src/Layouting/index.tsx @@ -59,6 +59,10 @@ const LayoutFlow = () => { setNodes(layoutedNodes); }; + const unselect = () => { + setNodes((nds) => nds.map((n) => ({ ...n, selected: false }))); + }; + return (
@@ -77,7 +81,10 @@ const LayoutFlow = () => { - + +
diff --git a/src/utils/graph.ts b/src/utils/graph.ts index 37765a01..a426baed 100644 --- a/src/utils/graph.ts +++ b/src/utils/graph.ts @@ -141,6 +141,10 @@ export const pointToRendererPoint = ( }; export const getRectOfNodes = (nodes: Node[]): Rect => { + if (nodes.length === 0) { + return { x: 0, y: 0, width: 0, height: 0 }; + } + const box = nodes.reduce( (currBox, { positionAbsolute, position, width, height }) => getBoundsOfBoxes(