getTransformForBounds()
此函数已弃用,将在 React Flow 12 中删除。改用 getViewportForBounds。
¥This function is deprecated and will be removed in React Flow 12. Use getViewportForBounds instead.
此实用程序告诉你将视口设置为多少以适合给定边界。你可以使用它来预先计算服务器上给定一组节点的视口,或者计算给定边界的视口,而无需直接更改视口。
¥This util tells you what to set the viewport to in order to fit the given bounds. You might use this to pre-calculate the viewport for a given set of nodes on the server or calculate the viewport for the given bounds without changing the viewport directly.
import { getTransformForBounds } from 'reactflow';
const transform = getTransformForBounds(
{
x: 0,
y: 0,
width: 100,
height: 100,
},
1200,
800,
0.5,
2,
);签名
¥Signature
| Name | Type | Default |
|---|---|---|
#Params | | |
# bounds | Rect | |
# width | number | |
# height | number | |
# minZoom | number | |
# maxZoom | number | |
# padding? | number | |
#Returns | | |
# [0] | numberThe x position of the transformed viewport. | |
# [1] | numberThe y position of the transformed viewport | |
# [2] | numberThe zoom level of the transformed viewport. | |
注释
¥Notes
-
这是一个相当底层的实用工具。你可能需要查看
fitView或fitBounds方法以获得更实用的 api。¥This is quite a low-level utility. You might want to look at the
fitVieworfitBoundsmethods for a more practical api. -
此函数称为 getTransform…出于历史原因。它的返回类型表示元组形式的
Viewport。¥This function is called getTransform… for historical reasons. Its return type represents a
Viewportin tuple form.