Skip to content

Commit 0558ff8

Browse files
committed
fix(bezieredge): correctly connect diagonally nodes closes xyflow#256
1 parent c620d0f commit 0558ff8

File tree

2 files changed

+16
-4
lines changed

2 files changed

+16
-4
lines changed

example/src/Horizontal/index.js

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,20 @@ const onLoad = (graph) => {
99
const initialElements = [
1010
{ id: '1', sourcePosition: 'right', type: 'input', className: 'dark-node', data: { label: 'Input' }, position: { x: 0, y: 80 } },
1111
{ id: '2', sourcePosition: 'right', targetPosition: 'left', data: { label: 'A Node' }, position: { x: 250, y: 0 } },
12-
{ id: '3', sourcePosition: 'right', targetPosition: 'left', data: { label: 'Another node' }, position: { x: 250, y: 160 } },
13-
{ id: '4', sourcePosition: 'right', targetPosition: 'left', data: { label: 'Node 4' }, position: { x: 500, y: 80 } },
12+
{ id: '3', sourcePosition: 'right', targetPosition: 'left', data: { label: 'Node 3' }, position: { x: 250, y: 160 } },
13+
{ id: '4', sourcePosition: 'right', targetPosition: 'left', data: { label: 'Node 4' }, position: { x: 500, y: 0 } },
14+
{ id: '5', sourcePosition: 'top', targetPosition: 'bottom', data: { label: 'Node 5' }, position: { x: 500, y: 100 } },
15+
{ id: '6', sourcePosition: 'bottom', targetPosition: 'top', data: { label: 'Node 6' }, position: { x: 500, y: 230 } },
16+
{ id: '7', sourcePosition: 'right', targetPosition: 'left', data: { label: 'Node 7' }, position: { x: 750, y: 50 } },
17+
{ id: '8', sourcePosition: 'right', targetPosition: 'left', data: { label: 'Node 8' }, position: { x: 750, y: 300 } },
18+
1419
{ id: 'e1-2', source: '1', target: '2', animated: true, },
1520
{ id: 'e1-3', source: '1', target: '3', animated: true, },
16-
{ id: 'e1-4', source: '2', target: '4', label: 'edge label' }
21+
{ id: 'e1-4', source: '2', target: '4', label: 'edge label' },
22+
{ id: 'e3-5', source: '3', target: '5', animated: true },
23+
{ id: 'e3-6', source: '3', target: '6', animated: true },
24+
{ id: 'e5-7', source: '5', target: '7', animated: true },
25+
{ id: 'e6-8', source: '6', target: '8', animated: true },
1726
];
1827

1928
const HorizontalFlow = () => {

src/components/Edges/BezierEdge.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,13 @@ export default memo(
2626
let dAttr = `M${sourceX},${sourceY} C${sourceX},${centerY} ${targetX},${centerY} ${targetX},${targetY}`;
2727

2828
const leftAndRight = [Position.Left, Position.Right];
29+
2930
if (leftAndRight.includes(sourcePosition) && leftAndRight.includes(targetPosition)) {
3031
dAttr = `M${sourceX},${sourceY} C${centerX},${sourceY} ${centerX},${targetY} ${targetX},${targetY}`;
31-
} else if (leftAndRight.includes(sourcePosition) || leftAndRight.includes(targetPosition)) {
32+
} else if (leftAndRight.includes(targetPosition)) {
3233
dAttr = `M${sourceX},${sourceY} C${sourceX},${targetY} ${sourceX},${targetY} ${targetX},${targetY}`;
34+
} else if (leftAndRight.includes(sourcePosition)) {
35+
dAttr = `M${sourceX},${sourceY} C${targetX},${sourceY} ${targetX},${sourceY} ${targetX},${targetY}`;
3336
}
3437

3538
const text = label ? (

0 commit comments

Comments
 (0)