Skip to Content
参考实用程序

getNodesBounds()

GitHub上的源代码 

返回包含数组中所有给定节点的边界框。当与getViewportForBounds结合使用时,这在计算将给定节点适合视口的正确变换时非常有用。

🌐 Returns the bounding box that contains all the given nodes in an array. This can be useful when combined with getViewportForBounds to calculate the correct transform to fit the given nodes in a viewport.

Note

这个函数以前被称为 getRectOfNodes

import { getNodesBounds } from '@xyflow/react'; const nodes = [ { id: 'a', position: { x: 0, y: 0 }, data: { label: 'a' }, width: 50, height: 25, }, { id: 'b', position: { x: 100, y: 100 }, data: { label: 'b' }, width: 50, height: 25, }, ]; const bounds = getNodesBounds(nodes);

签名

🌐 Signature

Parameters:
NameTypeDefault
nodes(string | NodeType | InternalNodeBase<NodeType>)[]

Nodes to calculate the bounds for.

params.nodeOriginNodeOrigin

Origin of the nodes: [0, 0] for top-left, [0.5, 0.5] for center.

[0, 0]
params.nodeLookupNodeLookup<InternalNodeBase<NodeType>>
Returns:
Rect

Bounding box enclosing all nodes.

Last updated on