參考utils

getViewportForBounds()

Github 上的原始碼

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

import { getViewportForBounds } from '@xyflow/svelte';
 
const { x, y, zoomn } = 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。