libavoid-js
    Preparing search index...

    Interface Router

    Routes connectors around obstacles (shapes and junctions). Owns everything added to it; router.delete() frees all of it.

    Changes (adding, moving and deleting objects, changing settings) are collected and applied together by processTransaction(), which then re-routes the affected connectors.

    interface Router {
        delete(): void;
        "[dispose]"(): void;
        isDeleted(): boolean;
        isAliasOf(other: Handle): boolean;
        processTransaction(): boolean;
        printInfo(): void;
        setRoutingParameter(parameter: RoutingParameterValue, value: number): void;
        setRoutingOption(option: RoutingOptionValue, value: boolean): void;
        addShape(
            shape: RectLike | readonly PointLike[],
            options?: AddOptions,
        ): ShapeRef;
        moveShape(shape: ShapeRef, newShape: RectLike | readonly PointLike[]): void;
        moveShape(shape: ShapeRef, dx: number, dy: number): void;
        deleteShape(shape: ShapeRef): void;
        addJunction(position: PointLike, options?: AddOptions): JunctionRef;
        moveJunction(junction: JunctionRef, position: PointLike): void;
        moveJunction(junction: JunctionRef, dx: number, dy: number): void;
        deleteJunction(junction: JunctionRef): void;
        addConnector(
            source: ConnEndLike,
            destination: ConnEndLike,
            options?: AddOptions,
        ): ConnRef;
        deleteConnector(connector: ConnRef): void;
    }

    Hierarchy (View Summary)

    Index
    • For the router: frees it and everything added to it. For other objects: removes the object. Shapes, junctions and connectors are removed through their router, like router.deleteShape(shape), with the same restrictions; a pin is removed from its shape or junction immediately. Everything the object owns goes with it. Using the object afterwards throws.

      Returns void

    • True once the object was freed, whether by its own delete() or by deleting its owner (e.g. a pin's shape, or the router).

      Returns boolean

    • Applies all changes made since the last call and re-routes the affected connectors, calling their callbacks (see ConnRef.setCallback).

      Returns boolean

      False if there was nothing to do: no objects were added, moved or deleted and no settings were changed since the last call.

    • Prints statistics about the router's internal visibility graph (numbers of shapes, vertices and edges) to stdout, which is the console in a browser. For debugging.

      Returns void

    • Sets a numeric routing parameter. Parameters are either distances, such as shapeBufferDistance (the space kept between connectors and shapes), or penalties, such as segmentPenalty (a cost added for every bend, so that routes with fewer bends are preferred). 0 turns a penalty off; a negative value picks a sensible default. Takes effect at the next processTransaction().

      Parameters

      Returns void

      TypeError or RangeError if parameter is not a RoutingParameter value or value is not a finite number.

      libavoid: each parameter, with its default, is documented on libavoid's RoutingParameter enum.

    • Turns a routing option on or off. Takes effect at the next processTransaction().

      Parameters

      Returns void

      TypeError or RangeError if option is not a RoutingOption value.

      libavoid: each option, with its default, is documented on libavoid's RoutingOption enum.

    • Adds a shape that connectors are routed around: a rectangle (top-left corner + size) or a polygon of at least 3 points. Connectors attach to a shape through its pins (shape.addPin). Takes effect at the next processTransaction().

      Parameters

      Returns ShapeRef

      RangeError if a polygon has fewer than 3 points.

      libavoid: new ShapeRef(router, polygon, id); a rectangle is passed as a 4-point polygon.

    • Moves or resizes the shape to a new rectangle or polygon. The number of points cannot change (a rectangle has 4): to change it, delete the shape and add a new one. Takes effect at the next processTransaction().

      Parameters

      Returns void

      RangeError if the number of points differs from the shape's.

      libavoid: Router::moveShape(shape, polygon). The restriction on the number of points comes from libavoid.

    • Moves the shape by dx, dy. Takes effect at the next processTransaction().

      Parameters

      Returns void

    • Removes the shape and its pins at the next processTransaction(). A shape cannot be removed in the transaction that added it: call processTransaction() first.

      Parameters

      Returns void

      Error if the shape was added in the current transaction.

      libavoid: the restriction comes from libavoid, which asserts (and aborts the module) in that case.

    • Adds a junction: a point where several connectors meet, e.g. to draw a connection between more than two objects (a hyperedge) as a tree. Connectors attach to it with {junction}. Takes effect at the next processTransaction().

      Parameters

      Returns JunctionRef

      libavoid: new JunctionRef(router, position, id).

    • Removes the junction and its pins at the next processTransaction(). Like a shape, a junction cannot be removed in the transaction that added it.

      Parameters

      Returns void

      Error if the junction was added in the current transaction.

    • Adds a connector between two ends, routed at the next processTransaction(). An end is a free point {x, y}, a class of a shape's pins {shape, pin} or a junction {junction}. The connector is routed as a polyline if the router supports polyline routing, otherwise orthogonally; see ConnRef.setRoutingType.

      Parameters

      Returns ConnRef

      libavoid: new ConnRef(router, id) followed by setSourceEndpoint and setDestEndpoint.