參考工具

getSimpleBezierPath()

在 Github 上的原始碼

getSimpleBezierPath 工具會回傳呈現兩個節點之間簡單貝茲曲線邊緣所需的所有內容。

import { Position, getSimpleBezierPath } from '@xyflow/react';
 
const source = { x: 0, y: 20 };
const target = { x: 150, y: 100 };
 
const [path, labelX, labelY, offsetX, offsetY] = getSimpleBezierPath({
  sourceX: source.x,
  sourceY: source.y,
  sourcePosition: Position.Right,
  targetX: target.x,
  targetY: target.y,
  targetPosition: Position.Left,
});
 
console.log(path); //=> "M0,20 C75,20 75,100 150,100"
console.log(labelX, labelY); //=> 75, 60
console.log(offsetX, offsetY); //=> 75, 40

簽名

#參數
#params
物件
#params.sourceX
數字
#params.sourceY
數字
#params.sourcePosition?
Position
Position.Bottom
#params.targetX
數字
#params.targetY
數字
#params.targetPosition?
Position
Position.Top
#回傳值
#[0]
字串
要在 SVG <path> 元素中使用的路徑。
#[1]
數字
您可以使用的 x 位置,以便呈現此邊緣的標籤。
#[2]
數字
您可以使用的 y 位置,以便呈現此邊緣的標籤。
#[3]
數字
來源 x 位置與此路徑中間的 x 位置之間的絕對差異。
#[4]
數字
來源 y 位置與此路徑中間的 y 位置之間的絕對差異。

筆記

  • 此函式會回傳元組(又稱固定大小的陣列),以便更容易同時處理多個邊緣路徑。