Search this API

y.layout
Class ComponentLayouter

java.lang.Object
  extended by y.layout.AbstractLayoutStage
      extended by y.layout.ComponentLayouter
All Implemented Interfaces:
Layouter, LayoutStage
Direct Known Subclasses:
IsolatedGroupComponentLayouter

public class ComponentLayouter
extends AbstractLayoutStage

This layout stage arranges the connected components of a graph.

It is possible to specify a core layout algorithm that will be invoked on all connected components of the graph before this layouter arranges the components themselves.

ComponentLayouter will handle hierarchically grouped graphs in a special way. The contents of a group node will always belong to the same component as the group node itself.


Field Summary
static Object GIVEN_COMPONENT_ID_DPKEY
          DataProvider key that can be used to determine components by hand.
static Object LAYOUT_NODE_DPKEY
          DataProvider key that can be used to determine which nodes should be laid out.
static byte STYLE_MASK
          Use this constant for masking actual styles constants from style modifiers.
static byte STYLE_MODIFIER_AS_IS
          Modifier constant that can be added to normal style constants to indicate that the arrangement strategy should take the initial positions of the components into account.
static byte STYLE_MODIFIER_NO_OVERLAP
          Modifier constant that can be added to normal style constants to indicate that the arrangement strategy should produce a non-overlapping component layout.
static byte STYLE_NONE
          Style specification constant describing no special component arrangement at all.
static byte STYLE_PACKED_CIRCLE
          Style specification constant describing a component arrangement strategy that tries to place components like in a cloud around the biggest component.
static byte STYLE_PACKED_COMPACT_CIRCLE
          Style specification constant describing a component arrangement strategy that tries to place components like in a cloud around the biggest component.
static byte STYLE_PACKED_COMPACT_RECTANGLE
          Style specification constant describing a component arrangement strategy that tries to place components like in a rectangular cloud around the biggest component.
static byte STYLE_PACKED_RECTANGLE
          Style specification constant describing a component arrangement strategy that tries to place components like in a rectangular cloud around the biggest component.
static byte STYLE_ROWS
          Style specification constant describing a component arrangement strategy that tries to place components in multiple rows so that the overall aspect ratio of all components gets as close to the aspect ratio of the preferred layout size as possible.
static byte STYLE_SINGLE_COLUMN
          Style specification constant describing a component arrangement strategy that places components above each other in a single column.
static byte STYLE_SINGLE_ROW
          Style specification constant describing a component arrangement strategy that places components next to each other in a single row.
 
Fields inherited from interface y.layout.Layouter
EDGE_ID_DPKEY, NODE_ID_DPKEY, SELECTED_EDGES, SELECTED_NODES
 
Constructor Summary
ComponentLayouter()
          Initializes a new ComponentLayouter instance.
ComponentLayouter(Layouter coreLayouter)
          Initializes a new ComponentLayouter instance.
 
Method Summary
protected  void arrangeComponents(LayoutGraph graph, NodeList[] nodes, EdgeList[] edges, YRectangle[] bbox, Rectangle2D[] boxes)
          Produces a non-overlapping component graph layout.
protected  void arrangeFields(LayoutGraph graph, NodeList[] nodes, EdgeList[] edges, YRectangle[] bbox, Rectangle2D[] boxes, boolean circular, boolean fill, boolean fromSketch)
           
protected  Rectangle2D calcBoundingBox(LayoutGraph graph)
          Calculates and returns the bounding box of a graph component.
 boolean canLayout(LayoutGraph graph)
          Determines if the preconditions for the graph layout algorithm are fulfilled, by applying them to the connected components.
 void doLayout(LayoutGraph graph)
          Calculate the layout.
protected  int findGraphComponents(LayoutGraph graph, NodeMap compNumber)
          Determines which nodes will belong to the same graph component.
 double getComponentSpacing()
          Returns the current component spacing.
 double getGridSpacing()
          Returns the current grid spacing.
 YDimension getPreferredLayoutSize()
          Gets the preferred layout size for this layouter.
 byte getStyle()
          Returns the component arrangement style used by this ComponentLayouter.
 boolean isComponentArrangementEnabled()
          Returns whether or not the separately laid out components of the input graph should be arranged by this class.
 boolean isGroupingActive()
          Determines whether or not grouping information bound to the graph will be used to calculate the components.
 boolean isLabelAwarenessEnabled()
          Determines whether or not to take node and edge labels into account when calculating the bounding box of the graph components.
 void setComponentArrangementEnabled(boolean enabled)
          Sets whether or not the separately laid out components of the input graph should be arranged by this class.
 void setComponentSpacing(double componentSpacing)
          Specifies the current component spacing.
 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 used to determine the connectedness of the graph structure.
 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 nl, EdgeList el, YPoint org, YRectangle r)
          Sets the origin for a subgraph.
 void setPreferredLayoutSize(double width, double height)
          Sets the preferred layout size for this layouter.
 void setStyle(byte style)
          Sets the component arrangement style used by this ComponentLayouter.
 
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

