Specifies custom data for the AlignmentStage.
Examples
The following example shows how to create a new instance of AlignmentStageData<TNode,TEdge,TNodeLabel,TEdgeLabel> and use it with an AlignmentStage:
const data = new AlignmentStageData()
// define a node halo for each non-group node, reserving space at the bottom side
data.nodeMargins = (node) =>
graph.isGroupNode(node) ? Insets.EMPTY : new Insets(0, 0, 40, 0)
graphComponent.graph.applyLayout(new AlignmentStage(coreLayout), data)
In many cases the complete initialization of AlignmentStageData<TNode,TEdge,TNodeLabel,TEdgeLabel> can also be done in a single object initializer:
const grid = new LayoutGrid(3, 3)
const data = new AlignmentStageData({
// specify the layout grid which is to be obeyed by the stage
layoutGridData: new LayoutGridData({
layoutGridCellDescriptors:
// node1 is assigned to the first row (index 0)
// all other nodes are assigned to the second row (index 1)
(node) => grid.createCellDescriptor(node == node1 ? 0 : 1, 0),
}),
})
graphComponent.graph.applyLayout(new AlignmentStage(coreLayout), data)
Type Parameters
- TNode
- TEdge
- TNodeLabel
- TEdgeLabel
Type Details
- yFiles module
- algorithms
Constructors
Parameters
A map of options to pass to the method.
- snapOffsets - ItemMapping<TNode,IPoint>
- The mapping from nodes to the points relative to the center that are aligned. This option either sets the value directly or recursively sets properties to the instance of the snapOffsets property on the created object.
- nodeMargins - ItemMapping<TNode,Insets>
- The mapping from nodes to their margins. This option either sets the value directly or recursively sets properties to the instance of the nodeMargins property on the created object.
- layoutGridData - LayoutGridData<TNode,TEdge,TNodeLabel,TEdgeLabel>
- The LayoutGrid layout data which allows to define a grid that is respected by the AlignmentStage so that nodes that are not in the same column/row may not be aligned. This option either sets the value directly or recursively sets properties to the instance of the layoutGridData property on the created object.
Properties
Gets or sets the LayoutGrid layout data which allows to define a grid that is respected by the AlignmentStage so that nodes that are not in the same column/row may not be aligned.
Gets or sets the mapping from nodes to their margins.
Remarks
Examples
The easiest option is to reserve the same space around all nodes, by setting a constant value:
layoutData.nodeMargins = new Insets(20)
Handling only certain nodes differently can be done easily by using the mapper property:
// node1 only reserves space above and below
layoutData.nodeMargins.mapper.set(node1, new Insets(20, 10, 0, 0))
// node2 has space all around
layoutData.nodeMargins.mapper.set(node2, new Insets(25))
// all other nodes don't get extra space
In cases where the nodeMargins for each node can be determined by looking at the node itself it's often easier to just set a mapperFunction instead of preparing a mapper:
// Retrieve the space around the node from its tag property
layoutData.nodeMargins = (node: INode): Insets =>
new Insets(parseFloat(node.tag))
See Also
Gets or sets the mapping from nodes to the points relative to the center that are aligned.
Remarks
Examples
The easiest way to define the same snap offset point for all items is by using a constant:
// Specify that the snap point for all nodes should be the top-left corner
layoutData.snapOffsets = new Point(-Number.MAX_VALUE, -Number.MAX_VALUE)
A convenient way to define different points for specific nodes is to use a delegate like so:
layoutData.snapOffsets = (node) => {
if (node == node1) {
// Align this node using its bottom-right corner
return new Point(Number.MAX_VALUE, Number.MAX_VALUE)
}
if (node == node2) {
// Align this node using the point in the center of the left border
return new Point(-Number.MAX_VALUE, 0)
}
// Align all other nodes using the center coordinates
return new Point(0, 0)
}
See Also
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.