getNodesBounds()
返回包含数组中所有给定节点的边界框。当与 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
¥This function was previously called 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:Name | Type | Default |
---|---|---|
nodes | (string | NodeType | InternalNodeBase<NodeType>)[] Nodes to calculate the bounds for. | |
params.nodeOrigin | NodeOrigin Origin of the nodes: | [0, 0] |
params.nodeLookup | NodeLookup<InternalNodeBase<NodeType>> |
Last updated on