getSmoothStepPath()
该 getSmoothStepPath 工具返回渲染两个节点之间阶梯路径所需的一切信息。 borderRadius 属性可用于选择这些阶梯的圆角程度。
import { Position, getSmoothStepPath } from '@xyflow/react';
 
const source = { x: 0, y: 20 };
const target = { x: 150, y: 100 };
 
const [path, labelX, labelY, offsetX, offsetY] = getSmoothStepPath({
  sourceX: source.x,
  sourceY: source.y,
  sourcePosition: Position.Right,
  targetX: target.x,
  targetY: target.y,
  targetPosition: Position.Left,
});
 
console.log(path); //=> "M0 20L20 20L 70,20Q 75,20 75,25L 75,95Q ..."
console.log(labelX, labelY); //=> 75, 60
console.log(offsetX, offsetY); //=> 75, 40签名
| 名称 | 类型 | 默认值 | 
|---|---|---|
| #参数 |  |  | 
| # sourceX | number |  | 
| # sourceY | number |  | 
| # sourcePosition | Position |  | 
| # targetX | number |  | 
| # targetY | number |  | 
| # targetPosition? | Position |  | 
| # borderRadius? | number |  | 
| # centerX? | number |  | 
| # centerY? | number |  | 
| # offset? | number |  | 
| #返回值 |  |  | 
| # [0] | string在 SVG <path> 元素中使用的路径。 |  | 
| # [1] | number可用于渲染此边标签的 x 坐标。 |  | 
| # [2] | number可用于渲染此边标签的 y 坐标。 |  | 
| # [3] | number源 x 坐标和此路径中间点的 x 坐标之间的绝对差值。 |  | 
| # [4] | number源 y 坐标和此路径中间点的 y 坐标之间的绝对差值。 |  | 
备注
- 此函数返回元组(即固定大小的数组)以便于同时处理多个边路径。
- 可以将 borderRadius属性设置为0以获得阶梯边路径。