getNodesBounds()

GitHub上のソースコード

与えられたノードの配列を含む境界ボックスを返します。これは、getViewportForBounds と組み合わせて、与えられたノードをビューポートに合わせるための正しい変換を計算する場合に便利です。

ℹ️

この関数は以前getRectOfNodesと呼ばれていました。

import { getNodesBounds } from '@xyflow/react';
 
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