GoJS API
/ to search
    Preparing search index...

    Class LinkLabelRouter

    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.

    Hierarchy (View Summary)

    Index

    Constructors

    Accessors

    • get diagram(): Diagram

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

      Returns Diagram

    • get isEnabled(): boolean

      Gets or sets whether this router is enabled.

      Returns boolean

    • get isRealtime(): boolean

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

      Returns boolean

    • get margin(): MarginLike

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

      Returns MarginLike

    • get name(): string

      Gets or sets the name of this router.

      Returns string

    Methods

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

      Parameters

      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

    • 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 a "main path" of the link, and are not fromArrows or toArrows.

      Parameters

      Returns boolean

    • Decide whether a given Link should be routed or ignored.

      By default this just returns true.

      Parameters

      Returns boolean

      whether or not this Router should operate on the given Link

      since

      3.1