Layout class

This is the base class for all of the predefined diagram layout implementations. They only arrange Parts (primarily Nodes and Links) in a Diagram, not to GraphObjects in Panels (i.e. panel layout).

The layout classes include TreeLayout, ForceDirectedLayout, LayeredDigraphLayout, CircularLayout, and GridLayout. This base class is not abstract -- in fact an instance of this base class is the default value for Diagram#layout and for Group#layout.

An instance of a Layout class will be the value of Diagram#layout. That layout positions the graph of top-level nodes and links. Nodes and links that belong to a Group are laid out by that group's Group#layout. The Diagram will automatically perform all nested group layouts before laying out the whole diagram.

If you have position information for all of the nodes when you load a model, you will typically have data bound the Part#location to some property on your node data. In order to avoid an initial layout causing those saved node positions to be discarded, you can either not set the Diagram#layout to a predefined layout or you can set #isInitial to false.

Because performing layouts can be expensive in space and time, automatic layouts are performed only on "invalid" layouts, and only well after a layout has been invalidated. This state is held by the #isValidLayout property. Many standard operations, such as adding or removing nodes or links, will cause the layout that is responsible for positioning those nodes or routing those links to be invalidated. Such invalidation is performed by calling #invalidateLayout, which not only clears the #isValidLayout state but also requests that the diagram do an automatic layout soon. You can avoid such invalidations by setting #isOngoing to false.

Layouts will ignore parts that have Part#isLayoutPositioned set to false or parts that are not GraphObject#visible. Layouts will also ignore parts that are in layers that are Layer#isTemporary.

Various operations on Parts will cause the responsible Layout to be invalidated. This includes adding or removing parts, changing their visibility, and changing their size. You can disable such automatic layout invalidations by setting Part#layoutConditions to the combination of Part flags named "Layout..." that you want.

But operations on parts are not the only way in which layouts become invalidated. Setting most properties on the layouts, thereby changing their behavior, will invalidate that layout. Replacing the Diagram#layout or Group#layout will automatically invalidate the new layout. If #isViewportSized is true, when a diagram's Diagram#viewportBounds changes size, the Diagram#layout is invalidated. (This is normally only true for GridLayouts when its GridLayout#wrappingWidth is NaN. Most layouts do not care about the size of the viewport.)

You can also explicitly call Diagram#layoutDiagram, which can invalidate all layouts and then perform them all. But we recommend that you avoid doing so, to allow the normal updating process perform layouts as needed.

If an automatic layout is the first time that a layout has been performed for the model, the diagram first raises the DiagramEvent named "InitialLayoutCompleted". Whenever a Diagram finishes an automatic layout, it raises the DiagramEvent named "LayoutCompleted".

It is also possible to call #doLayout explicitly, but this is uncommon and only used with instances of Layout that are not the Diagram#layout or Group#layout. It should only be needed when you want to layout a collection of nodes and links that is not the normal graph of top-level parts of a Diagram or a subgraph of a Group.

More complicated layouts make use of a separate LayoutNetwork, consisting of LayoutVertexes and LayoutEdges, that normally holds a graph that is isomorphic to the graph consisting of Nodes and Links in the Diagram or Group. The implementation of #doLayout will call #makeNetwork and remember the result as the #network. #makeNetwork will call #createNetwork and initialize it by adding new instances of LayoutVertexes and LayoutEdges corresponding to the given collection of Nodes and Links.

When #doLayout is finished with its work it will call #updateParts, which will call #commitLayout to set new node locations and route links. It then normally discards the #network.

The LayoutVertex and LayoutEdge instances allow the layout to work with more information about each Node and Link without actually modifying those Nodes and Links until #commitLayout is called to actually set the Node locations and route the Links. The use of a LayoutNetwork also allows the Layout to work with a graph that is not isomorphic to the given collection of Nodes and Links. This is useful when needing to use dummy vertexes and/or edges to achieve certain layout behaviors, or when one wants to ignore certain vertexes or edges, without actually modifying or adding or removing the diagram's nodes or links.

An instance of this base class provides a rudimentary default layout that will position all of the parts that have no position (i.e. the Part#location is (NaN,NaN). Parts that already have a position are ignored. This primitive layout class does not make use of a LayoutNetwork because it ignores all links.

To implement your own custom layouts, you can inherit from either this class or from one of the other predefined layout classes. If you inherit from this base class, you will want to override the #doLayout method. You can call the Part#move method to re-position a part, including whole groups. Please read the Introduction page on Extensions for how to override methods and how to call a base method.

Implementers
Available extensions
Annotations
  • @JS()
  • @staticInterop

Constructors

Layout([dynamic init])
factory

Properties

hashCode int
The hash code for this object.
no setterinherited
runtimeType Type
A representation of the runtime type of the object.
no setterinherited

Methods

noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
toString() String
A string representation of this object.
inherited

Operators

operator ==(Object other) bool
The equality operator.
inherited