Class LayeredDigraphLayout
This arranges nodes of directed graphs into layers (rows or columns).
Inheritance
Namespace: Northwoods.Go.Layouts
Assembly: Northwoods.GoDiagram.Avalonia.LayeredDigraphLayout.dll
Syntax
public class LayeredDigraphLayout : NetworkLayout<LayeredDigraphNetwork, LayeredDigraphVertex, LayeredDigraphEdge, LayeredDigraphLayout>
Remarks
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 FromSpot to Spot.Bottom
and 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 FromSpot to
Spot.BottomSide
and ToSpot to Spot.TopSide
.
This layout handles links that form cycles better than 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
This layout makes use of a Network<V, E, Y> 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.
Constructors
LayeredDigraphLayout()
Constructs a LayeredDigraphLayout with no Network and with no owning Diagram.
Declaration
public LayeredDigraphLayout()
Properties
AggressiveOption
Gets or sets which aggressive option is being used to look for link crossings.
Declaration
public LayeredDigraphAggressive AggressiveOption { get; set; }
Property Value
Type | Description |
---|---|
LayeredDigraphAggressive |
Remarks
The default value is Less.
ColumnSpacing
Gets or sets the size of each column.
Declaration
public double ColumnSpacing { get; set; }
Property Value
Type | Description |
---|---|
double |
Remarks
This value must be positive and it defaults to 25.
CycleRemoveOption
Gets or set which cycle removal option is used.
Declaration
public LayeredDigraphCycleRemove CycleRemoveOption { get; set; }
Property Value
Type | Description |
---|---|
LayeredDigraphCycleRemove |
Remarks
The default value is DepthFirst.
Direction
Gets or sets the direction the graph grows towards.
Declaration
public double Direction { get; set; }
Property Value
Type | Description |
---|---|
double |
Remarks
0 is towards the right, 90 is downwards, 180 is towards the left, and 270 is upwards. The default value is 0.
InitializeOption
Gets or sets which indices initialization option is being used.
Declaration
public LayeredDigraphInit InitializeOption { get; set; }
Property Value
Type | Description |
---|---|
LayeredDigraphInit |
Remarks
The default value is DepthFirstOut.
Iterations
Gets or sets the number of iterations to be done.
Declaration
public int Iterations { get; set; }
Property Value
Type | Description |
---|---|
int |
Remarks
The value must be non-negative. The default value is 4.
LayeringOption
Gets or sets which layering option is being used.
Declaration
public LayeredDigraphLayering LayeringOption { get; set; }
Property Value
Type | Description |
---|---|
LayeredDigraphLayering |
Remarks
The default value is OptimalLinkLength.
LayerSpacing
Gets or sets the space between each layer.
Declaration
public double LayerSpacing { get; set; }
Property Value
Type | Description |
---|---|
double |
Remarks
This value must be positive and it defaults to 25.
MaxColumn
This read-only property returns the largest column value.
Declaration
public int MaxColumn { get; }
Property Value
Type | Description |
---|---|
int |
MaxIndex
This read-only property returns the largest index value.
Declaration
public int MaxIndex { get; }
Property Value
Type | Description |
---|---|
int |
MaxIndexLayer
This read-only property returns the larges index layer.
Declaration
public int MaxIndexLayer { get; }
Property Value
Type | Description |
---|---|
int |
MaxLayer
This read-only property returns the largest layer value.
Declaration
public int MaxLayer { get; }
Property Value
Type | Description |
---|---|
int |
MinIndexLayer
This read-only property returns the smallest index layer.
Declaration
public int MinIndexLayer { get; }
Property Value
Type | Description |
---|---|
int |
PackOption
Gets or sets the options used by the straighten and pack function.
Declaration
public LayeredDigraphPack PackOption { get; set; }
Property Value
Type | Description |
---|---|
LayeredDigraphPack |
Remarks
The default value is All.
SetsPortSpots
Gets or sets whether the FromSpot and ToSpot of each link should be set to values appropriate for the given value of Direction.
Declaration
public bool SetsPortSpots { get; set; }
Property Value
Type | Description |
---|---|
bool |
Remarks
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.
Methods
AssignLayers()
Assigns every vertex in the input network to a layer.
Declaration
protected virtual void AssignLayers()
Remarks
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 Introduction 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.
CommitLayers(List<Rect>, Point)
This overridable method is called by CommitLayout() to support custom arrangement of bands or labels across each layout layer.
Declaration
protected virtual void CommitLayers(List<Rect> layerRects, Point offset)
Parameters
Type | Name | Description |
---|---|---|
List<Rect> | layerRects | a List of Rects with the bounds of each of the "layers" |
Point | offset | the position of the top-left corner of the banded area relative to the coordinates given by the layerRects |
Remarks
By default this method does nothing.
The coordinates used in the resulting Rects may need to be offset by the ArrangementOrigin.
CommitLayout()
Set the FromSpot and ToSpot on each Link, position each Node according to the vertex position, and then position/route the Links.
Declaration
protected override void CommitLayout()
Overrides
Remarks
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 Introduction page on Extensions for how to override methods and how to call this base method.
CommitLinks()
Routes the links.
Declaration
protected virtual void CommitLinks()
Remarks
This is called by CommitLayout(). This is only called if IsRouting is true. Please read the Introduction page on Extensions for how to override methods and how to call this base method.
See Also
CommitNodes()
Commit the position of all nodes.
Declaration
protected virtual void CommitNodes()
Remarks
This is called by CommitLayout(). Please read the Introduction page on Extensions for how to override methods and how to call this base method.
See Also
DoLayout(IEnumerable<Part>)
Perform the layered digraph layout.
Declaration
public override void DoLayout(IEnumerable<Part> coll = null)
Parameters
Type | Name | Description |
---|---|---|
IEnumerable<Part> | coll |
Overrides
Remarks
This removes any reflexive edges in the network, since they should be ignored.
In order to influence a vertex's layer, you can override AssignLayers().
Finally this calls UpdateParts() to commit the Node positions from the vertex positions. UpdateParts() calls CommitLayout() within a transaction.