Search
Link Routing

Routed links avoid nodes marked as obstacles (call the getObstacle and setObstacle methods) by finding the shortest path between their origin and destination that does not cross any other nodes.

Setting Up a Link Router

The control finds paths for links affected by modifications of nearby nodes by calling methods of an object that implements the LinkRouter interface. This object can be get or set through the LinkRouter property of the Diagram class. JDiagram provides a few classes that implement LinkRouter - PatternRouter, GridRouter, QuickRouter and CompositeRouter. By default LinkRouter is set to a CompositeRouter instance.

Automatic or Explicit Routing

The routeAllLinks method can be invoked to explicitly rearrange links in a way they do not cross nodes. In addition, links have an AutoRoute property that enables or disables automatic routing of a link; that property is initialized from the diagram's RouteLinks value. The TriggerRerouting property of RoutingOptions class specifies when links should be rerouted automatically.

Tuning the Routing Algorithm

When a GridRouter is used, the RoutingOptions class allows customizing various aspects of the routing algorithm. That algorithm evaluates possible paths aiming to find one that has a minimal cost. The values set through the setLengthCost, setTurnCost, setCrossingCost and setNodeVicinityCost methods are added to the total cost of a route and have a great influence over the shape of the chosen path. The orientation of the first and the last segment of the routed links can be specified by calling the setStartOrientation and setEndOrientation methods respectively.