Class PackedLayout

GoDiagram®
v10.0.12
by Northwoods Software®

A custom layout which attempts to pack nodes as close together as possible without overlap.

Inheritance
PackedLayout
Namespace: Northwoods.Go.Layouts.Extensions
Assembly: PackedAvalonia.dll
Syntax
public class PackedLayout : Layout
Remarks

Each node is assumed to be either rectangular or circular (dictated by the HasCircularNodes property). This layout supports packing nodes into either a rectangle or an ellipse, with the shape determined by the PackShape property and the aspect ratio determined by either the AspectRatio property or the specified width and height (depending on the PackMode).

Nodes with 0 width or height cannot be packed, so they are treated by this layout as having a width or height of 0.1 instead.

Constructors

PackedLayout()

Constructs a new PackedLayout.

Declaration
public PackedLayout()

Properties

ActualBounds

This read-only property returns the actual rectangular bounds occupied by the packed nodes.

Declaration
public Rect ActualBounds { get; }
Property Value
Type Description
Rect
Remarks

This property does not take into account any kind of spacing around the packed nodes.

Note that this property will only return a valid value after a layout has been performed. Before then, its behavior is undefined.

ActualSpacing

This read-only property is the effective spacing calculated after DoLayout(IEnumerable<Part>).

Declaration
public double ActualSpacing { get; }
Property Value
Type Description
double
Remarks

If the PackMode is AspectOnly, this will simply be the Spacing property. However, in the Fit and ExpandToFit modes, this property will include the forced spacing added by the modes themselves.

Note that this property will only return a valid value after a layout has been performed. Before then, its behavior is undefined.

ArrangesToOrigin

Gets or sets whether or not to use the ArrangementOrigin property when placing nodes.

Declaration
public bool ArrangesToOrigin { get; set; }
Property Value
Type Description
bool
Remarks

The default value is true.

AspectRatio

Gets or sets the aspect ratio for the shape that nodes will be packed into.

Declaration
public double AspectRatio { get; set; }
Property Value
Type Description
double
Remarks

The provided aspect ratio should be a nonzero postive number.

Note that this only applies if the PackMode is AspectOnly. Otherwise, the Size will determine the aspect ratio of the packed shape.

The default value is 1.

Comparer

Gets or sets the comparison function used for sorting nodes.

Declaration
public Comparison<Node> Comparer { get; set; }
Property Value
Type Description
Comparison<Node>
Remarks

By default, the comparison function is set according to the values of SortMode and SortOrder.

Whether this comparison function is used is determined by the value of SortMode. Any value except None will result in the comparison function being used.

myDiagram.Layout = new VirtualizedPackedLayout {
    SortMode = SortMode.Area,
    Comparer = (na, nb) => {
      var na = na.Data;
      var nb = nb.Data;
      if (da.SomeProperty < db.SomeProperty) return -1;
      if (da.SomeProperty > db.SomeProperty) return 1;
      return 0;
    }
  };

EnclosingCircle

This read-only property returns the smallest enclosing circle around the packed nodes.

Declaration
public Rect EnclosingCircle { get; }
Property Value
Type Description
Rect
Remarks

It makes use of the HasCircularNodes property to determine whether or not to make enclosing circle calculations for rectangles or for circles. This property does not take into account any kind of spacing around the packed nodes. The enclosing circle calculation is performed the first time this property is retrieved, and then cached to prevent slow accesses in the future.

Note that this property will only return a valid value after a layout has been performed. Before then, its behavior is undefined.

This property is included as it may be useful for some data visualizations.

HasCircularNodes

Gets or sets whether or not to assume that nodes are circular. This changes the packing algorithm to one that is much more efficient for circular nodes.

Declaration
public bool HasCircularNodes { get; set; }
Property Value
Type Description
bool
Remarks

As this algorithm expects circles, it is assumed that if this property is set to true that the given nodes will all have the same height and width. All calculations are done using the width of the given nodes, so unexpected results may occur if the height differs from the width.

The default value is false.

PackMode

Gets or sets the mode that the layout will use to determine its size.

Declaration
public PackMode PackMode { get; set; }
Property Value
Type Description
PackMode
Remarks

The default value is AspectOnly. In this mode, the layout will simply grow as needed, attempting to keep the aspect ratio defined by AspectRatio.

PackShape

Gets or sets the shape that nodes will be packed into. Valid values are Elliptical, Rectangular, and Spiral.

Declaration
public PackShape PackShape { get; set; }
Property Value
Type Description
PackShape
Remarks

In Spiral mode, nodes are not packed into a particular shape, but rather packed consecutively one after another in a spiral fashion. The AspectRatio property is ignored in this mode, and the Size property (if provided) is expected to be square. If it is not square, the largest dimension given will be used. This mode currently only works with circular nodes, so setting it cause the assume that layout to assume that HasCircularNodes is true.

Note that this property sets only the shape, not the aspect ratio. The aspect ratio of this shape is determined by either AspectRatio or Size, depending on the PackMode.

When the PackMode is Fit or ExpandToFit and this property is set to true, the layout will attempt to make the diameter of the enclosing circle of the layout approximately equal to the greater dimension of the given Size property.

The default value is Elliptical.

Size

Gets or sets the size for the shape that nodes will be packed into.

Declaration
public Size Size { get; set; }
Property Value
Type Description
Size
Remarks

To fill the viewport, set a size with a width and height of NaN. Size values of 0 are considered for layout purposes to instead be 1.

If the width and height are set to NaN (to fill the viewport), but this layout has no diagram associated with it, the default value of size will be used instead.

Note that this only applies if the PackMode is Fit or ExpandToFit.

The default value is 500x500.

SortMode

Gets or sets the method by which nodes will be sorted before being packed. To change the order, see SortOrder.

Declaration
public SortMode SortMode { get; set; }
Property Value
Type Description
SortMode
Remarks

The default value is None, in which nodes will not be sorted at all.

SortOrder

Gets or sets the order that nodes will be sorted in before being packed. To change the sort method, see SortMode.

Declaration
public SortOrder SortOrder { get; set; }
Property Value
Type Description
SortOrder
Remarks

The default value is Descending

Spacing

Gets or sets the spacing between nodes.

Declaration
public double Spacing { get; set; }
Property Value
Type Description
double
Remarks

This value can be set to any real double (a negative spacing will compress nodes together, and a positive spacing will leave space between them).

Note that the spacing value is only respected in the Fit PackMode if it does not cause the layout to grow outside of the specified bounds. In the ExpandToFit PackMode, this property does not do anything.

The default value is 0.

Methods

CommitLayout()

This method is called at the end of DoLayout(IEnumerable<Part>), but before the layout transaction is committed. It can be overriden and used to customize layout behavior. By default, the method does nothing.

Declaration
public virtual void CommitLayout()

DoLayout(IEnumerable<Part>)

Performs the PackedLayout.

Declaration
public override void DoLayout(IEnumerable<Part> coll = null)
Parameters
Type Name Description
IEnumerable<Part> coll
Overrides