fix(selection): only calculate selection box if selected nodes > 0
This commit is contained in:
@@ -59,6 +59,10 @@ const LayoutFlow = () => {
|
||||
setNodes(layoutedNodes);
|
||||
};
|
||||
|
||||
const unselect = () => {
|
||||
setNodes((nds) => nds.map((n) => ({ ...n, selected: false })));
|
||||
};
|
||||
|
||||
return (
|
||||
<div className="layoutflow">
|
||||
<ReactFlowProvider>
|
||||
@@ -77,7 +81,10 @@ const LayoutFlow = () => {
|
||||
<button onClick={() => onLayout('TB')} style={{ marginRight: 10 }}>
|
||||
vertical layout
|
||||
</button>
|
||||
<button onClick={() => onLayout('LR')}>horizontal layout</button>
|
||||
<button onClick={() => onLayout('LR')} style={{ marginRight: 10 }}>
|
||||
horizontal layout
|
||||
</button>
|
||||
<button onClick={() => unselect()}>unselect nodes</button>
|
||||
</div>
|
||||
</ReactFlowProvider>
|
||||
</div>
|
||||
|
||||
@@ -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(
|
||||
|
||||
Reference in New Issue
Block a user