LayeredDigraphLayout class

This arranges nodes of directed graphs into layers (rows or columns). There are many samples that use LayeredDigraphLayout.

If you want to experiment interactively with most of the properties, try the Layered Digraph Layout sample. See samples that make use of LayeredDigraphLayout in the samples index.

The #layerSpacing property controls the distance between layers. The #columnSpacing property controls the breadth of each "column" -- this affects the distance between nodes within a layer, although the exact distance also depends on the breadth of each node. The #layeringOption property determines whether nodes without links coming in or without links going out are lined up at the edge of the graph, or whether they are positioned close to their connected nodes.

By default the layout will route the links in a manner that is consistent with the #direction. So, for example, if the #direction is 90 degrees (i.e. downward), the links are expected to go from the top towards the bottom. That means the links should come out from the bottom of the ports and should go into the top of the ports. Basically the layout will set Link#fromSpot to Spot.Bottom and Link#toSpot to Spot.Top.

If you want to the links to use the spots that are given by the ports or by the links themselves, you will need to set #setsPortSpots to false to prevent this layout from setting the spots on the links. For example, if each node only has one port that is the whole node, and if you want the links to be spread out along the sides of the nodes, then you should set #setsPortSpots to false and set the node's GraphObject#fromSpot to Spot.BottomSide and GraphObject#toSpot to Spot.TopSide.

This layout handles links that form cycles better than TreeLayout does. The normal routing behavior for "backwards" links is to route them "around" the source node and "around" the destination node, so that all links come in one side and go out the other side. However if you want "backwards" links to go more directly between nodes, set #setsPortSpots to false and the node's GraphObject#fromSpot and GraphObject#toSpot both to Spot.TopBottomSides. (Of course if the #direction is zero or 180, you'll want to use Spot.LeftRightSides.)

If the diagram is structured in a tree-like fashion, it may be better to use TreeLayout, which has more options specific to trees. TreeLayout is much faster than LayeredDigraphLayout, and can handle a limited number of links that would prevent the graph structure from being a true tree (i.e. some nodes having multiple parents).

This layout makes use of a LayoutNetwork of LayeredDigraphVertexes and LayeredDigraphEdges that normally correspond to the Nodes and Links of the Diagram.

The layout algorithm consists of four-major steps: Cycle Removal, Layer Assignment, Crossing Reduction, and Straightening and Packing. The layout cannot guarantee that it provides optimal positioning of nodes or routing of links.

The Layer Assignment step can be slow if #layeringOption is LayeredDigraphLayout.LayerOptimalLinkLength, which is the default value.

The CrossingReduction step is usually slow, but it can be avoided if you want to maintain a certain order within each layer by setting LayeredDigraphLayout#aggressiveOption to LayeredDigraphLayout.AggressiveNone.

The Straightening and Packing step is usually slow, but you can set #packOption at the expense of less nicely placed nodes. Moreover, if you do not set this property, the layout will automatically remove the LayeredDigraphLayout.PackExpand flag if the graph is large enough, in order to improve performance. It is also worth experimenting whether using #alignOption to straighten and pack provides good results for your graphs, as it is faster than #packOption.

If performance remains a problem, contact us.

Implemented types
Available extensions
Annotations
  • @JS()
  • @staticInterop

Constructors

LayeredDigraphLayout([dynamic init])
factory

Properties

aggressiveOption EnumValue

Available on LayeredDigraphLayout, provided by the LayeredDigraphLayout$Typings extension

Gets or sets which aggressive option is being used to look for link crossings. The default value is LayeredDigraphLayout.AggressiveLess. The fastest option is LayeredDigraphLayout.AggressiveNone.
getter/setter pair
alignOption num

Available on LayeredDigraphLayout, provided by the LayeredDigraphLayout$Typings extension

Gets or sets the options used by the straighten and pack function, as a potentially faster alternative to #packOption.
getter/setter pair
arrangementOrigin Point

