參考工具

getViewportForBounds()

在 Github 上的原始碼

此工具會返回給定邊界的視口。您可以使用它來預先計算伺服器上給定節點集的視口,或計算給定邊界的視口,而無需直接更改視口。

ℹ️

此函式先前稱為 getTransformForBounds

import { getViewportForBounds } from '@xyflow/react';
 
const { x, y, zoom } = getViewportForBounds(
  {
    x: 0,
    y: 0,
    width: 100,
    height: 100,
  },
  1200,
  800,
  0.5,
  2,
);

簽名

#參數
#bounds
Rect
#width
number
#height
number
#minZoom
number
#maxZoom
number
#padding?
number
0.1
#返回
#viewport
Viewport
轉換後的視口 (`{ x: number, y: number, zoom: number }`)。

注意

  • 這是一個相當底層的工具。您可能想看看 fitViewfitBounds 方法,以取得更實用的 API。