Specifies the layout data for the GenericLayoutGridStage.
Examples
The following example shows how to create a new instance of GenericLayoutGridStageData<TNode,TEdge,TNodeLabel,TEdgeLabel> and use it with a GenericLayoutGridStage:
const layoutData = new GenericLayoutGridStageData()
// Define layout grid from custom data
layoutData.layoutGridData.rowIndices = (node) => node.tag.rowIndex
layoutData.layoutGridData.columnIndices = (node) => node.tag.columnIndex
// Define split edges from custom data
layoutData.splitEdges = (edge) => edge.tag.isSplitEdge
// Combine the layout data of the stage and the core layout
const compositeLayoutData = coreLayoutData.combineWith(layoutData)
graph.applyLayout(
new GenericLayoutGridStage(coreLayout),
compositeLayoutData,
)
In many cases, the complete initialization of GenericLayoutGridStageData<TNode,TEdge,TNodeLabel,TEdgeLabel> can also be done in a single object initializer:
const genericLayoutGridStage = new GenericLayoutGridStage(coreLayout)
const layoutData = new GenericLayoutGridStageData()
// Define layout grid from custom data
layoutData.layoutGridData.rowIndices = (node) => node.tag.rowIndex
layoutData.layoutGridData.columnIndices = (node) => node.tag.columnIndex
// Define split edges from custom data
layoutData.splitEdges = (edge: IEdge): boolean => edge.tag.isSplitEdge
graph.applyLayout(
genericLayoutGridStage,
coreLayoutData.combineWith(layoutData),
)
Type Parameters
- TNode
- TEdge
- TNodeLabel
- TEdgeLabel
Type Details
- yFiles module
- algorithms
Constructors
Parameters
A map of options to pass to the method.
- layoutGridData - LayoutGridData<TNode,TEdge,TNodeLabel,TEdgeLabel>
- The layoutGridData that allows to configure the LayoutGrid for the layout stage. This option either sets the value directly or recursively sets properties to the instance of the layoutGridData property on the created object.
- splitEdges - ItemCollection<TEdge>
- The collection of edges that should not be considered when calculating the sub-components. This option either sets the value directly or recursively sets properties to the instance of the splitEdges property on the created object.
Properties
Gets or sets the layoutGridData that allows to configure the LayoutGrid for the layout stage.
Examples
The following sample shows how to assign nodes to layout grid cells simply via cell indices:
// Create four nodes and place them in grid cells in the following way
// +---+---+---+
// | 1 | 2 | 3 |
// +---+---+---+
// | 4 |
// +---+
const gridData = layoutData.layoutGridData
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)
graph.applyLayout(
new GenericLayoutGridStage(coreLayout),
coreLayoutData.combineWith(layoutData),
)
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:
// Create three nodes and place them in grid cells in the following way
// +---+---+
// | 1 | 2 |
// +---+---+
// | 3 |
// +---+---+
const gridData = layoutData.layoutGridData
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
const gridCells = new Mapper<INode, LayoutGridCellDescriptor>()
gridCells.set(node1, grid.createCellDescriptor(0, 0))
gridCells.set(node2, grid.createCellDescriptor(0, 1))
gridCells.set(node3, grid.createRowSpanDescriptor(1))
gridData.layoutGridCellDescriptors = gridCells
graph.applyLayout(
new GenericLayoutGridStage(coreLayout),
coreLayoutData.combineWith(layoutData),
)
Gets or sets the collection of edges that should not be considered when calculating the sub-components.
Remarks
Examples
If only a few edges should be removed during the calculation of the sub-components, the easiest way is often to add them one by one via the items collection:
layoutData.splitEdges.items.add(edge1)
layoutData.splitEdges.items.add(edge2)
If you already have a collection or IEnumerable<T> for those edges, the source property is usually easier:
// Consider selected edges
layoutData.splitEdges = graphComponent.selection.edges
If it can be inferred directly from the edge itself whether it should be routed that way, a delegate is often most convenient:
layoutData.splitEdges = (edge) => edge.tag.isSplitEdge
Methods
combineWith
(data: LayoutData<TNode,TEdge,TNodeLabel,TEdgeLabel>…) : LayoutData<TNode,TEdge,TNodeLabel,TEdgeLabel>Combines this instance with the given layout data.
Remarks
Parameters
A map of options to pass to the method.
- data - LayoutData<TNode,TEdge,TNodeLabel,TEdgeLabel>
- The LayoutData<TNode,TEdge,TNodeLabel,TEdgeLabel> to combine this instance with.
Returns
- ↪LayoutData<TNode,TEdge,TNodeLabel,TEdgeLabel>
- The combined layout data.