LAYOUT_NODE_DPKEY

public static final Object LAYOUT_NODE_DPKEY
DataProvider key that can be used to determine which nodes should be laid out. Note that components will be laid out if and only if at least one of the nodes that make up the component returns true if queried through the DataProvider instance. If no such instance is registered with the graph, all components will be laid out by the core layout algorithm.


GIVEN_COMPONENT_ID_DPKEY

public static final Object GIVEN_COMPONENT_ID_DPKEY
DataProvider key that can be used to determine components by hand. The algorithm will use the DataProvider.get(Object) method to query for object instances that will be used to determine components: If null is returned for a node that node's component will be determined as usual. If non-null values are returned, they will be compared using their natural order (Comparable) to determine the component order.


STYLE_NONE

public static final byte STYLE_NONE
Style specification constant describing no special component arrangement at all. Components will be centered at the same position they resided at before the layout started. If combined with the style modifier STYLE_MODIFIER_NO_OVERLAP components might get moved so that they don't overlap after the layout.

See Also:
setStyle(byte), Constant Field Values

STYLE_ROWS

public static final byte STYLE_ROWS
Style specification constant describing a component arrangement strategy that tries to place components in multiple rows so that the overall aspect ratio of all components gets as close to the aspect ratio of the preferred layout size as possible.

See Also:
setStyle(byte), setPreferredLayoutSize(double, double), Constant Field Values

STYLE_SINGLE_ROW

public static final byte STYLE_SINGLE_ROW
Style specification constant describing a component arrangement strategy that places components next to each other in a single row. If combined with the style modifier STYLE_MODIFIER_AS_IS components will be placed in the same order as they were placed before the layout.

See Also:
setStyle(byte), Constant Field Values

STYLE_SINGLE_COLUMN

public static final byte STYLE_SINGLE_COLUMN
Style specification constant describing a component arrangement strategy that places components above each other in a single column. If combined with the style modifier STYLE_MODIFIER_AS_IS components will be placed in the same order as they were placed before the layout.

See Also:
setStyle(byte), Constant Field Values

STYLE_PACKED_RECTANGLE

public static final byte STYLE_PACKED_RECTANGLE
Style specification constant describing a component arrangement strategy that tries to place components like in a rectangular cloud around the biggest component. Entities of different components will not overlap, however the bounding boxes of the components may overlap.

See Also:
setStyle(byte), Constant Field Values

STYLE_PACKED_COMPACT_RECTANGLE

public static final byte STYLE_PACKED_COMPACT_RECTANGLE
Style specification constant describing a component arrangement strategy that tries to place components like in a rectangular cloud around the biggest component. Entities of different components will not overlap, however the bounding boxes of the components may overlap. In contrast to STYLE_PACKED_RECTANGLE components might even be placed in empty spaces inside other components.

See Also:
setStyle(byte), Constant Field Values

STYLE_PACKED_CIRCLE

public static final byte STYLE_PACKED_CIRCLE
Style specification constant describing a component arrangement strategy that tries to place components like in a cloud around the biggest component. Entities of different components will not overlap, however the bounding boxes of the components may overlap.

See Also:
setStyle(byte), Constant Field Values

STYLE_PACKED_COMPACT_CIRCLE

public static final byte STYLE_PACKED_COMPACT_CIRCLE
Style specification constant describing a component arrangement strategy that tries to place components like in a cloud around the biggest component. Entities of different components will not overlap, however the bounding boxes of the components may overlap. In contrast to STYLE_PACKED_CIRCLE components might even be placed in empty spaces inside other components.

See Also:
setStyle(byte), Constant Field Values

STYLE_MASK

public static final byte STYLE_MASK
Use this constant for masking actual styles constants from style modifiers.

