# Class LinkLabelRouter

GoJS® Diagramming Components
version 3.0.7
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
  - LinkLabelRouter

A custom Router for reducing overlaps between label objects on links by moving them apart with a custom ForceDirectedLayout. You can modify the properties of that Layout by setting layoutProps in the constructor.

By default, this router considers a "link label" to be any GraphObject that is part of a Link which is not a path Shape or an arrowhead. You can customize objects that the router operates on by overriding LinkLabelRouter.isLabel.

This Router will override the Spot.offsetX and Spot.offsetY of the GraphObject.alignmentFocus value for all link labels.

Typical setup:

      myDiagram.routers.add(new LinkLabelRouter({
         layoutProps: {
           defaultElectricalCharge: 100,
           ...
         }
      }));

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

#####
Index

### Constructors

constructor

### Accessors

layoutProps
margin

### Methods

canRoute
isLabel
routeLinks

#####
Inherited Index

### Accessors

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

### Methods

Router.invalidateRouter

## Constructors

### constructor

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

- #### Parameters

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

  #### Returns LinkLabelRouter

## Accessors

### layoutProps
: Partial<ForceDirectedLayout>

- Properties of the underlying custom ForceDirectedLayout for this router.

### margin
: MarginLike

- Margin that will be applied to each link label when checking for overlaps. The default value is 0 on all sides.

## Methods

### `Override` canRoute

- canRoute(coll: Diagram | Group): boolean

- Determine if the LinkLabelRouter should run on a given collection. By default only run once on the whole Diagram, never on Groups

  #### Parameters

  - ##### coll: Diagram | Group

  #### Returns boolean

### isLabel

- isLabel(obj: GraphObject): boolean

- Determines which GraphObjects in Panel.elements list of each link should be treated as labels. By default this consists of all objects that are not the "main path" of the link, and are not fromArrows or toArrows.

  #### Parameters

  - ##### obj: GraphObject

  #### Returns boolean

### `Override` routeLinks

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

- Attempt to move link label objects to avoid overlaps, if necessary.

  #### Parameters

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

  - ##### coll: Diagram | Group

    A Diagram or a Group

  #### Returns void

Copyright © 1998-2024 by Northwoods Software Corporation.