Available on Layout, provided by the Layout$Typings extension

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.
getter/setter pair
boundsComputation Rect Function(Part, Layout, Rect)?

Available on Layout, provided by the Layout$Typings extension

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.
getter/setter pair
columnSpacing num

Available on LayeredDigraphLayout, provided by the LayeredDigraphLayout$Typings extension

Gets or sets the size of each column. This value must be positive and it defaults to 25.
getter/setter pair
cycleRemoveOption EnumValue

Available on LayeredDigraphLayout, provided by the LayeredDigraphLayout$Typings extension

Gets or set which cycle removal option is used. The value must be one of the following values: LayeredDigraphLayout.CycleDepthFirst, LayeredDigraphLayout.CycleGreedy, or LayeredDigraphLayout.CycleFromLayers. The default value is LayeredDigraphLayout.CycleDepthFirst.
getter/setter pair
diagram Diagram?

Available on Layout, provided by the Layout$Typings extension

Gets the Diagram that owns this layout, if it is the value of Diagram#layout.
getter/setter pair
direction num

Available on LayeredDigraphLayout, provided by the LayeredDigraphLayout$Typings extension

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.
getter/setter pair
group Group?

Available on Layout, provided by the Layout$Typings extension

Gets the Group that uses this layout, if it is the value of a group's Group#layout.
getter/setter pair
hashCode int
The hash code for this object.
no setterinherited
initializeOption EnumValue

Available on LayeredDigraphLayout, provided by the LayeredDigraphLayout$Typings extension

Gets or sets which indices initialization option is being used. The value must be one of the following values: LayeredDigraphLayout.InitDepthFirstOut, LayeredDigraphLayout.InitDepthFirstIn, or LayeredDigraphLayout.InitNaive. The default value is LayeredDigraphLayout.InitDepthFirstOut.
getter/setter pair
isInitial bool

Available on Layout, provided by the Layout$Typings extension

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.
getter/setter pair
isOngoing bool

Available on Layout, provided by the Layout$Typings extension

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.
getter/setter pair
isRealtime bool?

Available on Layout, provided by the Layout$Typings extension

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.
getter/setter pair
isRouting bool

Available on Layout, provided by the Layout$Typings extension

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.
getter/setter pair
isValidLayout bool

Available on Layout, provided by the Layout$Typings extension

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.
getter/setter pair
isViewportSized bool

Available on Layout, provided by the Layout$Typings extension

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 Diagram.None.
getter/setter pair
iterations num

Available on LayeredDigraphLayout, provided by the LayeredDigraphLayout$Typings extension

Gets or sets the number of iterations to be done. The value must be non-negative. The default value is 4.
getter/setter pair
layeringOption EnumValue

Available on LayeredDigraphLayout, provided by the LayeredDigraphLayout$Typings extension

Gets or sets which layering option is being used. The value must be one of the following values: LayeredDigraphLayout.LayerLongestPathSink, LayeredDigraphLayout.LayerLongestPathSource, or LayeredDigraphLayout.LayerOptimalLinkLength. The default value is LayeredDigraphLayout.LayerOptimalLinkLength, which is also the slowest option.
getter/setter pair
layerSpacing num

Available on LayeredDigraphLayout, provided by the LayeredDigraphLayout$Typings extension

Gets or sets the space between each layer. This value must be non-negative and it defaults to 25.
getter/setter pair
linkSpacing num

Available on LayeredDigraphLayout, provided by the LayeredDigraphLayout$Typings extension

(undocumented) Gets or sets the distance between link segments for unrelated links that would otherwise be overlapping. The default value is 4. The value must be non-negative.
getter/setter pair
maxColumn num

Available on LayeredDigraphLayout, provided by the LayeredDigraphLayout$Typings extension

This read-only property returns the largest column value.
getter/setter pair
maxIndex num

Available on LayeredDigraphLayout, provided by the LayeredDigraphLayout$Typings extension

