Update getInternalNodesBounds and examples

This commit is contained in:
Alessandro
2025-10-14 11:33:10 +02:00
parent 4f77447ab5
commit a67f2992b1
5 changed files with 60 additions and 37 deletions

View File

@@ -241,20 +241,25 @@ export const getInternalNodesBounds = <NodeType extends InternalNodeBase | NodeD
nodeLookup: Map<string, NodeType>,
params: GetInternalNodesBoundsParams<NodeType> = {}
): Rect => {
const emptyRect = { x: 0, y: 0, width: 0, height: 0 };
if (nodeLookup.size === 0) {
return { x: 0, y: 0, width: 0, height: 0 };
return emptyRect;
}
let box = { x: Infinity, y: Infinity, x2: -Infinity, y2: -Infinity };
let hasVisibleNodes = false;
nodeLookup.forEach((node) => {
if (params.filter === undefined || params.filter(node)) {
hasVisibleNodes = true;
const nodeBox = nodeToBox(node as InternalNodeBase);
box = getBoundsOfBoxes(box, nodeBox);
}
});
return boxToRect(box);
return hasVisibleNodes ? boxToRect(box) : emptyRect;
};
export const getNodesInside = <NodeType extends NodeBase = NodeBase>(