getSmoothStepPath()
The getSmoothStepPath util returns everything you need to render a stepped path between two nodes. The borderRadius property can be used to choose how rounded the corners of those steps are.
import { Position, getSmoothStepPath } from '@xyflow/svelte';
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以获得一个阶梯状边路径。