|
1 | | -import type { Actions, EdgePositions, GraphEdge, GraphNode, HandleElement, ViewportTransform, XYPosition } from '../types' |
| 1 | +import type { Actions, GraphEdge, GraphNode, HandleElement, ViewportTransform, XYPosition } from '../types' |
2 | 2 | import { Position } from '../types' |
3 | | -import { rectToBox } from '.' |
| 3 | +import { getNodeDimensions, rectToBox } from '.' |
4 | 4 |
|
5 | | -export function getHandlePosition(position: Position, node: GraphNode, handle: HandleElement | null): XYPosition { |
| 5 | +export function getHandlePosition( |
| 6 | + node: GraphNode, |
| 7 | + handle: HandleElement | null, |
| 8 | + fallbackPosition: Position = Position.Left, |
| 9 | +): XYPosition { |
6 | 10 | const x = (handle?.x ?? 0) + node.computedPosition.x |
7 | 11 | const y = (handle?.y ?? 0) + node.computedPosition.y |
8 | | - const width = handle?.width ?? node.dimensions.width |
9 | | - const height = handle?.height ?? node.dimensions.height |
| 12 | + const { width, height } = handle ?? getNodeDimensions(node) |
| 13 | + const position = handle?.position ?? fallbackPosition |
10 | 14 |
|
11 | 15 | switch (position) { |
12 | 16 | case Position.Top: |
@@ -40,25 +44,6 @@ export function getHandle(bounds: HandleElement[] = [], handleId?: string | null |
40 | 44 | return (!handleId ? bounds[0] : bounds.find((d) => d.id === handleId)) || null |
41 | 45 | } |
42 | 46 |
|
43 | | -export function getEdgePositions( |
44 | | - sourceNode: GraphNode, |
45 | | - sourceHandle: HandleElement | null, |
46 | | - sourcePosition: Position, |
47 | | - targetNode: GraphNode, |
48 | | - targetHandle: HandleElement | null, |
49 | | - targetPosition: Position, |
50 | | -): EdgePositions { |
51 | | - const { x: sourceX, y: sourceY } = getHandlePosition(sourcePosition, sourceNode, sourceHandle) |
52 | | - const { x: targetX, y: targetY } = getHandlePosition(targetPosition, targetNode, targetHandle) |
53 | | - |
54 | | - return { |
55 | | - sourceX, |
56 | | - sourceY, |
57 | | - targetX, |
58 | | - targetY, |
59 | | - } |
60 | | -} |
61 | | - |
62 | 47 | interface IsEdgeVisibleParams { |
63 | 48 | sourcePos: XYPosition |
64 | 49 | targetPos: XYPosition |
|
0 commit comments