See Also:
setStyle(byte), Constant Field Values

STYLE_MODIFIER_AS_IS

public static final byte STYLE_MODIFIER_AS_IS
Modifier constant that can be added to normal style constants to indicate that the arrangement strategy should take the initial positions of the components into account.
Combining this modifier is supported with the following styles: STYLE_SINGLE_ROW, STYLE_SINGLE_COLUMN, STYLE_PACKED_RECTANGLE, STYLE_PACKED_COMPACT_RECTANGLE, STYLE_PACKED_CIRCLE, and STYLE_PACKED_COMPACT_CIRCLE.

See Also:
setStyle(byte), Constant Field Values

STYLE_MODIFIER_NO_OVERLAP

public static final byte STYLE_MODIFIER_NO_OVERLAP
Modifier constant that can be added to normal style constants to indicate that the arrangement strategy should produce a non-overlapping component layout.
Combining this modifier is supported with STYLE_NONE.

Note that non-overlapping component layout (in the sense that no elements from adjacent components overlap) is inherently supported by the following styles: STYLE_PACKED_RECTANGLE, STYLE_PACKED_COMPACT_RECTANGLE, STYLE_PACKED_CIRCLE, and STYLE_PACKED_COMPACT_CIRCLE.

See Also:
setStyle(byte), Constant Field Values
Constructor Detail

ComponentLayouter

public ComponentLayouter(Layouter coreLayouter)
Initializes a new ComponentLayouter instance.

Parameters:
coreLayouter - the layout algorithm that is invoked for connected components of the input graph.
See Also:
doLayout(LayoutGraph)

ComponentLayouter

public ComponentLayouter()
Initializes a new ComponentLayouter instance.

See Also:
setPreferredLayoutSize(double, double)
Method Detail

setPreferredLayoutSize

public void setPreferredLayoutSize(double width,
                                   double height)
Sets the preferred layout size for this layouter.

Parameters:
width - the preferred width of the calculated graph layout.
height - the preferred height of the calculated graph layout.
See Also:
getPreferredLayoutSize()

getPreferredLayoutSize

public YDimension getPreferredLayoutSize()
Gets the preferred layout size for this layouter.

Returns:
the preferred size of the calculated graph layout.
See Also:
setPreferredLayoutSize(double, double)

canLayout

public boolean canLayout(LayoutGraph graph)
Determines if the preconditions for the graph layout algorithm are fulfilled, by applying them to the connected components.


findGraphComponents

protected int findGraphComponents(LayoutGraph graph,
                                  NodeMap compNumber)
Determines which nodes will belong to the same graph component. Additionally to normal connectedness a group node and all of its children will belong to the same component.

Parameters:
graph - the input graph
compNumber - return value that will hold the zero-based number of the component that it belongs to. The component number of Node v is compNum.getInt(v).
Returns:
the number of connected components of this graph.

doLayout

public void doLayout(LayoutGraph graph)
Calculate the layout. This is done by decomposing the graph in its connected components and applying the core layout algorithm on each component.

See Also:
AbstractLayoutStage.getCoreLayouter(), ComponentLayouter(Layouter)

calcBoundingBox

protected Rectangle2D calcBoundingBox(LayoutGraph graph)
Calculates and returns the bounding box of a graph component. This method will be invoked for each component of the graph. Depending on the state of property labelAwarenessEnabled the returned bounding box will also take node and edge labels into account.


setLabelAwarenessEnabled

public 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.

By default this feature is enabled.

Parameters:
enabled - if true node and edge labels are taken into account when calculating the bounding box of the graph components.
See Also:
calcBoundingBox(LayoutGraph graph), isLabelAwarenessEnabled()

isLabelAwarenessEnabled

public boolean isLabelAwarenessEnabled()
Determines whether or not to take node and edge labels into account when calculating the bounding box of the graph components.

By default this feature is enabled.

Returns:
true if node and edge labels are taken into account when calculating the bounding box of the graph components; false otherwise.
See Also:
setLabelAwarenessEnabled(boolean)

arrangeComponents

protected void arrangeComponents(LayoutGraph graph,
                                 NodeList[] nodes,
                                 EdgeList[] edges,
                                 YRectangle[] bbox,
                                 Rectangle2D[] boxes)