This read-only property returns the largest index value.
getter/setter pair
maxIndexLayer num

Available on LayeredDigraphLayout, provided by the LayeredDigraphLayout$Typings extension

This read-only property returns the larges index layer.
getter/setter pair
maxLayer num

Available on LayeredDigraphLayout, provided by the LayeredDigraphLayout$Typings extension

This read-only property returns the largest layer value.
getter/setter pair
minIndexLayer num

Available on LayeredDigraphLayout, provided by the LayeredDigraphLayout$Typings extension

This read-only property returns the smallest index layer.
getter/setter pair
network LayoutNetwork?

Available on Layout, provided by the Layout$Typings extension

Gets or sets the LayoutNetwork used by this Layout, if any. The default value is null. Setting this property does not invalidate this layout. Not all kinds of layout make use of a LayoutNetwork. Call #createNetwork or #makeNetwork to create a network.
getter/setter pair
packOption num

Available on LayeredDigraphLayout, provided by the LayeredDigraphLayout$Typings extension

Gets or sets the options used by the straighten and pack function; this option is deprecated -- we recommend using #alignOption instead for better alignment and speed.
getter/setter pair
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
setsPortSpots bool

Available on LayeredDigraphLayout, provided by the LayeredDigraphLayout$Typings extension

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.
getter/setter pair

Methods

assignLayers() → void

Available on LayeredDigraphLayout, provided by the LayeredDigraphLayout$Typings extension

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.)
cloneProtected(Layout copy) → void

Available on Layout, provided by the Layout$Typings extension

Copies properties from this object to the given object, which is of the same class. This is called by #copy and should be overridden for each class that adds properties. There are examples of such overrides in the samples. Please read the Introduction page on Extensions for how to override methods and how to call this base method.
collectParts(Object coll) Set<Part>

Available on Layout, provided by the Layout$Typings extension

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.
commitLayers(Array<Rect> layerRects, Point offset) → void

Available on LayeredDigraphLayout, provided by the LayeredDigraphLayout$Typings extension

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.
commitLayout() → void

Available on LayeredDigraphLayout, provided by the LayeredDigraphLayout$Typings extension

Set the fromSpot and toSpot on each Link, position each Node according to the vertex position, and then position/route the Links.
commitLayout() → void

Available on Layout, provided by the Layout$Typings extension

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.

Available on LayeredDigraphLayout, provided by the LayeredDigraphLayout$Typings extension

Routes the links.
commitNodes() → void

Available on LayeredDigraphLayout, provided by the LayeredDigraphLayout$Typings extension

Commit the position of all nodes.
copy() Layout

Available on Layout, provided by the Layout$Typings extension

Creates a copy of this Layout and returns it. When a Group is copied that has a Group#layout, the Layout must also be copied. This calls #cloneProtected on a newly constructed Layout. @expose @return {Layout}
createNetwork() LayeredDigraphNetwork

Available on LayeredDigraphLayout, provided by the LayeredDigraphLayout$Typings extension

Create a new LayoutNetwork of LayeredDigraphVertexes and LayeredDigraphEdges. @expose @return {LayeredDigraphNetwork} a new LayoutNetwork.
createNetwork() LayoutNetwork

Available on Layout, provided by the Layout$Typings extension

Create a new LayoutNetwork of LayoutVertexes and LayoutEdges. This may be overridden in Layout subclasses to create instances of subclasses of LayoutNetwork. Please read the Introduction page on Extensions for how to override methods and how to call this base method. @expose @return {LayoutNetwork} a new LayoutNetwork.
doLayout(Object coll) → void

Available on LayeredDigraphLayout, provided by the LayeredDigraphLayout$Typings extension

Perform the layered digraph layout.
doLayout(Object coll) → void

Available on Layout, provided by the Layout$Typings extension

