AlignmentStage places the nodes of the given layout on automatically determined horizontal and/or vertical lines.
Remarks
The AlignmentStage arranges the nodes on vertical and horizontal lines that are derived from the given layout. It can be used to automatically snap nodes to the same x- or y-coordinate to obtain a grid-like structure. When rearranging the layout, the stage moves the nodes as little as possible.
Concept
The nodes are aligned on heuristically determined lines in two phases.
In the first phase, the nodes are assigned to lines such that the following criteria are taken into account:
- The nodes maintain their order along the x- and y-axis, if possible.
- Nodes that are assigned to the same grid line have similar coordinates in the initial layout.
- The number of lines is minimized.
In the second phase, the positions of these lines and consequently their assigned nodes are determined. The positions are chosen such that the overall movement of the nodes is minimized.
Features
Alignment policy
AlignmentStage supports the alignment of the nodes in horizontal direction, vertical direction or in both directions. The mode is determined by the alignmentPolicy. If a single direction, i.e., SNAP_X or SNAP_Y is selected, the nodes do not move in the orthogonal direction.Snap Distance
The snapDistance can be used to balance the trade-off between maintaining the initial graph layout and the grid-like structure produced by the stage. More specifically, the snap distance describes the maximum distance between two nodes that may still be snapped to the same grid line. Therefore, large snap distances produce a more emphasized grid structure, while giving up more of the initial layout compared to smaller snap distances.Minimum Node Distance
The minimumNodeDistance determines the compactness of the result. The distance is enforced in the same direction as the nodes are snapped to (horizontal, vertical, both). It prevents any two nodes on different grid lines from being placed closer to one another.Stripe Separation
If stripe separation is enabled, the nodes of two consecutive grid lines are strictly separated by a line L that has the same orientation as the two grid lines, i.e., the nodes of the two grid lines lie on opposite sides of L. For example, when aligning nodes horizontally with stripe separation, the nodes of two consecutive grid lines are separated by a horizontal line H such that the nodes of one grid line lie above H and the others lie below H. Further, if stripe separation is enabled, the minimumNodeDistance is enforced such that any two nodes of different grid lines are separated by at least the given distance.Node Margins and Node Labels
The automatic AlignmentStage supports node margins as well as considering node labels when calculating the distances between nodes.Node Overlaps
In case that nodes mutually overlap, applying the stage will resolve these overlaps resulting in a layout without overlaps. However, no guarantees are given how the nodes are rearranged such that it may lead to undesired artifacts. Generally, it is recommended that the initial layout should be free of node overlaps and adhere to the specified minimumNodeDistance as much as possible. To that end, an overlap removal stage can be applied to the layout before this stage.Layout Grid
The automatic AlignmentStage supports the use of a layout grid. It is required that the nodes do not span multiple cells. In particular, it is required that the child nodes of a group node are assigned to the same cell as the group node. In case that the AlignmentStage is applied only to one dimension, the layout grid is only changed in that dimension, while the other dimension remains unchanged.Default Values of Properties
alignmentPolicy | SNAP_XY
| Nodes are aligned horizontally and vertically. |
gridSpacing | 0.0 | Nodes are aligned on an irregular grid. |
minimumNodeDistance | 15.0 | |
nodeLabelPlacement | CONSIDER
| Node labels are considered for resolving overlaps when determining the alignment of the nodes. |
separateStripes | false | Rows and Columns are not strictly separated and may overlap. |
snapDistance | 50.0 |
Type Details
- yFiles module
- algorithms
Constructors
Creates a new AlignmentStage with the given algorithm as coreLayout or null
if no core layout should be applied prior to the alignment stage.
Parameters
A map of options to pass to the method.
- coreLayout - ILayoutAlgorithm
- the core layout algorithm
- gridSpacing - number
- The distance between two adjacent grid lines to which the nodes can be snapped, or zero if nodes are aligned on an irregular grid. This option sets the gridSpacing property on the created object.
- separateStripes - boolean
- Whether nodes are placed in strictly separated rows and strictly separated columns. This option sets the separateStripes property on the created object.
- nodeLabelPlacement - BasicNodeLabelPlacement
- Whether node labels are taken into account for snapping nodes on common lines. This option sets the nodeLabelPlacement property on the created object.
- minimumNodeDistance - number
- The minimum horizontal and vertical distance between two nodes. This option sets the minimumNodeDistance property on the created object.
- alignmentPolicy - AlignmentStageAlignmentPolicy
- The axis, parallel to which the nodes are aligned by the algorithm. This option sets the alignmentPolicy property on the created object.
- snapDistance - number
- The maximum distance between two nodes that can be aligned on the same line. This option sets the snapDistance property on the created object.
- enabled - boolean
Properties
Gets or sets the axis, parallel to which the nodes are aligned by the algorithm.
Remarks
Default Value
Property Value
Throws
- Exception({ name: 'ArgumentError' })
- if an unknown alignment policy is given
Sample Graphs
Gets or sets the core ILayoutAlgorithm that is wrapped by this stage.
Gets or sets a value that determines whether this stage should do anything but execute the coreLayout.
Remarks
By default, when constructed, stages should be enabled. Users may disable a stage's functionality by setting this property to false
.
Stages that can guarantee that the graph will not change can choose to not even execute the coreLayout when disabled.
Implements
Gets or sets the distance between two adjacent grid lines to which the nodes can be snapped, or zero if nodes are aligned on an irregular grid.
Remarks
Default Value
0.0
.Nodes are aligned on an irregular grid.
Property Value
Throws
- Exception({ name: 'ArgumentError' })
- if a negative value is specified
0.0
, the nodes are aligned on an irregular grid.Gets or sets the minimum horizontal and vertical distance between two nodes.
Remarks
The horizontal distance is enforced if using the SNAP_Y or the SNAP_XY alignment policy. The vertical distance is enforced if using the SNAP_Y or the SNAP_XY alignment policy.
If alignment separation is enabled, the vertical and horizontal distances are enforced such that any two nodes of different grid lines are separated by at least the given distance in horizontal and vertical direction, respectively.
Default Value
15.0
.Property Value
Throws
- Exception({ name: 'ArgumentError' })
- if the given value is negative
Sample Graphs
Gets or sets whether node labels are taken into account for snapping nodes on common lines.
Remarks
Default Value
CONSIDER.Node labels are considered for resolving overlaps when determining the alignment of the nodes.
Property Value
Gets or sets whether nodes are placed in strictly separated rows and strictly separated columns.
Default Value
false
.Rows and Columns are not strictly separated and may overlap.
Property Value
true
if nodes are placed in strictly separated rows and columns, false
if overlaps between rows as well as overlaps between columns are allowed.See Also
Sample Graphs
Gets or sets the maximum distance between two nodes that can be aligned on the same line.
Remarks
Default Value
50.0
.Property Value
Throws
- Exception({ name: 'ArgumentError' })
- if the given value is negative
Methods
Implementation of the ILayoutAlgorithm interface and main entry point for the layout calculation.
Remarks
Parameters
A map of options to pass to the method.
- graph - LayoutGraph
- The graph to apply the layout to.
Implements
Aligns the nodes of the graph into a grid-like structure.
Parameters
A map of options to pass to the method.
- graph - LayoutGraph
- the input graph
Implements
createLayoutData
(graph: LayoutGraph) : AlignmentStageData<LayoutNode,LayoutEdge,LayoutNodeLabel,LayoutEdgeLabel>Returns an instance of LayoutData<TNode,TEdge,TNodeLabel,TEdgeLabel> that can be used to perform item-specific configurations for the AlignmentStage.
Remarks
Parameters
A map of options to pass to the method.
- graph - LayoutGraph
- the graph that determines the generic type arguments of the created layout data
Returns
- ↪AlignmentStageData<LayoutNode,LayoutEdge,LayoutNodeLabel,LayoutEdgeLabel>
- an instance of layout data that can be used to perform item-specific configurations for the given AlignmentStage.
Returns an instance of LayoutData<TNode,TEdge,TNodeLabel,TEdgeLabel> that can be used to perform item-specific configurations for the AlignmentStage.
Remarks
Parameters
A map of options to pass to the method.
- graph - IGraph
- the graph that determines the generic type arguments of the created layout data
Returns
- ↪AlignmentStageData<INode,IEdge,ILabel,ILabel>
- an instance of layout data that can be used to perform item-specific configurations for the given AlignmentStage.
LayoutExecutor
type is available at runtime.Constants
A data key for specifying the points of the nodes that are aligned.
Remarks
Assign to each node the position of the snap point relative to the center of the node.
Each non-group or empty group node is aligned with the specified point. Its coordinates are defined relatively to the node's center. It is required that the specified point lies within the boundary of the node or on the boundary. If the point is not defined, the node is aligned with its center.