Update getInternalNodesBounds and examples
This commit is contained in:
@@ -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}
|
||||
|
||||
@@ -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>(
|
||||
|
||||
Reference in New Issue
Block a user