EdgeRoutingManager
Internal manager for registration, selection, and execution of edge routing implementations.
Remarks
Section titled “Remarks”For application code, use NgDiagramService routing methods instead.
This class is exposed primarily for middleware development where you can access it
via context.edgeRoutingManager.
The manager comes pre-populated with built-in routings (orthogonal, bezier, polyline).
You can register custom routings at runtime.
Example
Section titled “Example”const middleware: Middleware = { name: 'routing-optimizer', execute: (context, next) => { const routingManager = context.edgeRoutingManager; const defaultRouting = routingManager.getDefaultRouting(); console.log('Using routing:', defaultRouting); next(); }};Methods
Section titled “Methods”computePath()
Section titled “computePath()”computePath(
routingName,points):string
Computes an SVG path string for the given points using the specified routing.
Parameters
Section titled “Parameters”routingName
Section titled “routingName”The routing to use. If omitted or undefined, the default routing is used.
undefined | EdgeRoutingName
points
Section titled “points”Point[]
The points to convert into an SVG path string
Returns
Section titled “Returns”string
An SVG path string suitable for the d attribute of an SVG <path> element
Example
Section titled “Example”const points = [{ x: 0, y: 0 }, { x: 100, y: 100 }, { x: 200, y: 100 }];const path = routingManager.computePath('polyline', points);// Returns: "M 0 0 L 100 100 L 200 100"computePointOnPath()
Section titled “computePointOnPath()”computePointOnPath(
routingName,points,percentage):Point
Computes a point along the path at a given percentage.
Parameters
Section titled “Parameters”routingName
Section titled “routingName”The routing to use. If omitted or undefined, the default routing is used.
undefined | EdgeRoutingName
points
Section titled “points”Point[]
The path points
percentage
Section titled “percentage”number
Position along the path in range [0, 1] where 0 = start, 1 = end
Returns
Section titled “Returns”The interpolated point on the path
Remarks
Section titled “Remarks”If the selected routing implements computePointOnPath, it will be used.
Otherwise, falls back to linear interpolation between the first and last points.
Example
Section titled “Example”const points = [{ x: 0, y: 0 }, { x: 100, y: 100 }];const midpoint = routingManager.computePointOnPath('polyline', points, 0.5);// Returns: { x: 50, y: 50 }const quarterPoint = routingManager.computePointOnPath('polyline', points, 0.25);// Returns: { x: 25, y: 25 }computePoints()
Section titled “computePoints()”computePoints(
routingName,context):Point[]
Computes the routed points for an edge using the specified routing algorithm.
Parameters
Section titled “Parameters”routingName
Section titled “routingName”The routing to use. If omitted or undefined, the default routing is used.
undefined | EdgeRoutingName
context
Section titled “context”The routing context containing source/target nodes, ports, edge data, etc.
Returns
Section titled “Returns”Point[]
The computed polyline as an array of points
Example
Section titled “Example”const points = routingManager.computePoints('orthogonal', { sourceNode: node1, targetNode: node2, sourcePosition: { x: 100, y: 50 }, targetPosition: { x: 300, y: 200 }, edge: edge});getDefaultRouting()
Section titled “getDefaultRouting()”getDefaultRouting():
EdgeRoutingName
Gets the current default routing name.
Returns
Section titled “Returns”The name of the current default routing
getRegisteredRoutings()
Section titled “getRegisteredRoutings()”getRegisteredRoutings():
EdgeRoutingName[]
Gets all registered routing names.
Returns
Section titled “Returns”An array of registered routing names (built-in and custom)
getRouting()
Section titled “getRouting()”getRouting(
name):undefined|EdgeRouting
Gets a routing implementation by name.
Parameters
Section titled “Parameters”The routing name to look up
Returns
Section titled “Returns”undefined | EdgeRouting
The routing implementation or undefined if not registered
hasRouting()
Section titled “hasRouting()”hasRouting(
name):boolean
Checks whether a routing is registered.
Parameters
Section titled “Parameters”The routing name to check
Returns
Section titled “Returns”boolean
true if registered; otherwise false
registerRouting()
Section titled “registerRouting()”registerRouting(
routing):void
Registers (or replaces) a routing implementation.
Parameters
Section titled “Parameters”routing
Section titled “routing”The routing instance to register. Its name must be non-empty.
Returns
Section titled “Returns”void
setDefaultRouting()
Section titled “setDefaultRouting()”setDefaultRouting(
name):void
Sets the default routing to use for all edges when no specific routing is specified.
Parameters
Section titled “Parameters”The routing name to set as default
Returns
Section titled “Returns”void
unregisterRouting()
Section titled “unregisterRouting()”unregisterRouting(
name):void
Unregisters a routing by name.
Parameters
Section titled “Parameters”The routing name to remove
Returns
Section titled “Returns”void