Class GridLayout

Extends Layout. This simple layout places all of the Parts in a grid-like arrangement, ordered, spaced apart, and wrapping as needed. It ignores any Links connecting the Nodes being laid out. There are many samples that use GridLayout. Every Palette uses a GridLayout by default.

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

By default this layout will sort all of the Parts alphabetically (comparing Part.text values, respecting case) and position them left-to-right, separated by spacing.width, until they do not fit in the current row. At that time it starts a new row, separated from the previous row by spacing.height. There is a uniform cell size equal to the maximum Part width (plus spacing width) and the maximum part height (plus spacing height). At least one part is placed in each row, even if the part by itself is wider than the wrapping width.

You can specify values for the cellSize width and height. If a part is wider than the cell size, it spans more than one cell in the row. You can also specify a value for the wrappingWidth, which will be used instead of the diagram's viewport width, to control when each row is considered "full". The value of Layout.isViewportSized will be true when the value of wrappingWidth is NaN. This causes the layout to be performed again automatically as the viewport changes size.

You can also set wrappingColumn to limit the number of items in each row. Both the wrappingWidth and the wrappingColumn are respected when deciding when to wrap to the next row.

This layout is sufficiently simple that it does not use a LayoutNetwork.

Constructor Summary Details

Name Description
GridLayout()

Properties Summary Details

Name, Value Type Description
alignment
{EnumValue}

Gets or sets whether the Part.location or the position should be used to arrange each part.More...

The default value is GridLayout.Location -- the Part.locations will be aligned in a grid.
arrangement
{EnumValue}

Gets or sets how to arrange the parts.More... Must be GridLayout.LeftToRight or GridLayout.RightToLeft.

The default value is GridLayout.LeftToRight.
cellSize
{Size}

Gets or sets the minimum part size by which each part is positioned in the grid.More...

The default value is NaN x NaN. The units are in model coordinates.

When the cell size is smaller than a part, the part will occupy more than one cell. This allows parts to be positioned closer to each other, but then variations in part sizes may cause them not to be aligned in perfect rows or columns.

comparer
{function(Part, Part):number}

Gets or sets the comparison function used to sort the parts.More...

The default value is a case-insensitive alphabetic comparison using the Part.text property of each part.
isViewportSized

sorting
{EnumValue}

Gets or sets what order to place the parts.More... Must be GridLayout.Forward, GridLayout.Reverse, GridLayout.Ascending, or GridLayout.Descending.

The default value is GridLayout.Ascending.

spacing
{Size}

Gets or sets the minimum horizontal and vertical space between parts.More...

The default value is 10 x 10. The units are in model coordinates.
wrappingColumn
{number}

Gets or sets the maximum number of columns.More...

The default is NaN, meaning not to limit the number of columns. 1 is a common value to produce a single column of parts.

wrappingWidth
{number}

Gets or sets the wrapping width.More...

The default is NaN, meaning to use the width of the diagram's panel's viewport. Must be a value greater than 0.

Properties borrowed from class Layout:
arrangementOrigin, diagram, group, isInitial, isOngoing, isRealtime, isRouting, isValidLayout, network

Method Summary Details

Name, Return Type Description
doLayout(coll)

Assign the positions of the parts, ignoring any links.More...

Parameters:
{Diagram|Group|Iterable.} coll
A Diagram or a Group or a collection of Parts.
Methods borrowed from class Layout:
cloneProtected, collectParts, commitLayout, copy, createNetwork, invalidateLayout, makeNetwork, updateParts

Constants Summary Details

Name Description
Ascending {EnumValue}

Lay out each child according to the sort order given by GridLayout.comparer; This value is used for GridLayout.sorting.

Descending {EnumValue}

Lay out each child in reverse sort order given by GridLayout.comparer; This value is used for GridLayout.sorting.

Forward {EnumValue}

Lay out each child in the order in which they were found; This value is used for GridLayout.sorting.

LeftToRight {EnumValue}

Fill each row from left to right; This value is used for GridLayout.arrangement.

Location {EnumValue}

Position the part's Part.location at a grid point; This value is used for GridLayout.alignment.

Position {EnumValue}

Position the top-left corner of each part at a grid point; This value is used for GridLayout.alignment.

Reverse {EnumValue}

Lay out each child in reverse order from which they were found; This value is used for GridLayout.sorting.

RightToLeft {EnumValue}

Fill each row from right to left; This value is used for GridLayout.arrangement.