public class OrthogonalLayout extends MultiStageLayout
This layout algorithm arranges the nodes of a given graph such that each edge is drawn as an alternating sequence of horizontal and vertical segments.
It produces compact drawings with no overlapping nodes, few crossings and few bends and is well suited for small and medium-sized sparse graphs.
Orthogonal drawings are common in engineering applications since they are able to provide clear representations of complex networks that can also be optimal with respect to diverse objective functions such as bend minimization or area minimization. Application domains of orthogonal drawings include software engineering, database schema representation, system management, knowledge representation, VLSI circuits and floor planning applications.
Orthogonal layout with default settings
This algorithm also optionally supports directed edge drawings
(although not in combination
with hierarchically nested graphs or the non-default
layout styles
). Application domains of directed orthogonal drawings include, for example,
software engineering, database schema and system management.
Sample output of OrthogonalLayout
with default settings. Marked edges are considered as directed and the layout
orientation is top-to-bottom.
Sample output of OrthogonalLayout
with edge grouping. All edges are considered directed and the layout
orientation is left-to-right.
Also this algorithm supports hierarchically nested graphs (although not in combination with the directed edge drawings,
the from sketch
option, or the non-default
layout styles
) feature:
Orthogonal layout of a grouped graph with default settings Orthogonal layout of a graph with nested groups
There exist several different layout styles that the orthogonal layout algorithm supports depending on whether or not
the edges should be routed completely orthogonal, or whether or not the original size of the nodes should be maintained.
Such layout styles are LayoutStyle.NORMAL
, LayoutStyle.UNIFORM
, LayoutStyle.BOX
,
LayoutStyle.NORMAL_TREE
, LayoutStyle.MIXED
, LayoutStyle.FIXED_BOX
, LayoutStyle.FIXED_MIXED
and can be applied using LayoutStyle
.
OrthogonalLayout
is able to consider edge label data when arranging a graph. This means that the layout
algorithm will determine the positions of the nodes and edges such that the edge labels do not overlap with the rest of
the layout. Integrated edge labeling can be activated using method
IntegratedEdgeLabelingEnabled
.
EdgeLayoutDescriptor
instances can be used for specifying individual information (e.g. distances) for each edge
in the graph. The descriptors are bound to the graph using IDataProvider
s registered with key
EDGE_LAYOUT_DESCRIPTOR_DPKEY
. If there is no descriptor assigned to some edges, a default descriptor will
be used. To set default descriptors, use EdgeLayoutDescriptor
.
OrthogonalLayout
tries to optimize diverse objective functions such as bend minimization, number of edge
crossings, edge length minimization or face maximization. These settings can be enabled using the corresponding methods
PerceivedBendOptimizationEnabled
,
CrossingReductionEnabled
,
EdgeLengthReductionEnabled
, and
FaceMaximizationEnabled
, respectively. The drawback when these settings
are enabled is that the running time of the algorithm may be drastically increased.
Modifier and Type | Field and Description |
---|---|
static EdgeDpKey<Boolean> |
DIRECTED_EDGE_DPKEY
A
DataProvider key for marking edges which should be routed such that they point to the main layout orientation
The main layout orientation can be set using method
LayoutOrientation . |
static EdgeDpKey<EdgeLayoutDescriptor> |
EDGE_LAYOUT_DESCRIPTOR_DPKEY
A
DataProvider key for providing layout information for each edge
If no edge layout descriptor is mapped for an edge, a default edge layout descriptor will be obtained using method
createEdgeLayoutDescriptor() . |
Constructor and Description |
---|
OrthogonalLayout()
Creates a new
OrthogonalLayout instance with default settings. |
Modifier and Type | Method and Description |
---|---|
void |
applyLayout(LayoutGraph graph)
Calculates an orthogonal layout for the given graph.
|
void |
applyLayoutCore(LayoutGraph graph)
Calculates an orthogonal layout for the given graph.
|
protected EdgeLayoutDescriptor |
createEdgeLayoutDescriptor()
Returns a new
EdgeLayoutDescriptor instance that will be used during the various phases of the layout algorithm
to determine the drawing details of the edges of the graph. |
EdgeLayoutDescriptor |
getEdgeLayoutDescriptor()
Gets the
EdgeLayoutDescriptor instance used for all those edges that do not have a specific layout descriptor
assigned. |
int |
getGridSpacing()
Gets the equidistant spacing between the horizontal and vertical grid lines.
|
LayoutStyle |
getLayoutStyle()
Gets the layout style for this layout algorithm.
|
boolean |
isAligningDegreeOneNodesEnabled()
Gets whether or not degree-one nodes that have the same neighbor should be aligned.
|
boolean |
isCrossingReductionEnabled()
Gets whether or not the number of edge crossings should be reduced.
|
boolean |
isEdgeLengthReductionEnabled()
Gets whether or not the overall edge length should be optimized.
|
boolean |
isFaceMaximizationEnabled()
Gets whether or not one face of the embedding of the graph should be maximized.
|
boolean |
isFromSketchModeEnabled()
Gets whether or not the existing drawing should be used as a sketch of the resulting orthogonal layout.
|
boolean |
isIntegratedEdgeLabelingEnabled()
Gets whether or not the layout algorithm preserves space and places edge labels.
|
boolean |
isNodeLabelConsiderationEnabled()
Gets whether or not the layout algorithm considers node labels when calculating node positions to avoid overlaps.
|
boolean |
isPerceivedBendOptimizationEnabled()
Gets whether or not the number of perceived bends should be minimized.
|
boolean |
isRandomizationEnabled()
Gets whether or not a randomization strategy should be performed.
|
void |
setAligningDegreeOneNodesEnabled(boolean value)
Sets whether or not degree-one nodes that have the same neighbor should be aligned.
|
void |
setComponentLayoutEnabled(boolean value)
Sets whether or not the
ILayoutStage used for arranging the components of the graph is activated. |
void |
setCrossingReductionEnabled(boolean value)
Sets whether or not the number of edge crossings should be reduced.
|
void |
setEdgeLayoutDescriptor(EdgeLayoutDescriptor value)
Sets the
EdgeLayoutDescriptor instance used for all those edges that do not have a specific layout descriptor
assigned. |
void |
setEdgeLengthReductionEnabled(boolean value)
Sets whether or not the overall edge length should be optimized.
|
void |
setFaceMaximizationEnabled(boolean value)
Sets whether or not one face of the embedding of the graph should be maximized.
|
void |
setFromSketchModeEnabled(boolean value)
Sets whether or not the existing drawing should be used as a sketch of the resulting orthogonal layout.
|
void |
setGridSpacing(int value)
Sets the equidistant spacing between the horizontal and vertical grid lines.
|
void |
setHideGroupsStageEnabled(boolean value)
Sets whether or not the
ILayoutStage used for hiding group nodes is activated. |
void |
setIntegratedEdgeLabelingEnabled(boolean value)
Sets whether or not the layout algorithm preserves space and places edge labels.
|
void |
setLayoutStyle(LayoutStyle value)
Sets the layout style for this layout algorithm.
|
void |
setNodeLabelConsiderationEnabled(boolean value)
Sets whether or not the layout algorithm considers node labels when calculating node positions to avoid overlaps.
|
void |
setOrientationLayoutEnabled(boolean value)
Sets whether or not the
ILayoutStage that modifies the orientation of the layout is activated. |
void |
setPerceivedBendOptimizationEnabled(boolean value)
Sets whether or not the number of perceived bends should be minimized.
|
void |
setRandomizationEnabled(boolean value)
Sets whether or not a randomization strategy should be performed.
|
appendStage, checkNodeSize, disableAllStages, getComponentLayout, getHideGroupsStage, getLabeling, getLayoutOrientation, getOrientationLayout, getParallelEdgeRouter, getSelfLoopRouter, getSubgraphLayout, isComponentLayoutEnabled, isHideGroupsStageEnabled, isLabelingEnabled, isOrientationLayoutEnabled, isParallelEdgeRouterEnabled, isSelfLoopRouterEnabled, isSubgraphLayoutEnabled, prependStage, removeStage, setComponentLayout, setHideGroupsStage, setLabeling, setLabelingEnabled, setLayoutOrientation, setOrientationLayout, setParallelEdgeRouter, setParallelEdgeRouterEnabled, setSelfLoopRouter, setSelfLoopRouterEnabled, setSubgraphLayout, setSubgraphLayoutEnabled
public static final EdgeDpKey<Boolean> DIRECTED_EDGE_DPKEY
DataProvider
key for marking edges which should be routed such that they point to the main layout orientation
The main layout orientation can be set using method
LayoutOrientation
.
group nodes
exist in the graph component.public static final EdgeDpKey<EdgeLayoutDescriptor> EDGE_LAYOUT_DESCRIPTOR_DPKEY
DataProvider
key for providing layout information for each edge
If no edge layout descriptor is mapped for an edge, a default edge layout descriptor will be obtained using method
createEdgeLayoutDescriptor()
.
LayoutStyle.NORMAL
, LayoutStyle.NORMAL_TREE
and LayoutStyle.UNIFORM
.setLayoutStyle(LayoutStyle)
public OrthogonalLayout()
OrthogonalLayout
instance with default settings.public void applyLayout(LayoutGraph graph)
applyLayout
in interface ILayoutAlgorithm
applyLayout
in class MultiStageLayout
graph
- the input graphMultiStageLayout.appendStage(ILayoutStage)
,
MultiStageLayout.prependStage(ILayoutStage)
,
MultiStageLayout.applyLayoutCore(LayoutGraph)
public void applyLayoutCore(LayoutGraph graph)
applyLayoutCore
in class MultiStageLayout
graph
- the input graphprotected EdgeLayoutDescriptor createEdgeLayoutDescriptor()
EdgeLayoutDescriptor
instance that will be used during the various phases of the layout algorithm
to determine the drawing details of the edges of the graph.
This method may be overridden to create a new EdgeLayoutDescriptor
instance with different configuration
settings.
null
.EdgeLayoutDescriptor
instancepublic EdgeLayoutDescriptor getEdgeLayoutDescriptor()
EdgeLayoutDescriptor
instance used for all those edges that do not have a specific layout descriptor
assigned.
By default, this method will return an EdgeLayoutDescriptor
instance created with
createEdgeLayoutDescriptor()
.
IllegalArgumentException
- if the specified EdgeLayoutDescriptor
is null
EdgeLayoutDescriptor
EdgeLayoutDescriptor
instanceEDGE_LAYOUT_DESCRIPTOR_DPKEY
,
setEdgeLayoutDescriptor(EdgeLayoutDescriptor)
public int getGridSpacing()
Each node will be placed on a grid point. Edges will be routed such that all segments but the first and last one lie on grid lines. (The first and last segments of an edge may or may not lie on grid lines.) Edges consisting of a single segment always lie on grid lines.
The grid spacing has to be greater than 0
.
IllegalArgumentException
- if the grid spacing is negativelayout style
is
LayoutStyle.NORMAL
. For all other styles, it is used as a hint only.setGridSpacing(int)
public LayoutStyle getLayoutStyle()
IllegalArgumentException
- if an unknown layout style is givenLayoutStyle.NORMAL
setLayoutStyle(LayoutStyle)
public boolean isAligningDegreeOneNodesEnabled()
false
. Degree-one nodes with the same neighbor are not aligned with each other.true
if the degree-one nodes are aligned, false
otherwisesetAligningDegreeOneNodesEnabled(boolean)
public boolean isCrossingReductionEnabled()
The layout algorithm will try to significantly reduce the number of crossings in a post-processing step.
true
. The number of edge crossings is reduced.true
if the number of crossings is reduced, false
otherwisesetCrossingReductionEnabled(boolean)
public boolean isEdgeLengthReductionEnabled()
The algorithm will try to significantly reduce the length of some edges.
true
. The overall edge length is reduced.true
if the overall edge length minimization is reduced, false
otherwisesetEdgeLengthReductionEnabled(boolean)
public boolean isFaceMaximizationEnabled()
An embedding of a graph is uniquely specified by the cyclic order of edges incident to the same node in a graph drawing.
In any planar drawing of a planar graph, the edges divide the plane into different regions called faces. If one of these faces (the outer face) gets maximized, all other faces will be more compact.
false
. No face of the embedding is maximized.true
if a face of the embedding is maximized, false
otherwisesetRandomizationEnabled(boolean)
,
setFaceMaximizationEnabled(boolean)
public boolean isFromSketchModeEnabled()
The layout algorithm will try to orthogonalize the given sketch without making too many modifications with respect to the original drawing.
CrossingReductionEnabled
, FaceMaximizationEnabled
and PerceivedBendOptimizationEnabled
are not applied even if
enabled.group nodes
exist in the graph componentfalse
. The initial coordinates of the nodes are not considered.true
if the existing drawing is used as a sketch, false
otherwisesetFromSketchModeEnabled(boolean)
public boolean isIntegratedEdgeLabelingEnabled()
To define the desired placement for each label add a PreferredPlacementDescriptor
on
IEdgeLabelLayout
.
This method also assures that the labeling algorithm
is of type LabelLayoutTranslator
and EdgeLabelTranslationEnabled
is set to
true
.
IllegalStateException
- if no properly configured LabelLayoutTranslator
is registered even though integrated labeling was enabled
earlier (can happen when manually specifying the labeling algorithm
).labeling algorithm
will be
overwritten and when disabling it, any currently specified labeling algorithm will be disabled via property
LabelingEnabled
. Therefore, it is recommended to only use this
convenience property instead of manually changing the mentioned other properties.false
. Integrated edge labeling is disabled.true
if integrated edge labeling is enabled, false
otherwisesetIntegratedEdgeLabelingEnabled(boolean)
public boolean isNodeLabelConsiderationEnabled()
This method is a convenience method that assures that the labeling algorithm
is
of type LabelLayoutTranslator
and NodeLabelTranslationEnabled
is set to true
.
IllegalStateException
- if no properly configured LabelLayoutTranslator
is registered even though this property was enabled earlier (can
happen when manually specifying the labeling algorithm
).false
. Node labels are ignored.true
if the layout algorithm takes the node labels into account, false
otherwisesetNodeLabelConsiderationEnabled(boolean)
public boolean isPerceivedBendOptimizationEnabled()
A perceived bend is not an actual bend but it is created when a helical arrangement of chains of nodes occurs.
false
. The number of perceived bends will not be minimized.true
if the number of perceived bends is minimized, false
otherwisesetPerceivedBendOptimizationEnabled(boolean)
public boolean isRandomizationEnabled()
The randomization will increase the overall layout quality with high probability.
true
. A randomization strategy is applied.true
if randomization is performed, false
otherwisesetRandomizationEnabled(boolean)
public void setAligningDegreeOneNodesEnabled(boolean value)
false
. Degree-one nodes with the same neighbor are not aligned with each other.value
- true
if the degree-one nodes are aligned, false
otherwiseisAligningDegreeOneNodesEnabled()
public void setComponentLayoutEnabled(boolean value)
ILayoutStage
used for arranging the components of the graph is activated.setComponentLayoutEnabled
in class MultiStageLayout
OrthogonalLayout
can only handle single components. Disabling ComponentLayout
will lead to errors during
execution.true
. The stage that arranges connected graph components is activated.value
- true
if the stage that arranges the graph components is activated, false
otherwiseMultiStageLayout.isComponentLayoutEnabled()
,
MultiStageLayout.setComponentLayout(ILayoutStage)
,
ComponentLayout
public void setCrossingReductionEnabled(boolean value)
The layout algorithm will try to significantly reduce the number of crossings in a post-processing step.
true
. The number of edge crossings is reduced.value
- true
if the number of crossings is reduced, false
otherwiseisCrossingReductionEnabled()
public void setEdgeLayoutDescriptor(EdgeLayoutDescriptor value)
EdgeLayoutDescriptor
instance used for all those edges that do not have a specific layout descriptor
assigned.
By default, this method will return an EdgeLayoutDescriptor
instance created with
createEdgeLayoutDescriptor()
.
IllegalArgumentException
- if the specified EdgeLayoutDescriptor
is null
EdgeLayoutDescriptor
value
- the current EdgeLayoutDescriptor
instanceEDGE_LAYOUT_DESCRIPTOR_DPKEY
,
getEdgeLayoutDescriptor()
public void setEdgeLengthReductionEnabled(boolean value)
The algorithm will try to significantly reduce the length of some edges.
true
. The overall edge length is reduced.value
- true
if the overall edge length minimization is reduced, false
otherwiseisEdgeLengthReductionEnabled()
public void setFaceMaximizationEnabled(boolean value)
An embedding of a graph is uniquely specified by the cyclic order of edges incident to the same node in a graph drawing.
In any planar drawing of a planar graph, the edges divide the plane into different regions called faces. If one of these faces (the outer face) gets maximized, all other faces will be more compact.
false
. No face of the embedding is maximized.value
- true
if a face of the embedding is maximized, false
otherwisesetRandomizationEnabled(boolean)
,
isFaceMaximizationEnabled()
public void setFromSketchModeEnabled(boolean value)
The layout algorithm will try to orthogonalize the given sketch without making too many modifications with respect to the original drawing.
CrossingReductionEnabled
, FaceMaximizationEnabled
and PerceivedBendOptimizationEnabled
are not applied even if
enabled.group nodes
exist in the graph componentfalse
. The initial coordinates of the nodes are not considered.value
- true
if the existing drawing is used as a sketch, false
otherwiseisFromSketchModeEnabled()
public void setGridSpacing(int value)
Each node will be placed on a grid point. Edges will be routed such that all segments but the first and last one lie on grid lines. (The first and last segments of an edge may or may not lie on grid lines.) Edges consisting of a single segment always lie on grid lines.
The grid spacing has to be greater than 0
.
IllegalArgumentException
- if the grid spacing is negativelayout style
is
LayoutStyle.NORMAL
. For all other styles, it is used as a hint only.value
- the grid spacinggetGridSpacing()
public void setHideGroupsStageEnabled(boolean value)
ILayoutStage
used for hiding group nodes is activated.setHideGroupsStageEnabled
in class MultiStageLayout
OrthogonalLayout
cannot handle group nodes. Disabling HideGroupsStage
will lead to errors during
execution.true
. The stage responsible for hiding group nodes is activated.value
- true
if the stage used for hiding group nodes is activated, false
otherwiseMultiStageLayout.isHideGroupsStageEnabled()
,
MultiStageLayout.setHideGroupsStage(ILayoutStage)
,
HideGroupsStage
public void setIntegratedEdgeLabelingEnabled(boolean value)
To define the desired placement for each label add a PreferredPlacementDescriptor
on
IEdgeLabelLayout
.
This method also assures that the labeling algorithm
is of type LabelLayoutTranslator
and EdgeLabelTranslationEnabled
is set to
true
.
IllegalStateException
- if no properly configured LabelLayoutTranslator
is registered even though integrated labeling was enabled
earlier (can happen when manually specifying the labeling algorithm
).labeling algorithm
will be
overwritten and when disabling it, any currently specified labeling algorithm will be disabled via property
LabelingEnabled
. Therefore, it is recommended to only use this
convenience property instead of manually changing the mentioned other properties.false
. Integrated edge labeling is disabled.value
- true
if integrated edge labeling is enabled, false
otherwiseisIntegratedEdgeLabelingEnabled()
public void setLayoutStyle(LayoutStyle value)
IllegalArgumentException
- if an unknown layout style is givenLayoutStyle.NORMAL
value
- one of the predefined layout stylesgetLayoutStyle()
public void setNodeLabelConsiderationEnabled(boolean value)
This method is a convenience method that assures that the labeling algorithm
is
of type LabelLayoutTranslator
and NodeLabelTranslationEnabled
is set to true
.
IllegalStateException
- if no properly configured LabelLayoutTranslator
is registered even though this property was enabled earlier (can
happen when manually specifying the labeling algorithm
).false
. Node labels are ignored.value
- true
if the layout algorithm takes the node labels into account, false
otherwiseisNodeLabelConsiderationEnabled()
public void setOrientationLayoutEnabled(boolean value)
ILayoutStage
that modifies the orientation of the layout is activated.setOrientationLayoutEnabled
in class MultiStageLayout
LayoutOrientation.TOP_TO_BOTTOM
, the orientation of the layout will not be
modified.OrientationLayout
has no significant effect unless directed orthogonal edges
are enabled.true
. The orientation ILayoutStage
is activated.value
- true
if the stage that modifies the orientation is activated, false
otherwiseMultiStageLayout.isOrientationLayoutEnabled()
,
MultiStageLayout.setOrientationLayout(ILayoutStage)
,
MultiStageLayout.setLayoutOrientation(com.yworks.yfiles.layout.LayoutOrientation)
,
OrientationLayout
public void setPerceivedBendOptimizationEnabled(boolean value)
A perceived bend is not an actual bend but it is created when a helical arrangement of chains of nodes occurs.
false
. The number of perceived bends will not be minimized.value
- true
if the number of perceived bends is minimized, false
otherwiseisPerceivedBendOptimizationEnabled()
public void setRandomizationEnabled(boolean value)
The randomization will increase the overall layout quality with high probability.
true
. A randomization strategy is applied.value
- true
if randomization is performed, false
otherwiseisRandomizationEnabled()