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.

 
Your browser does not support SVG content.

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 the normal style constant 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 the normal style constant 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 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 rows.
 
Fields inherited from interface y.layout.Layouter
EDGE_ID_DPKEY, NODE_ID_DPKEY, SELECTED_EDGES, SELECTED_NODES
 
Constructor Summary
ComponentLayouter()
          Instantiates a ComponentLayouter.
ComponentLayouter(Layouter coreLayouter)
          Instantiates a ComponentLayouter.
 
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()
          Getter for property componentSpacing.
 double getGridSpacing()
          Getter for property gridSpacing.
 YDimension getPreferredLayoutSize()
          Gets the preferred layout size for this layouter.
 byte getStyle()
          Returns the current style of the component arrangement.
 boolean isComponentArrangementEnabled()
          Returns whether or not the separately laid out components of the input graph should be arranged by this class.
 boolean isGroupingActive()
          Returns whether grouping information bound to the graph will be used to calculate the 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)
          Sets whether or not the separately laid out components of the input graph should be arranged by this class.
 void setComponentSpacing(double componentSpacing)
          Setter for property componentSpacing.
 void setGridSpacing(double gridSpacing)
          Setter for property gridSpacing.
 void setGroupingActive(boolean groupingActive)
          Determines whether grouping information bound to the graph should be used to determine the connectedness of the graph structure.
 void setLabelAwarenessEnabled(boolean enabled)
          Sets 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 style of the component arrangement for this instance.
 
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:
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 ratio of the preferred layout size as possible.

See Also:
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 rows. 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:
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:
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:
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:
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:
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:
Constant Field Values

STYLE_MODIFIER_AS_IS

public static final byte STYLE_MODIFIER_AS_IS
Modifier constant that can be added to the normal style constant to indicate that the arrangement strategy should take the initial positions of the components into account.

See Also:
Constant Field Values

STYLE_MASK

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

See Also:
Constant Field Values

STYLE_MODIFIER_NO_OVERLAP

public static final byte STYLE_MODIFIER_NO_OVERLAP
Modifier constant that can be added to the normal style constant to indicate that the arrangement strategy should produce a non-overlapping component layout.

See Also:
Constant Field Values
Constructor Detail

ComponentLayouter

public ComponentLayouter(Layouter coreLayouter)
Instantiates a ComponentLayouter. Sets the layouter which is invoked for the connected components.


ComponentLayouter

public ComponentLayouter()
Instantiates a ComponentLayouter.

Method Detail

setPreferredLayoutSize

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


getPreferredLayoutSize

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


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 layout algorithm on them.


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)
Sets 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 disabled.

See Also:
calcBoundingBox(LayoutGraph graph)

isLabelAwarenessEnabled

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


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.


isComponentArrangementEnabled

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


setOrigin

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


getGridSpacing

public double getGridSpacing()
Getter for property gridSpacing. 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:
Value of property gridSpacing.

setGridSpacing

public void setGridSpacing(double gridSpacing)
Setter for property gridSpacing. 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 - New value of property gridSpacing.

getComponentSpacing

public double getComponentSpacing()
Getter for property componentSpacing. This value represents the minimum allowed distance between the bounding boxes of to components.

Returns:
Value of property componentSpacing.

setComponentSpacing

public void setComponentSpacing(double componentSpacing)
Setter for property componentSpacing. This value represents the minimum allowed distance between the bounding boxes of to components.

Parameters:
componentSpacing - New value of property componentSpacing.

isGroupingActive

public boolean isGroupingActive()
Returns whether grouping information bound to the graph will be used to calculate the components. Default is true.


setGroupingActive

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


getStyle

public byte getStyle()
Returns the current style of the component arrangement. 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 style of the component arrangement for this instance. 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-2008,
yWorks GmbH.
All rights reserved.