Constructs a GridLayout with no Layout.network and with no owning Layout.diagram.
Optionalinit: Partial<GridLayout>Optional initialization properties.
Gets or sets whether the Part.location or the position should be used to arrange each part.
The default value is GridAlignment.Location -- the Part.locations will be aligned in a grid.
Gets or sets how to arrange the parts. Must be a GridArrangement value.
The default value is GridArrangement.LeftToRight.
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.
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.
The non-null value must be a function that takes 3 arguments. The first argument will be the Part whose bounds the Layout should use. The second argument will be this Layout. The third argument will be a Rect that must be modified and returned The return value must be in document coordinates. You may find it convenient to call GraphObject.getDocumentBounds to get the bounds in document coordinates of an object within the node.
since2.0
Gets or sets the minimum part size by which each part is positioned in the grid.
The default value is NaN x NaN. The units are in document 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.
Gets or sets the comparison function used to sort the parts.
The default value is a case-insensitive alphabetic comparison using the Part.text property of each part.
new go.GridLayout({
sorting: go.GridSorting.Ascending,
comparer: (pa, pb) => {
const da = pa.data;
const db = pb.data;
if (da.someProperty < db.someProperty) return -1;
if (da.someProperty > db.someProperty) return 1;
return 0;
}
})
ReadonlydiagramGets the Diagram that owns this layout, if it is the value of Diagram.layout.
If this property and group are non-null, the Group should be in this Diagram.
see
ReadonlygroupGets the Group that uses this layout, if it is the value of a group's Group.layout.
If this property is set to a Group, the diagram is automatically set to be the Group's Diagram.
see
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.
If you set both isInitial and isOngoing to false, there will be no automatic layout invalidation, because invalidateLayout will not set isValidLayout to false. To get your nodes to appear, you will need to explicitly set or data-bind their Part.location or GraphObject.position to real Point values, because automatic layout will not assign any positions.
Another way of controlling when layouts are invalidated is by setting Part.isLayoutPositioned or Part.layoutConditions.
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.
If you set both isInitial and isOngoing to false, there will be no automatic layout invalidation, because invalidateLayout will not set isValidLayout to false. To get your nodes to appear, you will need to explicitly set or data-bind their Part.location or GraphObject.position to real Point values, because automatic layout will not assign any positions.
Another way of controlling when layouts are invalidated is by setting Part.isLayoutPositioned or Part.layoutConditions.
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.
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.
Some layouts ignore links, in which case this property is ignored.
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.
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 AutoScale.None.
The default value is false. Setting this property to true will invalidate this layout.
It is possible that a viewport-sized layout will trigger the Diagram to require scrollbars, which modifies the Diagram.viewportBounds, which will in turn trigger another layout. This is uncommon, but possible with GridLayout if the results require a vertical scrollbar, and that vertical scrollbar shrinks the viewport width enough that a grid column can no longer fit. When designing custom layouts, one should be careful that this behavior does not result in an infinite loop.
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.
Gets or sets what order to place the parts. Must be a GridSorting value.
The default value is GridSorting.Ascending.
Gets or sets the minimum horizontal and vertical space between parts.
The default value is 10 x 10. The units are in document coordinates.
Gets or sets the maximum number of items that the layout will arrange in a single row.
The default is NaN, meaning not to limit the number of columns. 1 is a common value to produce a single column of parts. The value must be positive or NaN.
When Diagram.initialAutoScale or Diagram.autoScale are not None, it is common to set wrappingColumn and wrappingWidth to large values -- whatever seems reasonable given the number and size of the parts that will be laid out and the size of the viewport.
Gets or sets the width beyond which the layout will start a new row.
The default is NaN, meaning to use the width of the diagram's panel's viewport. Infinity is a common value to produce a single row of parts, unless limited by wrappingColumn. The value must be positive or NaN.
If the new value is NaN, Layout.isViewportSized will be set to true. When Diagram.initialAutoScale or Diagram.autoScale are not None, it is common to set wrappingColumn and wrappingWidth to large values -- whatever seems reasonable given the number and size of the parts that will be laid out and the size of the viewport.
ProtectedcollectA 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.
Typical usage:
public doLayout(coll) {
// COLL might be a Diagram or a Group or some Iterable<Part>
const it = this.collectParts(coll).iterator;
while (it.next()) {
const node = it.value;
if (node instanceof go.Node) {
. . . position the node . . .
}
}
}
Protected VirtualcommitWhen 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.
You should not call this method -- it is a "protected virtual" method. This may be overridden by subclasses of Layout. By default this method is implemented as follows:
protected commitLayout() {
if (this.network === null) return;
const vit = this.network.vertexes.iterator;
while (vit.next()) {
const vert = vit.value;
vert.commit();
}
if (this.isRouting) {
const eit = this.network.edges.iterator;
while (eit.next()) {
const edge = eit.value;
edge.commit();
}
}
}
Please read the Learn page on Extensions for how to override methods and how to call this base method.
VirtualcopyCreates 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.
VirtualcreateCreate a new LayoutNetwork of LayoutVertexes and LayoutEdges. This may be overridden in Layout subclasses to create instances of subclasses of LayoutNetwork. Please read the Learn page on Extensions for how to override methods and how to call this base method.
a new LayoutNetwork.
OverridedoVirtualgetThis 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.
a Rect in document coordinates
since2.0
Protected VirtualinitialCompute 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.
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.
If you set both isInitial and isOngoing to false, there will be no automatic layout invalidation, because this method will not set isValidLayout to false. However you can still set isValidLayout explicitly.
This is typically called when a layout property value has changed, or when a Part is added or removed or changes visibility, if Part.layoutConditions includes the pertinent flags.
VirtualmakeCreate 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 Learn page on Extensions for how to override methods and how to call this base method.
normally the value of a call to createNetwork initialized by vertexes and edges corresponding to the coll argument.
VirtualupdateWhen 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 Learn page on Extensions for how to override methods and how to call this base method.
Static ReadonlyAscendingdeprecated
Static ReadonlyDescendingdeprecated
Static ReadonlyForwarddeprecatedSee GridSorting.Forwards.
Static ReadonlyLeftdeprecated
Static ReadonlyLocationdeprecated
Static ReadonlyPositiondeprecated
Static ReadonlyReversedeprecatedSee GridSorting.Reverse.
Static ReadonlyRightdeprecated
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
widthandheight. If a part is wider than the cell size, it spans more than one cell in the row.When the value of wrappingWidth is set to
NaN, as it is by default, the value of Layout.isViewportSized will be set to true. This causes the layout to be performed again automatically as the viewport changes size. You can also specify a real number value for the wrappingWidth, which will be used instead of the diagram's viewport width, to control when each row is considered "full".You can also set wrappingColumn to limit the number of items in each row. By default wrappingColumn is
NaN, meaning that there is no limit on the number of items in any one 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.