Class RouterAbstract

GoJS® Diagramming Components
version 3.0.12
by Northwoods Software®

Hierarchy

A Router is a class that is responsible for the paths of a collection of Links.

Some routers modify the Link.points of some Links in ways that the default routing provided by Link.computePoints cannot, because the latter method only considers the properties of the Link and its connected ports -- not other Nodes or Links.

Some routers modify other aspects of Links.

The most commonly used Router is the AvoidsLinksRouter extension in the extensions or extensionsJSM directories.

The Router class is abstract and does not really provide any functionality of its own. You can install a Router subclass by constructing and initializing it and then inserting it into the Diagram.routers list.

myDiagram.routers.add(new AvoidsLinksRouter());

A Router that has been installed will automatically operate on the Links of Groups or the top-level Links of the Diagram.

You can disable a Router by setting its isEnabled property to false, or by overriding canRoute to decide when it should operate.

Your subclass of Router should override routeLinks method in order to examine the Links implicitly given to the method.

since

3.0

Index

Constructors

  • Don't construct this directly -- this is an abstract class.

    Returns Router

Accessors

  • Gets or sets the Diagram this router is associated with. Routers cannot be shared.

  • Gets or sets whether this router is enabled.

  • Gets or sets whether this router runs during real-time operations, such as dragging or resizing. The default is true.

  • Gets or sets the name of this router.

Methods

  • Determine for the given collection if this router can route.

    Adding a Router to the Diagram will cause the Diagram to call canRoute for every group recursively, and finally for the Diagram itself.

    By default this returns false if isRealtime is false and a realtime operation (such as dragging or resizing) is ongoing, or else false if a default animation is running, or else the value of isEnabled.

    If true, routeLinks will be called on each collection.

    An override of this method should return false if isEnabled is false, or return false is if a call to the base method is false.

    This method is only called by the Diagram. If using a Router without adding it to a Diagram, this method will never be called.

    Parameters

    • container: Diagram | Group

      A Diagram or Group on which the Router will operate.

    Returns boolean

  • If this router has been added to a diagram, calling this method will ensure the Diagram re-runs all routing.

    The router should call this method when setting properties that might require the router to re-run when values change.

    Returns void

  • Route the links for a given collection (Group or Diagram). By default this is called in a depth-first manner on every Group in the Diagram, and then the Diagram itself. If a layout occurred for a Group or a Diagram, this is called immediately afterwards if canRoute returns true.

    It is common to route all links in each Group's Group.memberParts, and then all top-level links in the Diagram.links collection. (All Links that have Part.containingGroup === null)

    The first argument is a Set of Links that the Diagram has collected which it considers invalid. Typically, these are the only links that need routing. Since routeLinks is called with each Group and then the Diagram, you should check the Part.containingGroup on each Link to ensure it matches:

     public routeLinks(links: GSet<Link>, container?: Diagram | Group): void {
    const container = container instanceof Diagram ? null : container;
    const it = links.iterator;
    while (it.next()) {
    const link = it.value;
    // Only operate on links that are in the corresponding collection, if one is given
    if (container && link.containingGroup !== container) continue;
    . . .

    This method should not check the canRoute predicate.

    Parameters

    • links: Set<Link>

      The set of links that were recently recomputed, which may need routing.

    • Optional container: Diagram | Group

      A Diagram or Group on which the Router will operate. When calling a router manually, this does not need to be specified.

    Returns void