Import it from @grafloria/renderer.
WaypointEditor
Handles interactive waypoint editing on link paths:
- Add waypoints by clicking on path
- Move waypoints by dragging
- Remove waypoints by double-click
- Grid snapping
- Distance constraints
Architecture: Modular tool that can be enabled/disabled via InteractionConfig
tsclass WaypointEditor
Methods
constructor(config: WaypointEditorConfig)getWaypointAt(index: number, points: Point[]): Waypoint | null— Get waypoint at specific indexisWaypoint(index: number, points: Point[]): boolean— Check if point at index is a waypoint (not an endpoint)getWaypoints(points: Point[]): Waypoint[]— Get all waypoints (excluding endpoints)hitTestWaypoint( mouseX: number, mouseY: number, points: Point[], hitSlop = 0 ): WaypointHitResult | null— Hit test for clicking on a waypoint handle Optimized to avoid allocations on hot path (mousemove)hitTestPath( mouseX: number, mouseY: number, points: Point[], hitSlop = 0 ): PathHitResult | null— Hit test for clicking on a path segment (to add waypoint)addWaypointAtPosition( clickX: number, clickY: number, points: Point[] ): AddWaypointResult | null— Add waypoint at click position on pathmoveWaypoint( waypointIndex: number, newPosition: Point, points: Point[], pathType?: 'direct' | 'orthogonal' | 'smooth' | 'bezier' | 'straight' ): Point[] | null— Move waypoint to new position For orthogonal paths, just move the waypoint - the rendering will use orthogonal routingremoveWaypoint(waypointIndex: number, points: Point[]): Point[] | null— Remove waypoint at indexsnapToGrid(point: Point): Point— Snap point to griddistanceToSegment(point: Point, segmentStart: Point, segmentEnd: Point): number— Calculate distance from point to line segmentdistance(p1: Point, p2: Point): number— Calculate Euclidean distance between two pointsgetConfig(): WaypointEditorConfig— Get current configurationupdateConfig(updates: Partial<WaypointEditorConfig>): void— Update configurationrenderWaypointHandle(waypoint: Waypoint, linkId: string): VNode— Render waypoint handle as VNoderenderWaypointHandles(points: Point[], linkId: string): VNode[]— Render all waypoint handles for a link
Was this page helpful?