|
1 | | -import type { Actions, EdgePositions, GraphEdge, GraphNode, HandleElement, Rect, ViewportTransform, XYPosition } from '../types' |
| 1 | +import type { Actions, EdgePositions, GraphEdge, GraphNode, HandleElement, ViewportTransform, XYPosition } from '../types' |
2 | 2 | import { Position } from '../types' |
3 | 3 | import { rectToBox } from '.' |
4 | 4 |
|
5 | | -export function getHandlePosition(position: Position, rect: Rect, handle: HandleElement | null): XYPosition { |
6 | | - const x = (handle?.x ?? 0) + rect.x |
7 | | - const y = (handle?.y ?? 0) + rect.y |
8 | | - const width = handle?.width ?? rect.width |
9 | | - const height = handle?.height ?? rect.height |
| 5 | +export function getHandlePosition(position: Position, node: GraphNode, handle: HandleElement | null): XYPosition { |
| 6 | + const x = (handle?.x ?? 0) + node.computedPosition.x |
| 7 | + const y = (handle?.y ?? 0) + node.computedPosition.y |
| 8 | + const width = handle?.width ?? node.dimensions.width |
| 9 | + const height = handle?.height ?? node.dimensions.height |
10 | 10 |
|
11 | 11 | switch (position) { |
12 | 12 | case Position.Top: |
@@ -48,28 +48,14 @@ export function getEdgePositions( |
48 | 48 | targetHandle: HandleElement | null, |
49 | 49 | targetPosition: Position, |
50 | 50 | ): EdgePositions { |
51 | | - const sourceHandlePos = getHandlePosition( |
52 | | - sourcePosition, |
53 | | - { |
54 | | - ...sourceNode.dimensions, |
55 | | - ...sourceNode.computedPosition, |
56 | | - }, |
57 | | - sourceHandle, |
58 | | - ) |
59 | | - const targetHandlePos = getHandlePosition( |
60 | | - targetPosition, |
61 | | - { |
62 | | - ...targetNode.dimensions, |
63 | | - ...targetNode.computedPosition, |
64 | | - }, |
65 | | - targetHandle, |
66 | | - ) |
| 51 | + const { x: sourceX, y: sourceY } = getHandlePosition(sourcePosition, sourceNode, sourceHandle) |
| 52 | + const { x: targetX, y: targetY } = getHandlePosition(targetPosition, targetNode, targetHandle) |
67 | 53 |
|
68 | 54 | return { |
69 | | - sourceX: sourceHandlePos.x, |
70 | | - sourceY: sourceHandlePos.y, |
71 | | - targetX: targetHandlePos.x, |
72 | | - targetY: targetHandlePos.y, |
| 55 | + sourceX, |
| 56 | + sourceY, |
| 57 | + targetX, |
| 58 | + targetY, |
73 | 59 | } |
74 | 60 | } |
75 | 61 |
|
|
0 commit comments