Class LinkLabelRouter

GoJS® Diagramming Components
version 3.0.2
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.


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.




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


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


    Returns 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.


    Returns boolean

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


    Returns void