Position all of the nodes that do not have an assigned Part#location in the manner of a simple rectangular array. The default implementation ignores all Groups and Links; many subclasses of Layout ignore all instances of Parts that are not Nodes or Links.
getLayoutBounds(Part part, [Rect? rect]) Rect

Available on Layout, provided by the Layout$Typings extension

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. @param {Part} part the Part being laid out @param {Rect=} rect an optional Rect that will be modified and returned @return {Rect} a Rect in document coordinates @since 2.0
initializeIndices() → void

Available on LayeredDigraphLayout, provided by the LayeredDigraphLayout$Typings extension

(undocumented) Assigns every node in the input network an index number, such that nodes in the same layer will be labeled with consecutive indices in left to right order. All consecutive layout operations will preserve or update the indices.
initialOrigin(Point origin) Point

Available on Layout, provided by the Layout$Typings extension

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.
invalidateLayout() → void

Available on Layout, provided by the Layout$Typings extension

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.
linkMinLength(LayeredDigraphEdge edge) num

Available on LayeredDigraphLayout, provided by the LayeredDigraphLayout$Typings extension

(undocumented) The function LinkMinLength returns the minimum length of the link represented by the LayeredDigraphEdge link. The default implementation gives links a minimum length of 1. This function can be overridden to provide "fine-tuning" of the layout.
makeNetwork(Object coll) LayoutNetwork

Available on Layout, provided by the Layout$Typings extension

Create and initialize a LayoutNetwork with the given nodes and links. This should be called by #doLayout when this layout uses a #network. This method calls #createNetwork to allocate the network. This may be overridden in Layout subclasses to customize the initialization. Please read the Introduction page on Extensions for how to override methods and how to call this base method. @expose @param {Diagram|Group|Iterable.
nodeMinColumnSpace(LayeredDigraphVertex v, bool topleft) num

Available on LayeredDigraphLayout, provided by the LayeredDigraphLayout$Typings extension

(undocumented) The function nodeMinColumnSpace returns the minimum space reserved to either side of this node.
nodeMinLayerSpace(LayeredDigraphVertex v, bool topleft) num

Available on LayeredDigraphLayout, provided by the LayeredDigraphLayout$Typings extension

(undocumented) This function returns the minimum space reserved for this node from the center point for the "depth" of the layer that it is in.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
reduceCrossings() → void

Available on LayeredDigraphLayout, provided by the LayeredDigraphLayout$Typings extension

(undocumented) Reorders nodes within layers to reduce the total number of link crossings in the network.
removeCycles() → void

Available on LayeredDigraphLayout, provided by the LayeredDigraphLayout$Typings extension

(undocumented) Removes cycles from the input network by reversing some number of links. By default, this just calls #greedyCycleRemoval or #depthFirstCycleRemoval, as appropriate, give the value of #cycleRemoveOption.
straightenAndPack() → void

Available on LayeredDigraphLayout, provided by the LayeredDigraphLayout$Typings extension

(undocumented) Adjusts the columns of nodes in the network to produce a layout which reduces the number of bends and is tightly packed.
toString() String
A string representation of this object.
inherited
updateParts() → void

Available on Layout, provided by the Layout$Typings extension

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 Introduction page on Extensions for how to override methods and how to call this base method. @expose

Operators

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

Static Properties

