Skip to Content
参考手册实用程序

getViewportForBounds()

Github 上的源代码

¥Source on Github

此实用程序返回给定边界的视口。你可以使用它来预先计算服务器上给定一组节点的视口,或者计算给定边界的视口,而无需直接更改视口。

¥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

¥This function was previously called 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:
NameTypeDefault
boundsRect

Bounds to fit inside viewport.

widthnumber

Width of the viewport.

heightnumber

Height of the viewport.

minZoomnumber

Minimum zoom level of the resulting viewport.

maxZoomnumber

Maximum zoom level of the resulting viewport.

paddingPadding

Padding around the bounds.

Returns:

A transformed Viewport that encloses the given bounds which you can pass to e.g. setViewport .

NameType
xnumber
ynumber
zoomnumber

注释

¥Notes

  • 这是一个相当底层的实用工具。你可能需要查看 fitViewfitBounds 方法以获得更实用的 api。

    ¥This is quite a low-level utility. You might want to look at the fitView or fitBounds methods for a more practical api.

Last updated on