Skip to content

Commit 16bf14c

Browse files
committed
fix(core): smooth step edge horizontally or vertically aligned nodes
1 parent 0bc04e5 commit 16bf14c

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

packages/core/src/components/Edges/utils/smoothstep.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,10 @@ function getPoints({
7272

7373
let points: XYPosition[]
7474
let centerX, centerY
75+
76+
const sourceGapOffset = { x: 0, y: 0 }
77+
const targetGapOffset = { x: 0, y: 0 }
78+
7579
const [defaultCenterX, defaultCenterY, defaultOffsetX, defaultOffsetY] = getSimpleEdgeCenter({
7680
sourceX: source.x,
7781
sourceY: source.y,
@@ -128,6 +132,18 @@ function getPoints({
128132
if (flipSourceTarget) {
129133
points = dirAccessor === 'x' ? sourceTarget : targetSource
130134
}
135+
} else {
136+
const diff = Math.abs(source[dirAccessor] - target[dirAccessor])
137+
138+
// if an edge goes from right to right for example (sourcePosition === targetPosition) and the distance between source.x and target.x is less than the offset, the added point and the gapped source/target will overlap. This leads to a weird edge path. To avoid this we add a gapOffset to the source/target
139+
if (diff <= offset) {
140+
const gapOffset = Math.min(offset - 1, offset - diff)
141+
if (sourceDir[dirAccessor] === currDir) {
142+
sourceGapOffset[dirAccessor] = gapOffset
143+
} else {
144+
targetGapOffset[dirAccessor] = gapOffset
145+
}
146+
}
131147
}
132148

133149
centerX = points[0].x

0 commit comments

Comments
 (0)