GoJS API
/ to search
    Preparing search index...

    Class SwimLaneLayout

    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 LayeredDigraphLayout that knows about "lanes" and that positions each node in its respective lane.

    This assumes that each Node.data.lane property is a string that names the lane the node should be in. You can set the laneProperty property to use a different data property name. It is commonplace to set this property to be the same as the go.GraphLinksModel.nodeGroupKeyProperty, so that the one property indicates that a particular node data is a member of a particular group and thus that that group represents a lane.

    The lanes can be sorted by specifying the laneComparer function.

    You can add extra space between the lanes by increasing laneSpacing from its default of zero. That number's unit is columns, go.LayeredDigraphLayout.columnSpacing, not in document coordinates.

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

    Hierarchy (View Summary)

    Index

    Constructors

    Accessors

    • get alignOption(): LayeredDigraphAlign

      Gets or sets the options used by the straighten and pack function, as a faster alternative to packOption.

      When using this option, nodes are assigned coordinates within their layers to produce straighter paths of nodes and small edge lengths.

      When used as an alternative to packOption, this tends to be faster, particularly for larger graphs. Larger graphs, however, will usually be less compact than when using packOption. If this option is set, packOption is ignored.

      This option does not use columns, but rather uses columnSpacing to space nodes within a layer.

      The value must be a combination of the LayeredDigraphAlign bit flags.

      Using LayeredDigraphAlign.All will tend to provide the most balanced results and is what we recommend starting with.

      The default value is LayeredDigraphAlign.All. When the value is LayeredDigraphAlign.None, the packOption is used instead.

      Returns LayeredDigraphAlign

      since

      2.3

    • get arrangementOrigin(): Point

      Gets or sets the top-left point for where the graph should be positioned when laid out. The default value for this property is the Point(0, 0). Setting this property to a new value invalidates this layout. This property is likely to be set by many Layouts that belong to a Group when the layout is performed.

      Returns Point

    • get boundsComputation(): ((part: Part, lay: Layout, rect: Rect) => Rect) | null

      Gets or sets a function that determines the initial size and position in document coordinates of a LayoutVertex corresponding to a Node. This function is called by getLayoutBounds. The default value for this property is null, in which case the GraphObject.actualBounds of the Node is used. Setting this property to a new value invalidates this layout.

      The non-null value must be a function that takes 3 arguments. The first argument will be the Part whose bounds the Layout should use. The second argument will be this Layout. The third argument will be a Rect that must be modified and returned The return value must be in document coordinates. You may find it convenient to call GraphObject.getDocumentBounds to get the bounds in document coordinates of an object within the node.

      Returns ((part: Part, lay: Layout, rect: Rect) => Rect) | null

      since

      2.0

    • get centered(): boolean

      Gets or sets how the nodes in each layer are positioned within each layer. Each node is aligned in the center of its layer according to its LayoutVertex.focus (the default positioning) or at the top or the left side of the layer if LayeredDigraphVertex.centered is false.

      The default value is true. This property provides the default value for LayeredDigraphVertex.centered.

      Returns boolean

      since

      3.1

    • get columnSpacing(): number

      Gets or sets the size of each column. This value must be positive and it defaults to 25.

      When using alignOption, this will act as node spacing for nodes within a layer.

      Returns number

    • get diagram(): Diagram | null

      Gets the Diagram that owns this layout, if it is the value of Diagram.layout.

      If this property and group are non-null, the Group should be in this Diagram.

      Returns Diagram | null

      see

      group

    • get direction(): number

      Gets or sets the direction the graph grows towards. 0 is towards the right, 90 is downwards, 180 is towards the left, and 270 is upwards. The default value is 0.

      Returns number

    • get group(): Group | null

      Gets the Group that uses this layout, if it is the value of a group's Group.layout.

      If this property is set to a Group, the diagram is automatically set to be the Group's Diagram.

      Returns Group | null

    • get isInitial(): boolean

      Gets or sets whether this layout is performed on an initial layout. The default value is true. Setting this property to false causes isValidLayout to be set to true so that the diagram does not perform this layout.

      If you set both isInitial and isOngoing to false, there will be no automatic layout invalidation, because invalidateLayout will not set isValidLayout to false. To get your nodes to appear, you will need to explicitly set or data-bind their Part.location or GraphObject.position to real Point values, because automatic layout will not assign any positions.

      Another way of controlling when layouts are invalidated is by setting Part.isLayoutPositioned or Part.layoutConditions.

      Returns boolean

    • get isOngoing(): boolean

      Gets or sets whether this layout can be invalidated by invalidateLayout. Set this to false to prevent actions such as adding or removing Parts from invalidating this layout. The default value is true. Setting this property does not invalidate this layout.

      If you set both isInitial and isOngoing to false, there will be no automatic layout invalidation, because invalidateLayout will not set isValidLayout to false. To get your nodes to appear, you will need to explicitly set or data-bind their Part.location or GraphObject.position to real Point values, because automatic layout will not assign any positions.

      Another way of controlling when layouts are invalidated is by setting Part.isLayoutPositioned or Part.layoutConditions.

      Returns boolean

    • get isRealtime(): boolean | null

      Gets or sets whether this layout be performed in real-time, before the end of a transaction. All layouts that are invalidated will be performed at the end of a transaction. The default value is null. A null value is treated as true for a Diagram.layout but false for a Group.layout. Setting this property does not invalidate this layout.

      Returns boolean | null

    • get isRouting(): boolean

      Gets or sets whether this layout routes Links. The default value is true. When false, this layout will not explicitly set the Link.points, and the default routing of each individual Link will take place after the Nodes are moved by commitLayout. Setting this property does not invalidate this layout.

      Some layouts ignore links, in which case this property is ignored.

      Returns boolean

    • get isValidLayout(): boolean

      Gets or sets whether this layout needs to be performed again (if false). Instead of setting this property directly, it is normal to set it to false by calling invalidateLayout, since that also requests performing a layout in the near future.

      Returns boolean

    • get isViewportSized(): boolean

      Gets or sets whether this layout depends on the Diagram.viewportBounds's size. If set to true, the layout will invalidate when the Diagram's viewport changes size. This only applies to diagram layouts, not to group layouts, and only when Diagram.autoScale is set to AutoScale.None.

      The default value is false. Setting this property to true will invalidate this layout.

      It is possible that a viewport-sized layout will trigger the Diagram to require scrollbars, which modifies the Diagram.viewportBounds, which will in turn trigger another layout. This is uncommon, but possible with GridLayout if the results require a vertical scrollbar, and that vertical scrollbar shrinks the viewport width enough that a grid column can no longer fit. When designing custom layouts, one should be careful that this behavior does not result in an infinite loop.

      Returns boolean

    • get iterations(): number

      Gets or sets the number of iterations to be done. The value must be non-negative. The default value is 4.

      Returns number

    • get laneBreadths(): Map<string, number>

      The computed breadths (widths or heights depending on the direction) of each lane, in the form of a Map mapping lane names (strings) to numbers.

      Returns Map<string, number>

    • get laneComparer(): ((a: string, b: string) => number) | null

      Gets or sets a function by which to compare lane names, for ordering the lanes within the laneNames Array. By default the function is null -- the lanes are not sorted.

      Returns ((a: string, b: string) => number) | null

    • get laneNames(): string[]

      Gets or sets an Array of lane names. If you set this before a layout happens, it will use those lanes in that order. Any additional lane names that it discovers will be added to the end of this Array.

      This property is reset to an empty Array at the end of each layout. The default value is an empty Array.

      Returns string[]

    • get lanePositions(): Map<string, number>

      The computed positions of each lane, in the form of a Map mapping lane names (strings) to numbers.

      Returns Map<string, number>

    • get laneProperty(): string | ((d: any) => string)

      Gets or sets the name of the data property that holds the string which is the name of the lane that the node should be in. The default value is "lane".

      Returns string | ((d: any) => string)

    • get laneSpacing(): number

      Gets or sets the amount of additional space it allocates between the lanes. This number specifies the number of columns, with the same meaning as go.LayeredDigraphLayout.columnSpacing. The number unit is not in document coordinate or pixels. The default value is zero columns.

      Returns number

    • get layerSpacing(): number

      Gets or sets the space between each layer. This value must be non-negative and it defaults to 25.

      Returns number

    • get maxColumn(): number

      This read-only property returns the largest column value.

      Returns number

    • get maxIndex(): number

      This read-only property returns the largest index value.

      Returns number

    • get maxIndexLayer(): number

      This read-only property returns the larges index layer.

      Returns number

    • get maxLayer(): number

      This read-only property returns the largest layer value.

      Returns number

    • get minIndexLayer(): number

      This read-only property returns the smallest index layer.

      Returns number

    • get packOption(): LayeredDigraphPack

      Gets or sets the options used by the straighten and pack function; this option is deprecated -- alignOption usually produces a better alignment, faster.

      The value must be a combination of bit flags. The default value is LayeredDigraphLayout.PackAll, which is a combination of all three flags.

      Each of the flags has a cost; Expand is particularly slow. However if you do not set this property, this layout will automatically turn off the Expand option for you if the graph is large enough. You can set this property value to LayeredDigraphLayout.PackNone to avoid most of the work.

      This option is ignored if alignOption is set to a value other than LayeredDigraphAlign.None. This tends to be slower than alignOption, particularly for larger graphs. Larger graphs, however, will usually be more compact than when using alignOption.

      Returns LayeredDigraphPack

      deprecated
    • get setsPortSpots(): boolean

      Gets or sets whether the FromSpot and ToSpot of each link should be set to values appropriate for the given value of LayeredDigraphLayout.direction. The default value is true.

      If you set this to false, the spot values of the links and port objects will be used. If you do not set the spot values to sensible values matching the direction, the routing results may be poor and they may cross over nodes.

      Returns boolean

    Methods

    • Assigns every vertex in the input network to a layer. The layer is a non-negative integer describing which row of vertexes each vertex belongs in. (Do not confuse this concept of "layer" with Layers that control the Z-ordering of Parts.)

      The layering satisfies the following relationship: if L is a link from node U to node V, then U.layer > V.layer.

      This method can be overridden to customize how nodes are assigned layers. Please read the Learn page on Extensions for how to override methods and how to call this base method. By default, this does the appropriate assignments given the value of layeringOption.

      Returns void

    • A convenient way of converting the Diagram|Group|Iterable argument to doLayout to an actual collection of eligible Parts. The resulting Set will not include any Nodes or Links for which Part.canLayout is false. If the argument includes a Group for which Group.layout is null, the resulting Set will include the member parts of that group rather than that group itself. You will not need to call collectParts if you call makeNetwork, because that method does effectively the same thing when building the LayoutNetwork.

      Typical usage:

      public doLayout(coll) {
      // COLL might be a Diagram or a Group or some Iterable<Part>
      const it = this.collectParts(coll).iterator;
      while (it.next()) {
      const node = it.value;
      if (node instanceof go.Node) {
      . . . position the node . . .
      }
      }
      }

      Parameters

      Returns Set<Part>

    • This overridable method is called by commitLayout to support custom arrangement of bands or labels across each layout layer. By default this method does nothing.

      The coordinates used in the resulting Rects may need to be offset by the Layout.arrangementOrigin.

      Parameters

      • layerRects: Rect[]

        an Array of Rects with the bounds of each of the "layers"

      • offset: Point

        the position of the top-left corner of the banded area relative to the coordinates given by the layerRects

      Returns void

    • Set the fromSpot and toSpot on each Link, position each Node according to the vertex position, and then position/route the Links.

      This calls the commitNodes and commitLinks methods, the latter only if isRouting is true. You should not call this method -- it is a "protected virtual" method. Please read the Learn page on Extensions for how to override methods and how to call this base method.

      Returns void

    • Return the minimum lane width, in columns

      Parameters

      • lane: string

      Returns number

    • This is just like getLane but handles dummy vertexes for which the getLane returns null by returning the lane of the edge's source or destination vertex. This can only be called after the lanes have been set up internally.

      Parameters

      Returns string | null

    • Given a vertex, get the lane (name) that its node belongs in. If the lane appears to be undefined, this returns the empty string. For dummy vertexes (with no node) this will return null.

      Parameters

      Returns string | null

    • This method is called by layouts to determine the size and initial position of the nodes that it is laying out. Normally this just returns the part's GraphObject.actualBounds. However, if boundsComputation has been set to a function, that function will be called in order to return the bounds of the given Part in document coordinates that the layout should pretend it has.

      Parameters

      • part: Part

        the Part being laid out

      • Optionalrect: Rect

        an optional Rect that will be modified and returned

      Returns Rect

      a Rect in document coordinates

      since

      2.0

    • Compute the desired value of arrangementOrigin if this Layout is being performed for a Group. This is typically called near the beginning of the implementation of doLayout: this.arrangementOrigin = this.initialOrigin(this.arrangementOrigin); if the layout wants to respect the pre-layout location of the Group when deciding where to position its member nodes.

      Parameters

      Returns Point

    • If isOngoing is true and if an initial layout has not yet been performed, set the isValidLayout property to false, and ask to perform another layout in the near future. If isInitial is true, this layout is invalidated only when the Diagram.model is replaced, not under the normal circumstances such as when parts are added or removed or due to other calls to Layout._invalidateLayout.

      If you set both isInitial and isOngoing to false, there will be no automatic layout invalidation, because this method will not set isValidLayout to false. However you can still set isValidLayout explicitly.

      This is typically called when a layout property value has changed, or when a Part is added or removed or changes visibility, if Part.layoutConditions includes the pertinent flags.

      Returns void

    • When using a LayoutNetwork, update the "physical" node positionings and link routings. This should be called by doLayout when this layout uses a network. This calls commitLayout to actually set Node positions and route Links. This performs the changes within a transaction. Please read the Learn page on Extensions for how to override methods and how to call this base method.

      Returns void

    Properties

    AggressiveLess: Less = LayeredDigraphAggressive.Less
    AggressiveMore: More = LayeredDigraphAggressive.More
    AggressiveNone: None = LayeredDigraphAggressive.None
    AlignAll: All = LayeredDigraphAlign.All
    deprecated

    See LayeredDigraphAlign.All.

    AlignLowerLeft: LowerLeft = LayeredDigraphAlign.LowerLeft
    AlignLowerRight: LowerRight = LayeredDigraphAlign.LowerRight
    AlignNone: None = LayeredDigraphAlign.None
    deprecated

    See LayeredDigraphAlign.None.

    AlignUpperLeft: UpperLeft = LayeredDigraphAlign.UpperLeft
    AlignUpperRight: UpperRight = LayeredDigraphAlign.UpperRight
    CycleDepthFirst: DepthFirst = LayeredDigraphCycleRemove.DepthFirst
    CycleFromLayers: FromLayers = LayeredDigraphCycleRemove.FromLayers
    CycleGreedy: Greedy = LayeredDigraphCycleRemove.Greedy
    InitDepthFirstIn: DepthFirstIn = LayeredDigraphInit.DepthFirstIn
    InitDepthFirstOut: DepthFirstOut = LayeredDigraphInit.DepthFirstOut
    InitNaive: Naive = LayeredDigraphInit.Naive
    deprecated

    See LayeredDigraphInit.Naive.

    LayerLongestPathSink: LongestPathSink = LayeredDigraphLayering.LongestPathSink
    LayerLongestPathSource: LongestPathSource = LayeredDigraphLayering.LongestPathSource
    LayerOptimalLinkLength: OptimalLinkLength = LayeredDigraphLayering.OptimalLinkLength
    PackAll: All = LayeredDigraphPack.All
    deprecated
    PackExpand: Expand = LayeredDigraphPack.Expand
    deprecated
    PackMedian: Median = LayeredDigraphPack.Median
    deprecated
    PackNone: None = LayeredDigraphPack.None
    deprecated
    PackStraighten: Straighten = LayeredDigraphPack.Straighten
    deprecated