aggressiveLess EnumValue
The faster, less aggressive, crossing reduction algorithm; a valid value for LayeredDigraphLayout#aggressiveOption.
getter/setter pair
aggressiveMore EnumValue
The slower, more aggressive, crossing reduction algorithm, a valid value for LayeredDigraphLayout#aggressiveOption.
getter/setter pair
aggressiveNone EnumValue
The fastest, but poorest, crossing reduction algorithm; a valid value for LayeredDigraphLayout#aggressiveOption.
getter/setter pair
alignAll num
Enable all options for the LayeredDigraphLayout#alignOption property; See also LayeredDigraphLayout.AlignUpperLeft, LayeredDigraphLayout.AlignUpperRight, LayeredDigraphLayout.AlignLowerLeft, and LayeredDigraphLayout.AlignLowerRight.
getter/setter pair
alignLowerLeft num
This option aligns and compacts nodes based on lower neighbors, favoring leftmost neighbors, a valid value for LayeredDigraphLayout#alignOption.
getter/setter pair
alignLowerRight num
This option aligns and compacts nodes based on lower neighbors, favoring rightmost neighbors, a valid value for LayeredDigraphLayout#alignOption.
getter/setter pair
alignNone num
This option means the the layout will pack nodes using the LayeredDigraphLayout#packOption instead of LayeredDigraphLayout#alignOption, a valid value for LayeredDigraphLayout#alignOption.
getter/setter pair
alignUpperLeft num
This option aligns and compacts nodes based on upper neighbors, favoring leftmost neighbors, a valid value for LayeredDigraphLayout#alignOption.
getter/setter pair
alignUpperRight num
This option aligns and compacts nodes based on upper neighbors, favoring rightmost neighbors, a valid value for LayeredDigraphLayout#alignOption.
getter/setter pair
cycleDepthFirst EnumValue
Remove cycles using depth first cycle removal; a valid value of LayeredDigraphLayout#cycleRemoveOption.
getter/setter pair
cycleFromLayers EnumValue
Remove cycles depending on #assignLayers determining entirely which links are backwards links; a valid value of LayeredDigraphLayout#cycleRemoveOption.
getter/setter pair
cycleGreedy EnumValue
Remove cycles using greedy cycle removal; a valid value of LayeredDigraphLayout#cycleRemoveOption.
getter/setter pair
initDepthFirstIn EnumValue
Initialize using depth first in initialization; a valid value for LayeredDigraphLayout#initializeOption.
getter/setter pair
initDepthFirstOut EnumValue
Initialize using depth first out initialization; a valid value for LayeredDigraphLayout#initializeOption.
getter/setter pair
initNaive EnumValue
Initialize using naive initialization; a valid value for LayeredDigraphLayout#initializeOption.
getter/setter pair
layerLongestPathSink EnumValue
Assign layers using longest path sink layering, so that nodes are placed in the latest layer possible possibly resulting in longer links to nodes at the last/deepest layers; a valid value for LayeredDigraphLayout#layeringOption.
getter/setter pair
layerLongestPathSource EnumValue
Assign layers using longest path source layering, so that nodes without any predecessors are placed in the first layer possibly resulting in longer links from nodes at the first/shallowest layers; a valid value for LayeredDigraphLayout#layeringOption.
getter/setter pair
layerOptimalLinkLength EnumValue
Assign layers using optimal link length layering, so that links tend to cross the fewest number of layers; A valid value for LayeredDigraphLayout#layeringOption.
getter/setter pair
packAll num
Enable all options for the LayeredDigraphLayout#packOption property; but we recommend using #alignOption instead for better alignment and speed; See also LayeredDigraphLayout.PackExpand, LayeredDigraphLayout.PackStraighten, and LayeredDigraphLayout.PackMedian.
getter/setter pair
packExpand num
This option gives more chances for the packing algorithm to improve the network, but is very expensive in time for large networks; but we recommend using #alignOption instead for better alignment and speed; a valid value for LayeredDigraphLayout#packOption.
getter/setter pair
packMedian num
This option tries to have the packing algorithm center groups of nodes based on their relationships with nodes in other layers, a valid value for LayeredDigraphLayout#packOption; but we recommend using #alignOption instead for better alignment and speed.
getter/setter pair
packNone num
Does minimal work in packing the nodes; a valid value for LayeredDigraphLayout#packOption; but we recommend using #alignOption instead for better alignment and speed.
getter/setter pair
packStraighten num
This option tries to have the packing algorithm straighten many of the links that cross layers, a valid value for LayeredDigraphLayout#packOption; but we recommend using #alignOption instead for better alignment and speed.
getter/setter pair