Skip to content

EdgeRoutingManager

Internal manager for registration, selection, and execution of edge routing implementations.

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.

const middleware: Middleware = {
name: 'routing-optimizer',
execute: (context, next) => {
const routingManager = context.edgeRoutingManager;
const defaultRouting = routingManager.getDefaultRouting();
console.log('Using routing:', defaultRouting);
next();
}
};

computePath(routingName, points): string

Computes an SVG path string for the given points using the specified routing.

The routing to use. If omitted or undefined, the default routing is used.

undefined | EdgeRoutingName

Point[]

The points to convert into an SVG path string

string

An SVG path string suitable for the d attribute of an SVG <path> element

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(routingName, points, percentage): Point

Computes a point along the path at a given percentage.

The routing to use. If omitted or undefined, the default routing is used.

undefined | EdgeRoutingName

Point[]

The path points

number

Position along the path in range [0, 1] where 0 = start, 1 = end

Point

The interpolated point on the path

If the selected routing implements computePointOnPath, it will be used. Otherwise, falls back to linear interpolation between the first and last points.

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(routingName, context): Point[]

Computes the routed points for an edge using the specified routing algorithm.

The routing to use. If omitted or undefined, the default routing is used.

undefined | EdgeRoutingName

EdgeRoutingContext

The routing context containing source/target nodes, ports, edge data, etc.

Point[]

The computed polyline as an array of points

const points = routingManager.computePoints('orthogonal', {
sourceNode: node1,
targetNode: node2,
sourcePosition: { x: 100, y: 50 },
targetPosition: { x: 300, y: 200 },
edge: edge
});

getDefaultRouting(): EdgeRoutingName

Gets the current default routing name.

EdgeRoutingName

The name of the current default routing


getRegisteredRoutings(): EdgeRoutingName[]

Gets all registered routing names.

EdgeRoutingName[]

An array of registered routing names (built-in and custom)


getRouting(name): undefined | EdgeRouting

Gets a routing implementation by name.

EdgeRoutingName

The routing name to look up

undefined | EdgeRouting

The routing implementation or undefined if not registered


hasRouting(name): boolean

Checks whether a routing is registered.

EdgeRoutingName

The routing name to check

boolean

true if registered; otherwise false


registerRouting(routing): void

Registers (or replaces) a routing implementation.

EdgeRouting

The routing instance to register. Its name must be non-empty.

void


setDefaultRouting(name): void

Sets the default routing to use for all edges when no specific routing is specified.

EdgeRoutingName

The routing name to set as default

void


unregisterRouting(name): void

Unregisters a routing by name.

EdgeRoutingName

The routing name to remove

void