參考utils

getNodesBounds()

在 GitHub 上查看原始碼

傳回包含陣列中所有指定節點的邊界框。當與 getViewportForBounds 結合使用時,這會很有用,用於計算正確的轉換以將指定節點放入視窗中。

ℹ️

此函數先前稱為 getRectOfNodes,將在 v12 中移除。

import { getNodesBounds } from '@xyflow/svelte';
 
const nodes = [
  {
    id: 'a',
    position: { x: 0, y: 0 },
    data: { label: 'a' },
    width: 50,
    height: 25,
  },
  {
    id: 'b',
    position: { x: 100, y: 100 },
    data: { label: 'b' },
    width: 50,
    height: 25,
  },
];
 
const bounds = getNodesBounds(nodes);

簽名

#參數
#nodes
Node[]
#傳回
Rect