UNPKG

@rxflow/manhattan

Version:

Manhattan routing algorithm for ReactFlow - generates orthogonal paths with obstacle avoidance

169 lines 4.25 kB
import { Point } from '../geometry'; /** * Direction type for routing */ export type Direction = 'top' | 'right' | 'bottom' | 'left'; /** * ReactFlow internal node structure * Based on ReactFlow's InternalNodeBase type */ export interface InternalNode { id: string; position: { x: number; y: number; }; internals: { positionAbsolute: { x: number; y: number; }; }; measured?: { width?: number; height?: number; }; width?: number; height?: number; initialWidth?: number; initialHeight?: number; type?: string; [key: string]: any; } /** * Node lookup map type (ReactFlow's internal structure) */ export type NodeLookup = Map<string, InternalNode>; /** * Manhattan router configuration options */ export interface ManhattanRouterOptions { /** * The size of step to find a route (the grid of the manhattan pathfinder) * @default 10 */ step?: number; /** * The number of route finding loops that cause the router to abort and return fallback route instead * @default 2000 */ maxLoopCount?: number; /** * The number of decimal places to round floating point coordinates * @default 1 */ precision?: number; /** * The maximum change of direction (in degrees) * @default 90 */ maxDirectionChange?: number; /** * Possible starting directions from a node * @default ['top', 'right', 'bottom', 'left'] */ startDirections?: Direction[]; /** * Possible ending directions to a node * @default ['top', 'right', 'bottom', 'left'] */ endDirections?: Direction[]; /** * Should certain nodes not be considered as obstacles? */ excludeNodes?: string[]; /** * Should certain types of nodes not be considered as obstacles? */ excludeShapes?: string[]; /** * Should the source and/or target not be considered as obstacles? */ excludeTerminals?: ('source' | 'target')[]; /** * The padding applied on the element bounding boxes */ padding?: number | { top: number; right: number; bottom: number; left: number; }; /** * Border radius for rounded corners at path turns (in pixels) * Set to 0 for sharp corners * @default 5 */ borderRadius?: number; /** * Extension distance from node edge for path start/end points (in pixels) * This controls how far the path extends away from the node before turning * @default 20 */ extensionDistance?: number; /** * Source position (from ReactFlow) * Used for smart point generation */ sourcePosition?: string; /** * Target position (from ReactFlow) * Used for smart point generation */ targetPosition?: string; /** * A penalty received for direction change */ penalties?: { [angle: number]: number; }; /** * Fallback route function when pathfinding fails */ fallbackRoute?: (from: Point, to: Point) => Point[]; } /** * Resolved options with all defaults applied */ export interface ResolvedOptions { step: number; maxLoopCount: number; precision: number; maxDirectionChange: number; startDirections: Direction[]; endDirections: Direction[]; excludeNodes: string[]; excludeShapes: string[]; excludeTerminals: ('source' | 'target')[]; paddingBox: { x: number; y: number; width: number; height: number; }; borderRadius: number; extensionDistance: number; sourcePosition?: string; targetPosition?: string; directionMap: { top: Point; right: Point; bottom: Point; left: Point; }; directions: Array<{ cost: number; offsetX: number; offsetY: number; angle?: number; gridOffsetX?: number; gridOffsetY?: number; }>; penalties: { [angle: number]: number; }; cost: number; fallbackRoute?: (from: Point, to: Point) => Point[]; previousDirectionAngle?: number | null; } //# sourceMappingURL=types.d.ts.map