|
Search this API | ||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object y.layout.AbstractLayoutStage y.layout.ComponentLayouter
public class ComponentLayouter
A ComponentLayouter
arranges the connected components of a graph.
The components can be arranged using different styles
. All styles except STYLE_NONE
place the components without overlaps.
Layout with orthogonal components using STYLE_MULTI_ROWS_COMPACT
ComponentLayouter
is a LayoutStage
that can wrap another layout algorithm
. That way,
it allows handling disconnected graphs for the wrapped core layout algorithm
.
The following steps outline the concept of ComponentLayouter
:
core layout algorithm
to the componentOptionally arrange
the components
To arrange the subgraphs of the components, ComponentLayouter
uses the specified
core layout algorithm
. If there is no core layout algorithm
specified, it will keep the locations in the subgraph and arrange the components as they are.
Hierarchically grouped graphs are handled in a special way.
The contents of a group node will always belong to the same component as the group node itself. To change that
behavior grouping
can be disabled.
By default, the components consist of the connected nodes in a graph. To choose custom subgraphs to form components,
register a DataProvider
with GIVEN_COMPONENT_ID_DPKEY
and assign component IDs to the nodes.
When arranging components
, node types
(see Layouter.NODE_TYPE_DPKEY
) can be considered. If all nodes of a component have the
same node type, the component is considered to be of that type. Components with same type are preferably put next
to each other. Note, however, that only the styles STYLE_ROWS
, STYLE_SINGLE_ROW
,
STYLE_SINGLE_COLUMN
and STYLE_MULTI_ROWS_TYPE_SEPARATED
handle types such
that an ordering by type is realized. Other styles aim at more important optimization criteria (e.g. compactness)
such that components of the same type are not guaranteed to be close to each other.
CanonicMultiStageLayouter
Field Summary | |
---|---|
static java.lang.Object |
GIVEN_COMPONENT_ID_DPKEY
A DataProvider key for specifying custom graph components
|
static java.lang.Object |
LAYOUT_NODE_DPKEY
A DataProvider key for specifying which nodes should be arranged
If no DataProvider is registered with this key, all components will be laid out by the core layout
algorithm. |
static byte |
STYLE_MASK
A constant for masking actual style constants from style modifiers. |
static byte |
STYLE_MODIFIER_AS_IS
A modifier that can be added to normal style specifiers to indicate that the arrangement strategy should take the initial positions of the components into account. |
static byte |
STYLE_MODIFIER_NO_OVERLAP
A modifier that can be added to normal style specifiers to indicate that the arrangement strategy should produce a non-overlapping component layout. |
static byte |
STYLE_MULTI_ROWS
Style specifier describing a component arrangement strategy that places components in multiple rows. |
static byte |
STYLE_MULTI_ROWS_COMPACT
Style specifier describing a component arrangement strategy that places components in multiple rows. |
static byte |
STYLE_MULTI_ROWS_HEIGHT_CONSTRAINED
Style specifier describing a component arrangement strategy that places the components in STYLE_MULTI_ROWS
with a restricted height. |
static byte |
STYLE_MULTI_ROWS_HEIGHT_CONSTRAINED_COMPACT
Style specifier describing a component arrangement strategy that places the components in STYLE_MULTI_ROWS
with a restricted height and as compact as possible. |
static byte |
STYLE_MULTI_ROWS_TYPE_SEPARATED
Style specifier describing a component arrangement strategy that places the components in multiple nested rows, like STYLE_MULTI_ROWS , but separates components of different node type . |
static byte |
STYLE_MULTI_ROWS_WIDTH_CONSTRAINED
Style specifier describing a component arrangement strategy that places the components in STYLE_MULTI_ROWS
with a restricted width. |
static byte |
STYLE_MULTI_ROWS_WIDTH_CONSTRAINED_COMPACT
Style specifier describing a component arrangement strategy that places the components in STYLE_MULTI_ROWS
with a restricted width and as compact as possible. |
static byte |
STYLE_NONE
Style specifier describing no special component arrangement at all. |
static byte |
STYLE_PACKED_CIRCLE
Style specifier describing a component arrangement strategy that places components in a circular cloud around the biggest component. |
static byte |
STYLE_PACKED_COMPACT_CIRCLE
Style specifier describing a component arrangement strategy that places components in a circular compact cloud around the biggest component. |
static byte |
STYLE_PACKED_COMPACT_RECTANGLE
Style specifier describing a component arrangement strategy that places components in a rectangular cloud around the biggest component. |
static byte |
STYLE_PACKED_RECTANGLE
Style specifier describing a component arrangement strategy that places components in a rectangular cloud around the biggest component. |
static byte |
STYLE_ROWS
Style specifier describing a component arrangement strategy that places components in multiple rows so that the overall aspect ratio of the whole graph gets as close to the aspect ratio of the preferred layout size as possible. |
static byte |
STYLE_SINGLE_COLUMN
Style specifier describing a component arrangement strategy that places components above each other in a single column. |
static byte |
STYLE_SINGLE_ROW
Style specifier describing a component arrangement strategy that places all components next to each other in a single row. |
Fields inherited from interface y.layout.Layouter |
---|
EDGE_ID_DPKEY, NODE_ID_DPKEY, NODE_TYPE_DPKEY, SELECTED_EDGES, SELECTED_NODES |
Constructor Summary | |
---|---|
ComponentLayouter()
Creates a new ComponentLayouter instance with default settings. |
|
ComponentLayouter(Layouter coreLayouter)
Creates a new ComponentLayouter instance using the given core layout algorithm . |
Method Summary | |
---|---|
protected void |
arrangeComponents(LayoutGraph graph,
NodeList[] nodes,
EdgeList[] edges,
YRectangle[] bbox,
java.awt.geom.Rectangle2D[] boxes)
Produces a component graph layout. |
protected void |
arrangeFields(LayoutGraph graph,
NodeList[] nodes,
EdgeList[] edges,
YRectangle[] bbox,
java.awt.geom.Rectangle2D[] boxes,
boolean circular,
boolean fill,
boolean fromSketch)
Arranges the bounding boxes of the components. |
protected java.awt.geom.Rectangle2D |
calcBoundingBox(LayoutGraph graph)
Calculates the bounding box of a graph component including NodeHalo s. |
boolean |
canLayout(LayoutGraph graph)
Accepts graphs where all components can be arranged by the core layout algorithm . |
void |
doLayout(LayoutGraph graph)
Delegates the layout calculation for each component separately to the core layout algorithm and optionally arranges the components. |
protected int |
findGraphComponents(LayoutGraph graph,
NodeMap compNumber)
Determines which nodes belong to the same graph component. |
double |
getComponentSpacing()
Returns the distance between the bounding boxes of the components. |
double |
getGridSpacing()
Returns the current grid spacing. |
YDimension |
getPreferredLayoutSize()
Returns the preferred size of the layout. |
byte |
getStyle()
Returns how the components are arranged. |
boolean |
isComponentArrangementEnabled()
Returns whether or not the separately arranged components of the input graph should be arranged relative to each other. |
boolean |
isGroupingActive()
Returns whether or not grouping information bound to the graph should be considered when determining the graph components. |
boolean |
isLabelAwarenessEnabled()
Returns whether or not to take node and edge labels into account when calculating the bounding box of the graph components. |
void |
setComponentArrangementEnabled(boolean enabled)
Specifies whether or not the separately arranged components of the input graph should be arranged relative to each other. |
void |
setComponentSpacing(double componentSpacing)
Specifies the distance between the bounding boxes of the components. |
void |
setGridSpacing(double gridSpacing)
Specifies the current grid spacing. |
void |
setGroupingActive(boolean groupingActive)
Specifies whether or not grouping information bound to the graph should be considered when determining the graph components. |
void |
setLabelAwarenessEnabled(boolean enabled)
Specifies whether or not to take node and edge labels into account when calculating the bounding box of the graph components. |
protected void |
setOrigin(LayoutGraph graph,
NodeList nodes,
EdgeList edges,
YPoint origin,
YRectangle rectangle)
Moves the subgraph containing the given nodes and edges to the specified origin. |
void |
setPreferredLayoutSize(double width,
double height)
Specifies the preferred width and height of the layout. |
void |
setPreferredLayoutSize(YDimension size)
Specifies the preferred size of the layout. |
void |
setStyle(byte style)
Specifies how the components are arranged. |
Methods inherited from class y.layout.AbstractLayoutStage |
---|
canLayoutCore, doLayoutCore, getCoreLayouter, setCoreLayouter |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static final java.lang.Object LAYOUT_NODE_DPKEY
DataProvider
key for specifying which nodes should be arranged
If no DataProvider
is registered with this key, all components will be laid out by the core layout
algorithm.
public static final java.lang.Object GIVEN_COMPONENT_ID_DPKEY
DataProvider
key for specifying custom graph components
IncrementalHierarchicLayouter
,
PartitionLayouter
and EdgeRouter
can handle such components).
Hence, you should not assign the same
component ID to nodes of different connected components
for algorithms that cannot handle the disconnected components.public static final byte STYLE_NONE
STYLE_MODIFIER_NO_OVERLAP
,
components might get moved so that they don't overlap after the layout.
public static final byte STYLE_ROWS
public static final byte STYLE_SINGLE_ROW
STYLE_MODIFIER_AS_IS
,
components will be placed in the same order as they were placed before the layout.
public static final byte STYLE_SINGLE_COLUMN
STYLE_MODIFIER_AS_IS
,
components will be placed in the same order as they were placed before the layout.
public static final byte STYLE_PACKED_RECTANGLE
The aspect ratio of the rectangle is defined by the preferred size
of the graph.
public static final byte STYLE_PACKED_COMPACT_RECTANGLE
In contrast to STYLE_PACKED_RECTANGLE
, components might even be placed in empty spaces inside other
components.
The aspect ratio of the rectangle is defined by the preferred size
of the graph.
public static final byte STYLE_PACKED_CIRCLE
public static final byte STYLE_PACKED_COMPACT_CIRCLE
In contrast to STYLE_PACKED_CIRCLE
, components might even be placed in empty spaces inside other components.
public static final byte STYLE_MULTI_ROWS
The strategy tries to arrange the components such that the aspect ratio of the final component placement
gets as close as possible to the aspect ratio of the preferred layout size, configurable
using setPreferredLayoutSize(YDimension)
.
In contrast to STYLE_ROWS
, each row may also be divided into further sub-rows, which is especially
useful if there are few very large components and many significantly smaller ones.
public static final byte STYLE_MULTI_ROWS_COMPACT
The strategy tries to arrange the components such that the aspect ratio of the final component placement
gets close to the aspect ratio of the preferred layout size, configurable using
setPreferredLayoutSize(YDimension)
. But in contrast to STYLE_MULTI_ROWS
, this strategy does
not always try to come as close to the preferred view ratio, if a ratio close to the preferred
ratio only induces a lot of unused view space. This unused space will be minimized.
In contrast to STYLE_ROWS
, each row may also be divided into further sub-rows, which is especially
useful if there are few very large components and many significantly smaller ones.
public static final byte STYLE_MULTI_ROWS_HEIGHT_CONSTRAINED
STYLE_MULTI_ROWS
with a restricted height.
The resulting height does not exceed the preferred height (getPreferredLayoutSize()
).
In contrast to STYLE_MULTI_ROWS_HEIGHT_CONSTRAINED_COMPACT
, the result will be an arrangement which uses
as much height as possible, even if that means that all components will be arranged in one single column.
public static final byte STYLE_MULTI_ROWS_HEIGHT_CONSTRAINED_COMPACT
STYLE_MULTI_ROWS
with a restricted height and as compact as possible.
The resulting height does not exceed the preferred height (getPreferredLayoutSize()
).
In comparison with STYLE_MULTI_ROWS_HEIGHT_CONSTRAINED
, the result will be compacted, which means that
an arrangement with the minimum width such that the height constraint is still fulfilled will be realized.
public static final byte STYLE_MULTI_ROWS_WIDTH_CONSTRAINED
STYLE_MULTI_ROWS
with a restricted width.
The resulting width does not exceed the preferred width (getPreferredLayoutSize()
).
In contrast to STYLE_MULTI_ROWS_WIDTH_CONSTRAINED_COMPACT
the result will be an arrangement which uses
as much space in width as possible, even if that means that all components will be arranged in a single row.
public static final byte STYLE_MULTI_ROWS_WIDTH_CONSTRAINED_COMPACT
STYLE_MULTI_ROWS
with a restricted width and as compact as possible.
The resulting width does not exceed the preferred width (getPreferredLayoutSize()
).
In comparison with STYLE_MULTI_ROWS_HEIGHT_CONSTRAINED
the result will be compacted, in order to
minimize unused view space induced by components that are large in height.
public static final byte STYLE_MULTI_ROWS_TYPE_SEPARATED
STYLE_MULTI_ROWS
, but separates components of different node type
.
The strategy for placing components of same type is equal to the one of STYLE_MULTI_ROWS
, but components
of different node type are not placed in the same nested row. This means rows are not filled-up
anymore (even though there would be space), but the components of different type are placed in a new row.
Therefore, this strategy produces more rows and is less compact.
The type of a component is derived from the type of its nodes such that if most of the nodes are of same type, the component is considered to be of this dominant type, too. If there is no dominant type, the component is considered to have no type. Components without type are separated from the components with type.
In contrast to STYLE_MULTI_ROWS
without type separation, this strategy may not come as close
to the preferred view ratio, because the node types are of higher priority. Furthermore, results
may contain more white space and be less compact.
setStyle(byte)
,
setPreferredLayoutSize(YDimension)
,
Layouter.NODE_TYPE_DPKEY
,
Constant Field Valuespublic static final byte STYLE_MASK
setStyle(byte)
,
Constant Field Valuespublic static final byte STYLE_MODIFIER_AS_IS
Combining this modifier is supported with the following styles:
STYLE_SINGLE_ROW
and STYLE_SINGLE_COLUMN
.
setStyle(byte)
,
Constant Field Valuespublic static final byte STYLE_MODIFIER_NO_OVERLAP
Combining this modifier is not supported with STYLE_NONE
.
STYLE_NONE
.setStyle(byte)
,
Constant Field ValuesConstructor Detail |
---|
public ComponentLayouter(Layouter coreLayouter)
ComponentLayouter
instance using the given core layout algorithm
.
coreLayouter
- the core layout routinepublic ComponentLayouter()
ComponentLayouter
instance with default settings.
Method Detail |
---|
public void setPreferredLayoutSize(double width, double height)
Width and height define the preferred layout size and also the desired aspect ratio (width/height).
Width and height need to be greater than zero.
STYLE_NONE
, STYLE_SINGLE_ROW
and STYLE_SINGLE_COLUMN
do not consider the
preferred layout size.width
- the preferred width of the calculated graph layoutheight
- the preferred height of the calculated graph layout
java.lang.IllegalArgumentException
- if the specified width or height is negative or zero.setPreferredLayoutSize(YDimension)
public void setPreferredLayoutSize(YDimension size)
The layout size also defines the desired aspect ratio (width/height).
The width and height need to be greater than zero.
STYLE_NONE
, STYLE_SINGLE_ROW
and STYLE_SINGLE_COLUMN
do not consider the
preferred layout size.YDimension
. Both preferred width and height are 400
.size
- the preferred size of the calculated graph layout
java.lang.IllegalArgumentException
- if the specified width or height is negative or zero
or the given dimension is null
Size 100x400 | Size 400x400 | Size 400x100 |
public YDimension getPreferredLayoutSize()
The layout size also defines the desired aspect ratio (width/height).
The width and height need to be greater than zero.
STYLE_NONE
, STYLE_SINGLE_ROW
and STYLE_SINGLE_COLUMN
do not consider the
preferred layout size.setPreferredLayoutSize(YDimension)
public boolean canLayout(LayoutGraph graph)
core layout algorithm
.
graph
- the input graph
true
if all components of the graph can be handled by the
core layout algorithm
, the graph is empty
or
there is no core layout algorithm, false
otherwiseLayouter.doLayout(LayoutGraph)
protected int findGraphComponents(LayoutGraph graph, NodeMap compNumber)
This implementation uses the graph connectivity to sort the nodes into different components. Nodes that are not connected by a path will be in separate components.
This method is called by doLayout(LayoutGraph)
. It may be overridden to choose another approach to find
components that will be passed to the core layout algorithm
. However, most of the layout
algorithms cannot handle disconnected graphs. Also, edges between custom components will be ignored.
graph
- the input graphcompNumber
- a map that will be filled with the zero-based index of the component to which the node
belongs
GraphConnectivity.connectedComponents(y.base.Graph)
public void doLayout(LayoutGraph graph)
core layout algorithm
and optionally arranges the components.
graph
- the input graphLayouter.canLayout(LayoutGraph)
protected java.awt.geom.Rectangle2D calcBoundingBox(LayoutGraph graph)
NodeHalo
s.
This method will be invoked for each component of the graph. Depending on the state of property
isLabelAwarenessEnabled()
, the returned bounding box will also include node and edge labels.
It may be overridden to extend the bounds to reserve space for other elements.
graph
- the subgraph containing the nodes and edges of a component
setLabelAwarenessEnabled(boolean)
public void setLabelAwarenessEnabled(boolean enabled)
enabled
- true
if node and edge labels should be taken into account when calculating the bounding box
of the graph components, false
otherwisecalcBoundingBox(LayoutGraph graph)
false | true |
public boolean isLabelAwarenessEnabled()
true
if node and edge labels are taken into account when calculating the bounding box of the
graph components, false
otherwisesetLabelAwarenessEnabled(boolean)
,
calcBoundingBox(LayoutGraph graph)
protected void arrangeComponents(LayoutGraph graph, NodeList[] nodes, EdgeList[] edges, YRectangle[] bbox, java.awt.geom.Rectangle2D[] boxes)
This method is called by doLayout(LayoutGraph)
in case
component arrangement
is enabled. It moves the graph's components such
that their bounding boxes do not overlap.
Subclasses may want to override this method to introduce custom component arrangement styles.
STYLE_NONE
, STYLE_SINGLE_ROW
and STYLE_SINGLE_COLUMN
are
excluded.graph
- the input graphnodes
- the nodes of the components; the i-th list contains the nodes of the i-th componentedges
- the edges of the components; the i-th list contains the edges of the i-th componentbbox
- the bounds of the components; the i-th rectangle describes the bounding box of the i-th componentboxes
- the extended bounds of the components; the i-th rectangle describes the bounding box of the i-th
component extended by the spacing between components.
The method arranges these boxes in such a way that they do not overlap. Then, the i-th graph component
must be placed inside the i-th boxarrangeFields(LayoutGraph, NodeList[], EdgeList[], YRectangle[], Rectangle2D[], boolean, boolean, boolean)
,
LayoutTool.arrangeRectangleRows(Rectangle2D[], Rectangle2D, double)
,
LayoutTool.arrangeRectangleMultiRows(Rectangle2D[], Rectangle2D, double, double, boolean, byte)
public void setComponentArrangementEnabled(boolean enabled)
style
without producing overlaps
between components (except for STYLE_NONE
). Otherwise, the
layout algorithm will keep the components at their location. Then, the components may overlap.
public boolean isComponentArrangementEnabled()
style
without producing overlaps
between components (except for STYLE_NONE
). Otherwise, the
layout algorithm will keep the components at their location. Then, the components may overlap.
true
if the components of the graph are arranged,
false
otherwisesetComponentArrangementEnabled(boolean)
protected void setOrigin(LayoutGraph graph, NodeList nodes, EdgeList edges, YPoint origin, YRectangle rectangle)
This method is called by arrangeComponents(LayoutGraph, NodeList[], EdgeList[], YRectangle[], Rectangle2D[])
and arrangeFields(LayoutGraph, NodeList[], EdgeList[], YRectangle[], Rectangle2D[], boolean, boolean, boolean)
to move the components to overlap-free positions.
graph
- the input graphnodes
- the nodes in the moving subgraphedges
- the edges in the moving subgraphorigin
- the new origin of the graphrectangle
- the current bounds of the subgraphpublic double getGridSpacing()
The spacing needs to be a non-negative value. If the grid spacing is set to 0
,
the grid won't be considered at all.
setGridSpacing(double)
public void setGridSpacing(double gridSpacing)
The spacing needs to be a non-negative value. If the grid spacing is set to 0
,
the grid won't be considered at all.
gridSpacing
- the grid spacing
java.lang.IllegalArgumentException
- if the given spacing is negativeThe initial graph | Grid spacing 30 | No grid (spacing 0 ) |
public double getComponentSpacing()
The spacing needs to be non-negative.
setComponentSpacing(double)
public void setComponentSpacing(double componentSpacing)
The spacing needs to be non-negative.
public boolean isGroupingActive()
true
if the nesting structure of the graph is considered when determining the
components, false
otherwisesetGroupingActive(boolean)
public void setGroupingActive(boolean groupingActive)
public byte getStyle()
component arrangement
is disabled.setStyle(byte)
public void setStyle(byte style)
component arrangement
is disabled.STYLE_ROWS
style
- one of the valid style specifiers
java.lang.IllegalArgumentException
- if the specified style is unknownprotected void arrangeFields(LayoutGraph graph, NodeList[] nodes, EdgeList[] edges, YRectangle[] bbox, java.awt.geom.Rectangle2D[] boxes, boolean circular, boolean fill, boolean fromSketch)
This method is called by arrangeComponents(LayoutGraph, NodeList[], EdgeList[], YRectangle[], Rectangle2D[])
if the style
is set to STYLE_PACKED_RECTANGLE
, STYLE_PACKED_COMPACT_RECTANGLE
,
STYLE_PACKED_CIRCLE
or STYLE_PACKED_COMPACT_CIRCLE
. It may be overridden to adjust the
component arrangement strategy of the mentioned styles.
graph
- the input graphnodes
- the nodes of the components; the i-th list contains the nodes of the i-th componentedges
- the edges of the components; the i-th list contains the edges of the i-th componentbbox
- the bounds of the components; the i-th rectangle describes the bounding box of the i-th
componentboxes
- the extended bounds of the components; the i-th rectangle describes the bounding box of the i-th
componentcircular
- true
if the arrangement should be circular, false
if it should be rectangularfill
- true
if it is allowed to place components in empty spaces inside other
components, false
otherwisefromSketch
- true
if the initial coordinates should be considered, false
otherwise
|
© Copyright 2000-2022, yWorks GmbH. All rights reserved. |
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |