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