documentationfor yFiles for HTML 3.0.0.3

LayoutGridData<TNode,TEdge,TNodeLabel,TEdgeLabel>

Specifies one or multiple LayoutGrids for a layout.

Inheritance Hierarchy

Remarks

There are different ways to define the layout grid(s):

The simpler one is to define rowIndices and/or columnIndices for the nodes. This creates a basic LayoutGrid according to these indices. To further customize the layout grid it is possible to specify one using property grid. This enables to specify e.g. minimumWidths for columns. The layout grid may be expanded according to the indices. Specifying a layout grid using property grid but assigning no indices to nodes has no effect. If property layoutGridCellDescriptors is set, these three properties are being ignored.

The second way is to define the mapping layoutGridCellDescriptors which maps nodes to a LayoutGridCellDescriptor. If you want to work with multiple grids, this way must be chosen. Note that not all layout algorithms support multiple layout grids.

A third way is to use a LayoutExecutor with automatic table configuration.

Note that cell spanning is only supported using the layoutGridCellDescriptors.

Examples

The following sample shows how to assign nodes to layout grid cells simply via cell indices:

Assigning nodes to layout grid cells via indices
// Create four nodes and place them in grid cells in the following way
// +---+---+---+
// | 1 | 2 | 3 |
// +---+---+---+
//     | 4 |
//     +---+

const gridData = new LayoutGridData<INode, IEdge, ILabel, ILabel>()

const node1 = graph.createNode()
const node2 = graph.createNode()
const node3 = graph.createNode()
const node4 = graph.createNode()

// Assign the nodes to their rows and columns.
// Note that you don't have to create or use LayoutGrid directly in this case.
// Setting the indices is enough.
gridData.rowIndices.mapper.set(node1, 0)
gridData.rowIndices.mapper.set(node2, 0)
gridData.rowIndices.mapper.set(node3, 0)
gridData.rowIndices.mapper.set(node4, 1)
gridData.columnIndices.mapper.set(node1, 0)
gridData.columnIndices.mapper.set(node2, 1)
gridData.columnIndices.mapper.set(node3, 2)
gridData.columnIndices.mapper.set(node4, 1)

// Run a layout with the LayoutGridData. Note that the layout-specific
// LayoutData classes that support layout grids (e.g. HierarchicalLayoutData)
// also contain a LayoutGridData that can be used directly.
graph.applyLayout(new HierarchicalLayout(), gridData)

If used this way there is no need to create a LayoutGrid instance or work with it directly. For more flexibility, e.g. to use cells that span multiple columns or rows, the LayoutGrid can be used as well:

Assigning nodes to layout grid cells via factory methods on the grid
// Create three nodes and place them in grid cells in the following way
// +---+---+
// | 1 | 2 |
// +---+---+
// |   3   |
// +-------+

const gridData = new LayoutGridData<INode, IEdge, ILabel, ILabel>()

const node1 = graph.createNode(new Rect(0, 0, 50, 50))
const node2 = graph.createNode(new Rect(0, 0, 50, 50))
const node3 = graph.createNode(new Rect(0, 0, 125, 50))
// Create a new LayoutGrid with two rows and two columns
const grid = new LayoutGrid(2, 2)
// Assign the nodes to their cells
gridData.layoutGridCellDescriptors.mapper.set(
  node1,
  grid.createCellDescriptor(0, 0),
)
gridData.layoutGridCellDescriptors.mapper.set(
  node2,
  grid.createCellDescriptor(0, 1),
)
gridData.layoutGridCellDescriptors.mapper.set(
  node3,
  grid.createRowSpanDescriptor(1),
)

// Run a layout with the LayoutGridData. Note that the layout-specific
// LayoutData classes that support layout grids (e.g. HierarchicalLayoutData)
// also contain a LayoutGridData that can be used directly.
graph.applyLayout(new HierarchicalLayout(), gridData)

Type Parameters

TNode
TEdge
TNodeLabel
TEdgeLabel

Type Details

yFiles module
algorithms

Constructors

Properties

Methods