# Class AvoidsLinksRouter

GoJS® Diagramming Components
version 3.0.5
by Northwoods Software®

This is an extension and not part of the main GoJS library. Note that the API for this class may change at any time. If you intend to use an extension in production, you should copy the code to your own source directory. See the Extensions intro page for more information.

#### Hierarchy

- Router
  - AvoidsLinksRouter

A custom Router that will cause overlapping segments of Orthogonal or AvoidsNodes links to be routed in parallel, while minimizing resulting crossings between links.

The maximum distance that resulting sets of links will be spread apart is given by AvoidsLinksRouter.linkSpacing.

By default the router will reduce the space between parallel segments to prevent them from overlapping nearby Nodes, however this behavior can be disabled by setting AvoidsLinksRouter.avoidsNodes to false. If that property is set to false, then all modified sets of links will be at a distance of exactly AvoidsLinksRouter.linkSpacing, even if this causes some of the links to overlap a nearby Node.

Typical setup:

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

If you want to experiment with this extension, try the AvoidsLinksRouter sample.

#####
Index

### Constructors

constructor

### Accessors

avoidsNodes
epsilonDistance
ignoreContainingGroups
iterations
linkSpacing

### Methods

canRoute
routeLinks

#####
Inherited Index

### Accessors

Router.diagram
Router.isEnabled
Router.isRealtime
Router.name

### Methods

Router.invalidateRouter

## Constructors

### constructor

- new AvoidsLinksRouter(init?: Partial<AvoidsLinksRouter>): AvoidsLinksRouter

- #### Parameters

  - ##### `Optional` init: Partial<AvoidsLinksRouter>

  #### Returns AvoidsLinksRouter

## Accessors

### avoidsNodes
: boolean

- Gets or sets whether the AvoidsLinksRouter should reduce spacing between separated Links to avoid overlap with nearby Nodes. If avoidsNodes is false, all separated links will have a distance of exactly linkSpacing, even if this causes them to cross over a nearby Node.

  The default value is true.

### epsilonDistance
: number

- Gets or sets the minimum distance between links for them to be considered "overlapping" and be separated by AvoidsLinksRouter. Large values of this parameter compared to linkSpacing can make the resulting groups of segments less evenly-spaced, so it is recommended to use a small value for this parameter - ideally a small fraction of linkSpacing.

  The default value is 0.5.

### ignoreContainingGroups
: boolean

- Gets or sets whether the router will run only once on the top-level Diagram, considering all links regardless of their containing group.

  If false, the router will instead separately route the top-level links against links in each Group, which is more efficient but may have undefined results when links route in and out of nested Groups.

  The default value is false.

### iterations
: number

- Gets or sets the number of times the AvoidsLinksRouter will run iteratively. In the vast majority of cases, one iteration should be enough and this parameter should not need to be modified. Multiple iterations may be useful when numerous links coincide, particularly when they are close to Nodes with avoidsNodes set to true.

  The default value is 1.

### linkSpacing
: number

- Gets or sets the desired distance between Links that are separated by AvoidsLinksRouter. If avoidsNodes is true, this value is the maximum allowed distance between such links, but the distance could be smaller to avoid overlapping Nodes.

  The default value is 4.

## Methods

### `Override` canRoute

- canRoute(coll: Diagram | Group): boolean

- Determine whether the AvoidsLinksRouter should operate on a given collection. See ignoreContainingGroups for the default behavior.

  #### Parameters

  - ##### coll: Diagram | Group

  #### Returns boolean

### `Override` routeLinks

- routeLinks(links: Set<Link>, coll: Diagram | Group): void

- Adjust segments of all links in the Diagram to prevent overlap.

  #### Parameters

  - ##### links: Set<Link>

  - ##### coll: Diagram | Group

    A Diagram or a Group

  #### Returns void

Copyright © 1998-2024 by Northwoods Software Corporation.