This layout algorithm clears a specified area by moving intersecting elements, while trying to minimize the changes in the given layout.
Remarks
Layout Style
The algorithm can be applied if it is necessary to make space within a specific region/area in an existing graph layout. It tries to keep the given layout style as much as possible. Ideally, only local changes in and around the marked area are made, such that the mental map for the user is preserved.
An example application is the use case that new nodes or a whole graph component were added to the graph and should be placed in a specific region of an existing graph layout. The region can then first be cleared using this algorithm such that afterwards the nodes or the component could be inserted without overlaps with other elements. This specific case can conveniently be implemented by defining a set of so-called area nodes, via AREA_NODES_DP_KEY. Another, more general use case would be nodes that grow in size, including the case that a folder node is expanded and converted to a larger group node. This case is easily realized by specifying the expanded node via EXPANDED_NODE_DP_KEY.
Concept
The area, which can be defined as a rectangle or an outline, defines a region in the given input graph which must be cleared. Clearing the area means no graph elements are allowed to intersect with it. This includes nodes and, depending on settings considerEdges, considerNodeLabels and considerEdgeLabels also edges, node labels and edge labels.
In order to clear the area, the graph elements must be moved. Moving an element often induces the necessity to move further elements along with them. Thus, depending on where the area is located in the input drawing, many elements may be moved to make the necessary space. How elements are selected and how they are moved highly depends on the chosen clearing strategy.
Features
For grouped graphs, the group nodes are also correctly handled by this algorithm. However, it is important to note that there is always one so-called area group node. It is the group node inside which the free space should be created and which may in consequence need to grow, see AREA_GROUP_NODE_DP_KEY for more details. When defining the free space via area nodes (see above), this group is automatically determined, otherwise it must explicitly be specified. If not specified, the free space is created in the top-level hierarchy.
The algorithm is able to consider a specified PartitionGrid as long as there are no group nodes that span multiple grid cells. Note that the cleared area is always allocated to a single cell of the grid, i.e., it is not possible that the area spans multiple cells. For this feature to work properly it is required that the values of the properties originalPosition, originalPosition originalWidth and originalHeight are correctly specified. This is usually automatically the case when executing the ClearAreaLayout as a standalone algorithm via layout execution convenience methods (e.g. the values are taken from the table visualization of the grid). However, if the ClearAreaLayout is applied as part of a more complex layout pipeline it may be necessary to specify the values manually. For example, if another algorithm previously computed the grid position values and stored them in the respective 'computed' properties (e.g. computedPosition), and afterwards ClearAreaLayout should be applied, then the 'computed' values of the first algorithm should be written to the 'original' values prior to the run of the ClearAreaLayout.
Default Values of Properties
area | null | There is no area to be cleared. |
clearAreaStrategy | PRESERVE_SHAPES
| |
componentAssignmentStrategy | CUSTOMIZED
| Components can be user-defined and if none are defined, each node is a separate component. |
considerEdgeLabels | true | Edge labels are considered. |
considerEdges | true | Edges are not allowed to intersect the area. |
considerNodeLabels | true | Node labels are considered. |
edgeRoutingStrategy | AUTOMATIC
| The routing strategy is automatically determined. |
fixPorts | true | Ports are fixed and not allowed to change when adjusting the edge paths. |
gridSpacing | 0 | No grid is considered. |
layoutOrientation | NONE
| The layout is considered to have no specific orientation. |
maximumDuration | <code>0x7FFFFFFF</code> | |
spacing | 10 |
Type Details
- yfiles module
- layout-area
- yfiles-umd modules
- layout-area, layout
- Legacy UMD name
- yfiles.partial.ClearAreaLayout
See Also
Constructors
Creates a new instance of ClearAreaLayout with default settings.
Parameters
A map of options to pass to the method.
- clearAreaStrategy - ClearAreaStrategy
The strategy applied for clearing the desired area. This option sets the clearAreaStrategy property on the created object.
- gridSpacing - number
The current grid spacing. This option sets the gridSpacing property on the created object.
- edgeRouter - ILayoutAlgorithm
The custom edge router instance that is applied to reroute edges. This option sets the edgeRouter property on the created object.
- edgeRoutingStrategy - PartialLayoutEdgeRoutingStrategy
The routing strategy that is preserved while clearing the area and applied when rerouting edges. This option sets the edgeRoutingStrategy property on the created object.
- componentAssignmentStrategy - ComponentAssignmentStrategy
The strategy that assigns nodes to components whose elements should preferably not be separated. This option sets the componentAssignmentStrategy property on the created object.
- maximumDuration - number
The time limit in milliseconds for the layout algorithm. This option sets the maximumDuration property on the created object.
- fixPorts - boolean
Whether the ports of the input graph must be fixed or if they can be changed. This option sets the fixPorts property on the created object.
- considerEdges - boolean
Whether or not edges are considered when clearing the area such that no segments intersecting the area are allowed. This option sets the considerEdges property on the created object.
- area - YRectangle
The rectangular area that must be cleared. This option sets the area property on the created object.
- areaOutline - BorderLine[]
The outline describing the shape of the area that must be cleared. This option sets the areaOutline property on the created object.
- layoutOrientation - PartialLayoutOrientation
The layout orientation that is considered during the clearing of the area. This option sets the layoutOrientation property on the created object.
- considerEdgeLabels - boolean
Whether or not the layout algorithm considers edge labels, moving them outside the area, if necessary. This option sets the considerEdgeLabels property on the created object.
- considerNodeLabels - boolean
Whether or not the layout algorithm considers node labels, moving them outside the area, if necessary. This option sets the considerNodeLabels property on the created object.
- spacing - number
The spacing that is considered between elements when they are moved to clear the area. This option sets the spacing property on the created object.
Properties
Gets or sets the rectangular area that must be cleared.
Remarks
Default Value
null
.There is no area to be cleared.
See Also
Gets or sets the outline describing the shape of the area that must be cleared.
Remarks
- index
0
: the top border line - index
1
: the right border line - index
2
: the bottom border line - index
3
: the left border line
Default Value
null
.There is no outline to be cleared.
Throws
- Exception({ name: 'ArgumentError' })
- if the given array does not contain exactly four non-null
s
See Also
Gets or sets the strategy applied for clearing the desired area.
Remarks
Default Value
PRESERVE_SHAPES.Throws
- Exception({ name: 'ArgumentError' })
- if an unknown strategy is provided
See Also
Gets or sets the strategy that assigns nodes to components whose elements should preferably not be separated.
Remarks
- CUSTOMIZED: the components can be user-defined. If the user does not specify any, there are no components that should explicitly be kept together, which is equal to the behavior of SINGLE.
- CONNECTED components are defined by the connected components of the graph.
- CLUSTERING: components are defined by edge betweenness clustering.
- SINGLE: each node is a separate component which basically means that there are no components that should explicitly be kept together.
Default Value
CUSTOMIZED.Components can be user-defined and if none are defined, each node is a separate component.
Throws
- Exception({ name: 'ArgumentError' })
- if the specified strategy does not match one of the predefined strategies
See Also
Gets or sets whether or not the layout algorithm considers edge labels, moving them outside the area, if necessary.
Remarks
When enabled, the edge labels intersecting the area are explicitly rearranged even if the corresponding edges would not be changed.
If disabled, edge labels may remain intersecting with the area. In addition, after moving elements to clear the area, there may be new edge label overlaps.
Default Value
true
.Edge labels are considered.
See Also
Gets or sets whether or not edges are considered when clearing the area such that no segments intersecting the area are allowed.
Remarks
If enabled, edges that must be rerouted are not allowed to intersect the area that is cleared. Furthermore, edges whose source and target node are not moved but where segments intersect the area in the input graph are rerouted in order to remove that intersection.
If disabled, edges are allowed to intersect the area that is cleared. This has the effect that the area is cleared of nodes only.
Default Value
true
.Edges are not allowed to intersect the area.
See Also
Sample Graphs
Gets or sets whether or not the layout algorithm considers node labels, moving them outside the area, if necessary.
Remarks
Internally, nodes are treated like they would have a size including their labels. Therefore, layout results can get significantly less compact if this feature is enabled.
If this feature is disabled, node labels may remain intersecting with the area. In addition, after moving elements to clear the area, there may be new node label overlaps.
Default Value
true
.Node labels are considered.
See Also
Gets or sets the custom edge router instance that is applied to reroute edges.
Remarks
Several types of edges can be routed by this algorithm:
- Edges where one or both endpoints where displaced in order to clear the area. It depends on the strategy if such edges are actually handled by the routing algorithm or if they are implicitly moved. For example, strategy PRESERVE_SHAPES tries to keep the shapes and can avoid rerouting in many cases.
- So-called inter-edges resulting from the area nodes component. If such a component exists, the inter-edges are the edges connecting area nodes with non-area nodes. They are always handled by this routing algorithm, independent of the strategy.
- Edges connecting to a specifically marked expanded node and to the descendants of the expanded node in case it is a group node.
Changing the value of property edgeRoutingStrategy automatically sets a new edge router instance according to the specified routing strategy, thus, overwriting any previously set instances. The following routing algorithms are set:
- EdgeRouter for strategies ORTHOGONAL and OCTILINEAR.
- OrganicEdgeRouter for strategy ORGANIC.
- StraightLineEdgeRouter for strategy STRAIGHTLINE.
Default Value
null
.There is no custom router and the routing strategy is automatically determined.
See Also
Gets or sets the routing strategy that is preserved while clearing the area and applied when rerouting edges.
Remarks
The algorithm assumes that the existing edges have paths according to the specified strategy and takes this into account when moving nodes and edges in order to clear the area. If the automatic strategy is set, then no assumptions are made but the given paths are analyzed to derive the best fitting routing strategy. Note that in this case, the algorithm may use different routing styles for the edges.
This routing strategy is also relevant when edges need to be rerouted, as it determines the routing algorithm used for rerouting, see edgeRouter for more details.
Default Value
Throws
- Exception({ name: 'ArgumentError' })
- if the given strategy does not match one of the predefined routing strategies
See Also
Gets or sets whether the ports of the input graph must be fixed or if they can be changed.
Remarks
This property is relevant for edges that are rerouted in order to clear the area, i.e., edges where one or both endpoints where displaced or edges that intersect the area in the input graph (depending on property considerEdges) and that are consequently handled by the specified edge router. Inter-edges resulting from the area nodes component are not affected by this property (edges connecting area nodes with non-area nodes). For such edges, the behavior is the same as if this property would be disabled, see the following description. The same applies for edges incident to the expanded node or the descendants of the expanded node (if one endpoint is not the expanded node or a descendant).
If the ports are fixed, then the port side and location are not changed, except for group nodes that grow due to the area inside them. Edges at these groups keep the port side, but the absolute location is not fixed.
If disabled, the algorithm considers specified PortConstraint and PortCandidates when rerouting edges. If there are no such constraints for an edge, then the ports of that edge can be freely placed. This can often produce better edge routes in the resulting drawing, however, the overall shape of the edge may then not be preserved.
Default Value
true
.Ports are fixed and not allowed to change when adjusting the edge paths.
See Also
Gets or sets the current grid spacing.
Remarks
Elements are moved by multiples of this value, thus, keeping their offset to the grid. That way, components or parts of them that were placed on a grid before, will stay on their original grid.
The grid spacing needs to be a non-negative value. If it is set to 0
, no grid is considered.
Default Value
0
.No grid is considered.
Throws
- Exception({ name: 'ArgumentError' })
- if the given spacing is negative
See Also
Gets or sets the layout orientation that is considered during the clearing of the area.
Remarks
The orientation affects the direction that the algorithm prefers when moving elements. For the vertical orientations TOP_TO_BOTTOM and BOTTOM_TO_TOP, moving elements horizontally (i.e. to the left and to the right) is preferred. For the horizontal orientations LEFT_TO_RIGHT and RIGHT_TO_LEFT, the vertical moving direction is preferred. This is mainly useful for layouts that have a clear direction and nodes are divided into layers with respect to this directions, like e.g., hierarchical layouts.
If this behavior is undesired, the orientation can be ignored by specifying NONE. No specific moving direction will be preferred in that case. The orientation can also be automatically detected based on the flow direction of the edges when choosing AUTO_DETECT.
Default Value
Throws
- Exception({ name: 'ArgumentError' })
- if the specified orientation does not match one of the predefined orientations
See Also
Gets or sets the time limit in milliseconds for the layout algorithm.
Remarks
0
.Default Value
<code>0x7FFFFFFF</code>
.Throws
- Exception({ name: 'ArgumentError' })
- if the maximum duration is negative
See Also
Gets or sets the spacing that is considered between elements when they are moved to clear the area.
Remarks
This spacing only affects the moving of elements out of the area. Elements keep the specified distance to other elements. Carefully observe that if the distance between two elements is already smaller, then they may not be moved apart.
Strategies PRESERVE_SHAPES, PRESERVE_SHAPES_UNIFORM and GLOBAL consider the spacing for all graph elements, including nodes, edges, node labels and edge labels when they are encountered during the movement process. On the other hand, strategies LOCAL and LOCAL_UNIFORM consider the spacing only with respect to nodes.
Default Value
10
.Throws
- Exception({ name: 'ArgumentError' })
- if the given spacing is negative
See Also
Sample Graphs
Methods
Clears the specified rectangular area, the area defined via AREA_NODES_DP_KEY or EXPANDED_NODE_DP_KEY by moving all other graph elements currently intersecting with it.
Parameters
A map of options to pass to the method.
- graph - LayoutGraph
- the input graph
See Also
Implements
Creates and sets the value of the property areaOutline of the layout
determined from the items
.
Remarks
Parameters
A map of options to pass to the method.
- items - IEnumerable<IModelItem>
- The IModelItems from which the BorderLines are determined.
- spacing - number
- The spacing that is considered between the area and the elements.
- closed - boolean
- Whether the area is closed or can be traversed by other elements (without overlaps).
Class.ensure(LayoutExecutor)
More information.This method is called each time when edges are rerouted with the given edge router.
Remarks
This method may be overridden to customize the settings of the applied routing algorithm without manually specifying a custom router instance. This can be beneficial because the basic configuration of the router has already been made upon calling this method (e.g. setting up the scope). This method can then be implemented to fine-tune further settings, like, for example, minimum distance values.
The type of the given instance depends on the edge routing strategy.
- EdgeRouter for strategies ORTHOGONAL and OCTILINEAR.
- OrganicEdgeRouter for strategy ORGANIC.
- StraightLineEdgeRouter for strategy STRAIGHTLINE.
- If strategy AUTOMATIC is selected, one of the mentioned types is chosen, depending on the style of the given edge routes.
- If a custom edgeRouter is set, its instance corresponds to that of the parameter.
Parameters
A map of options to pass to the method.
- edgeRouter - ILayoutAlgorithm
- the instance used for routing the edges
See Also
Creates the outline that describes the shape of the given nodes and edges.
Remarks
This method is called when the area to be cleared is derived from a specified set of area nodes, see AREA_NODES_DP_KEY. The outline is defined by four BorderLines, which are then used as the area outline for the layout run.
The default implementation of this method includes the bounds of the given nodes, the bounding boxes of the segments of the given edges, as well as the bounds of the corresponding node and edge labels (depending on the properties considerNodeLabels and considerEdgeLabels. This method may be overridden if another way of deriving the area shape from the defined nodes and edges is desired (e.g. if only nodes shall be considered, ignoring edges).
The returned array must contain exactly four BorderLine instances where the indices are interpreted as follows:
- index
0
: the top border line - index
1
: the right border line - index
2
: the bottom border line - index
3
: the left border line
Parameters
A map of options to pass to the method.
- graph - LayoutGraph
- the input graph
- areaNodes - YNodeList
- the nodes that are part of the area that should be cleared
- areaEdges - EdgeList
- the edges that are adjacent to the given area nodes
Returns
- ↪BorderLine[]
- an array of four BorderLines describing the outline of the area to be cleared
Moves the areaOutline by the given delta
.
Remarks
Parameters
A map of options to pass to the method.
- delta - IPoint
- The delta to move the areaOutline.
Class.ensure(LayoutExecutor)
More information.Constants
A data provider key for specifying the group node inside which the cleared area should be located.
Remarks
The area that is cleared of elements can be associated to one specific group node. This means that this group can grow because the free space must be created inside it. In consequence, all ancestor nodes of the group may grow, too. Other groups are treated as fixed and must be moved in order to avoid an overlap with the specified area.
If no group is specified, the free space will be created in the top-level hierarchy.
Domain | YNode | the group nodes of the input graph |
Values | boolean | true if the free space should be created inside the group node false otherwise |
See Also
Sample Graphs
A data provider key for specifying a set of nodes that define the area which should be cleared.
Remarks
These nodes define a sort of component from which the area that must be cleared is derived by calling method createAreaOutline. This means that the area will exactly be defined by the current locations of these nodes (including the edges among them) such that after the algorithm execution there will not be any other elements intersecting with them.
Carefully observe that if group nodes are marked, all their descendants are treated as area nodes too.
The area group node can not be defined manually, but the nearest common ancestor of all area nodes will become the area group node. For group nodes other than the area group either all their descendants including the group itself must be area nodes or all their descendants including the group must not be area nodes. If the input is not complete in this matter, the required nodes are internally automatically treated as area nodes too.
Domain | YNode | the nodes of the input graph |
Values | boolean | true if the node should be considered part of the area component, false otherwise |
See Also
Sample Graphs
A data provider key for defining custom components whose elements should preferably not be separated.
Remarks
Domain | YNode | the nodes of the input graph |
Values | Object | all nodes associated with the same object are assigned to the same component |
See Also
A data provider key for marking the node that was expanded and, thus, defines the area that must be cleared.
Remarks
When an expanded node is provided, the area that must be cleared is directly derived from the size of the expanded node. Defining an expanded node is intended for the case that a node's size increased such that it might now overlap with other graph elements. This includes the use case of expanding a folder node.
It is strongly recommended to additionally provide the original (smaller) bounds of the expanded node via EXPANDED_NODE_ORIGINAL_BOUNDS_DP_KEY. If the node has incident edges, it is also recommended to provide the original paths of these edges via key EXPANDED_NODE_ORIGINAL_EDGE_PATH_DP_KEY, i.e. the edge paths before the size of the node was changed (for example, before expanding a folder node). This includes paths of edges that were only incident to the non-expanded node and are now incident to descendants of it. Using this knowledge the algorithm clears the area occupied by the expanded node but also considers how the layout looked before the change. This way the mental map may be preserved to a higher degree.
Domain | YNode | the nodes of the input graph |
Values | boolean | true if the node was enlarged, false otherwise |
See Also
A data provider key for specifying the original, non-expanded bounds of the expanded node.
Remarks
Domain | Graph | the input graph |
Values | YRectangle | the original, non-expanded bounds of the expanded node |
See Also
A data provider key for associating original paths for edges connecting to the expanded node, including edges that did so only when the node was not yet expanded.
Remarks
When an expanded node is provided, the area that must be cleared is directly derived from the bounds of the expanded node. The original paths together with the original, non-expanded (smaller) bounds (see EXPANDED_NODE_ORIGINAL_BOUNDS_DP_KEY) of the expanded node are helpful to preserve the mental map of the overall drawing by providing knowledge about the previous layout state. Note, however, that only strategies PRESERVE_SHAPES, PRESERVE_SHAPES_UNIFORM and GLOBAL will significantly profit from it.
Carefully observe that the original paths must correspond to the ones that were valid when the expanded node still had its original, non-expanded bounds. Thus, they should only be provided when the original bounds are provided too.
Domain | Edge | the edges connecting to the expanded node, including edges that did so only in non-expanded state |
Values | YPointPath | the original path leading to the non-expanded node |
See Also
A data provider key for obtaining the edges that should be routed by the custom edge router.
Domain | Edge | |
Values | boolean | all edges associated with value true have to be routed by the |