GoJS API
/ to search
    Preparing search index...

    Class ArrangingLayout

    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 Layout that provides one way to have a layout of layouts. It partitions nodes and links into separate subnetworks, applies a primary layout to each subnetwork, and then arranges those results by an arranging layout. Any disconnected nodes are laid out later by a side layout, by default in a grid underneath the main body of subnetworks.

    This layout uses three separate Layouts.

    One is used for laying out nodes and links that are connected together: primaryLayout. This defaults to null and must be set to an instance of a go.Layout, such as a go.TreeLayout or a go.ForceDirectedLayout or a custom Layout.

    One is used to arrange separate subnetworks of the main graph: arrangingLayout. This defaults to an instance of go.GridLayout.

    One is used for laying out the additional nodes along one of the sides of the main graph: sideLayout. This also defaults to an instance of go.GridLayout. A filter predicate, filter, splits up the collection of nodes and links into two subsets, one for the main layout and one for the side layout. By default, when there is no filter, it puts all nodes that have no link connections into the subset to be processed by the side layout.

    If all pairs of nodes in the main graph can be reached by some path of undirected links, there are no separate subnetworks, so the arrangingLayout need not be used and the primaryLayout would apply to all of those nodes and links.

    But if there are disconnected subnetworks, the primaryLayout is applied to each subnetwork, and then all of those results are arranged by the arrangingLayout. If you don't want to use an arrangingLayout and you want to force the primaryLayout to operate on all of the subnetworks, set arrangingLayout to null.

    In either case if there are any nodes in the side graph, those are arranged by the sideLayout to be on the side of the arrangement of the main graph of nodes and links. The side property controls which side they will be placed -- the default is BottomSide.

    Note: if you do not want to have singleton nodes be arranged by sideLayout, set filter to part => true. That will cause all singleton nodes to be arranged by arrangingLayout as if they were each their own subnetwork.

    If you both don't want to use sideLayout and you don't want to use arrangingLayout to lay out connected subnetworks, don't use this ArrangingLayout at all -- just use whatever Layout you would have assigned to primaryLayout.

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

    Hierarchy (View Summary)

    Index

    Constructors

    Accessors

    • 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 arrangingLayout(): Layout | null

      Gets or sets the Layout used to arrange multiple separate connected subnetworks of the main graph. The default value is an instance of GridLayout. Set this property to null in order to get the primaryLayout to operate on all connected graphs as a whole.

      Returns Layout | null

    • 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 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 filter(): ((part: Part) => boolean) | null

      Gets or sets the predicate function to call on each non-Link. If the predicate returns true, the part will be laid out by the main layouts, the primaryLayouts and the arrangingLayout, otherwise by the sideLayout. The default value is a function that is true when there are any links connecting with the node. Such default behavior will have the sideLayout position all of the singleton nodes.

      Returns ((part: Part) => boolean) | null

    • 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 primaryLayout(): Layout

      Gets or sets the Layout used for the main part of the diagram. The default value is an instance of GridLayout. Any new value must not be null.

      Returns Layout

    • get side(): Spot

      Gets or sets the side go.Spot where the side nodes and links should be laid out, relative to the results of the main Layout. The default value is Spot.BottomSide.

      If the value is Spot.Bottom, Spot.Top, Spot.Right, or Spot.Left, the side nodes will be centered along that side.

      Currently only handles a single side.

      Returns Spot

    • get sideLayout(): Layout

      Gets or sets the Layout used to arrange the 'side' nodes and links -- those outside of the main layout. The default value is an instance of GridLayout. Any new value must not be null.

      Returns Layout

    • get spacing(): Size

      Gets or sets the space between the main layout and the side layout. The default value is Size(20, 20).

      Returns Size

    Methods

    • 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>

    • When using a LayoutNetwork, commit changes to the diagram by setting Node positions and by routing the Links. This is called by updateParts within a transaction.

      You should not call this method -- it is a "protected virtual" method. This may be overridden by subclasses of Layout. By default this method is implemented as follows:

      protected commitLayout() {
      if (this.network === null) return;
      const vit = this.network.vertexes.iterator;
      while (vit.next()) {
      const vert = vit.value;
      vert.commit();
      }
      if (this.isRouting) {
      const eit = this.network.edges.iterator;
      while (eit.next()) {
      const edge = eit.value;
      edge.commit();
      }
      }
      }

      Please read the Learn page on Extensions for how to override methods and how to call this base method.

      Returns void

    • 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

    • This method is called just after the sideLayout has been performed in order to move its parts to the desired area relative to the results of the main layouts. By default this calls go.Diagram.moveParts on the sidecoll collection to the side of the mainbounds. This won't get called if there are no Parts in the sidecoll collection.

      Parameters

      • sidecoll: Set<Part>

        a collection of Parts that were laid out by the sideLayout

      • mainbounds: Rect

        the area occupied by the results of the main layouts

      • sidebounds: Rect

        the area occupied by the results of the sideLayout

      Returns void

    • Move a Set of Nodes and Links to the given area.

      Parameters

      • subColl: Set<Part>

        the Set of Nodes and Links that form a separate connected subnetwork

      • subbounds: Rect

        the area occupied by the subColl

      • bounds: Rect

        the area where they should be moved according to the arrangingLayout

      Returns void

    • This method is called just before the primaryLayout is performed so that there can be adjustments made to the primaryLayout, if desired. By default this method makes no adjustments to the primaryLayout.

      Parameters

      • primaryLayout: Layout

        the primaryLayout that may be modified for the achieving different results from that layout

      • mainColl: Set<Part>

        the Nodes and Links to be laid out by primaryLayout after being separated into subnetworks

      Returns void

    • This method is called just after the main layouts (the primaryLayouts and arrangingLayout) have been performed and just before the sideLayout is performed so that there can be adjustments made to the sideLayout, if desired. By default this method makes no adjustments to the sideLayout.

      Parameters

      • sideLayout: Layout

        the sideLayout that may be modified for the results of the main layouts

      • sideColl: Set<Part>

        the Nodes and Links filtered out to be laid out by sideLayout

      • mainBounds: Rect

        the area occupied by the nodes and links of the main layout, after it was performed

      Returns void

    • Assign all of the Parts in the given collection into either the set of Nodes and Links for the main graph or the set of Nodes and Links for the side graph.

      By default this just calls the filter on each non-Link to decide, and then looks at each Link's connected Nodes to decide.

      A null filter assigns all Nodes that have connected Links to the main graph, and all Links will be assigned to the main graph, and the side graph will only contain Parts with no connected Links.

      Parameters

      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