Produces a non-overlapping component graph layout. This method moves the graph components in such a fashion that their bounding boxes do not overlap. The arrangement strategy used is takes the ratio of the overall layout area into account.

Subclasses may want to overwrite this method.

Parameters:
graph - the layout graph.
nodes - array of type NodeList. The i-th NodeList contains all nodes of the i-th graph component.
edges - array of type EdgeList. The i-th NodeList contains all edges of the i-th graph component.
bbox - array of type YRectangle. The i-th YRectangle contains the current bounding box of the i-th graph component.
boxes - array of type Rectangle2D. The i-th Rectangle2D contains the extended bounding box of the i-th graph component. The method arrange these boxes in such a way that they do not overlap. Then the i-th graph component must be placed inside the i-th box.

setComponentArrangementEnabled

public void setComponentArrangementEnabled(boolean enabled)
Sets whether or not the separately laid out components of the input graph should be arranged by this class.

By default this feature is enabled.

Parameters:
enabled - if true separately laid out components of the input graph are arranged by this class.
See Also:
isComponentArrangementEnabled()

isComponentArrangementEnabled

public boolean isComponentArrangementEnabled()
Returns whether or not the separately laid out components of the input graph should be arranged by this class.

By default this feature is enabled.

Returns:
true if separately laid out components of the input graph are arranged by this class; false otherwise.
See Also:
setComponentArrangementEnabled(boolean)

setOrigin

protected void setOrigin(LayoutGraph graph,
                         NodeList nl,
                         EdgeList el,
                         YPoint org,
                         YRectangle r)
Sets the origin for a subgraph.


getGridSpacing

public double getGridSpacing()
Returns the current grid spacing. If this value is set to a value greater than 0, components will be moved by multiples of this value. This assures, that laid out subcomponents, which adhere to a known grid, will stay on their grid.

Returns:
the current grid spacing.

setGridSpacing

public void setGridSpacing(double gridSpacing)
Specifies the current grid spacing. If this value is set to a value greater than 0, components will be moved by multiples of this value. This assures, that laid out subcomponents, which adhere to a known grid, will stay on their grid.

Parameters:
gridSpacing - the current grid spacing.

getComponentSpacing

public double getComponentSpacing()
Returns the current component spacing. This value represents the minimum allowed distance between the bounding boxes of to components.

Returns:
the current component spacing.

setComponentSpacing

public void setComponentSpacing(double componentSpacing)
Specifies the current component spacing. This value represents the minimum allowed distance between the bounding boxes of to components.

Parameters:
componentSpacing - the current component spacing.

isGroupingActive

public boolean isGroupingActive()
Determines whether or not grouping information bound to the graph will be used to calculate the components.

The default value is true.

Returns:
true if the nesting structure of the graph is taken into account when determining connectedness; false otherwise.
See Also:
setGroupingActive(boolean)

setGroupingActive

public void setGroupingActive(boolean groupingActive)
Specifies whether or not grouping information bound to the graph should be used to determine the connectedness of the graph structure.

The default value is true.

Parameters:
groupingActive - if true the nesting structure of the graph is taken into account when determining connectedness.
See Also:
isGroupingActive()

getStyle

public byte getStyle()
Returns the component arrangement style used by this ComponentLayouter.

The default is STYLE_ROWS.

Returns:
the current style constant. Use STYLE_MASK to mask out the basic style without the modifier bits.
See Also:
setStyle(byte)

setStyle

public void setStyle(byte style)
Sets the component arrangement style used by this ComponentLayouter.

The default is STYLE_ROWS.

Parameters:
style - New value of property style. One of STYLE_NONE, STYLE_ROWS, STYLE_SINGLE_ROW, STYLE_SINGLE_COLUMN, STYLE_PACKED_RECTANGLE, STYLE_PACKED_COMPACT_RECTANGLE, STYLE_PACKED_CIRCLE, or STYLE_PACKED_COMPACT_CIRCLE, possibly bitwise combined using STYLE_MODIFIER_AS_IS and/or STYLE_MODIFIER_NO_OVERLAP.

arrangeFields

protected void arrangeFields(LayoutGraph graph,
                             NodeList[] nodes,
                             EdgeList[] edges,
                             YRectangle[] bbox,
                             Rectangle2D[] boxes,
                             boolean circular,
                             boolean fill,
                             boolean fromSketch)

© Copyright 2000-2013,
yWorks GmbH.
All rights reserved.