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
@@ -61,16 +61,19 @@
height: store.height / store.viewport.zoom
});
const hasVisibleNodes = $derived(store.nodeLookup.size > 0 && store.nodes.some((n) => !n.hidden));
// let boundingRect = $derived(
// store.nodeLookup.size > 0 && store.nodes.some((n) => !n.hidden)
// ? getBoundsOfRects(
// getInternalNodesBounds(store.nodeLookup, { filter: (n) => !n.hidden }),
// viewBB
// )
// : viewBB
// );
let boundingRect = $derived(
hasVisibleNodes
? getBoundsOfRects(
getInternalNodesBounds(store.nodeLookup, { filter: (n) => !n.hidden }),
viewBB
)
: viewBB
getBoundsOfRects(getInternalNodesBounds(store.nodeLookup, { filter: (n) => !n.hidden }), viewBB)
);
let scaledWidth = $derived(boundingRect.width / width);
let scaledHeight = $derived(boundingRect.height / height);
let viewScale = $derived(Math.max(scaledWidth, scaledHeight));
@@ -124,7 +127,7 @@
{#each store.nodes as userNode (userNode.id)}
{@const node = store.nodeLookup.get(userNode.id)}
{#if node && nodeHasDimensions(node)}
{#if node && nodeHasDimensions(node) && !node.hidden}
{@const nodeDimesions = getNodeDimensions(node)}
<MinimapNode
x={node.internals.positionAbsolute.x}
+7 -2
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>(