getViewportForBounds()
此工具返回给定边界的视口。你可以使用它来预先计算服务器上给定节点集合的视口,或者为给定边界计算视口,而无需直接更改视口。
🌐 This util returns the viewport for 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.
Note
这个函数以前被称为 getTransformForBounds
import { getViewportForBounds } from '@xyflow/react';
const { x, y, zoom } = getViewportForBounds(
{
x: 0,
y: 0,
width: 100,
height: 100,
},
1200,
800,
0.5,
2,
);签名
🌐 Signature
Parameters:| Name | Type | Default |
|---|---|---|
bounds | RectBounds to fit inside viewport. | |
width | numberWidth of the viewport. | |
height | numberHeight of the viewport. | |
minZoom | numberMinimum zoom level of the resulting viewport. | |
maxZoom | numberMaximum zoom level of the resulting viewport. | |
padding | PaddingPadding around the bounds. |
A transformed Viewport that encloses the given bounds which you can pass to e.g. setViewport .
| Name | Type |
|---|---|
x | number |
y | number |
zoom | number |
注释
🌐 Notes
Last updated on