y.layout.transformer
Class GraphTransformer

java.lang.Object
  |
  +--y.layout.CanonicMultiStageLayouter
        |
        +--y.layout.transformer.GraphTransformer
All Implemented Interfaces:
Layouter, LayoutStage

public class GraphTransformer
extends CanonicMultiStageLayouter
implements LayoutStage

Provides geometric transforms for (sub-)graphs. This module provides the following kinds of geometric transforms on graphs or subgraphs.

Here is an sample output of the layouter that rotated the inner nine nodes of the grid by 45 degrees.


Field Summary
static int MIRROR_XAXIS
          Operation type constant.
static int MIRROR_YAXIS
          Operation type constant.
static int ROTATE
          Operation type constant.
static int SCALE
          Operation type constant.
 
Fields inherited from interface y.layout.Layouter
EDGE_ID_DPKEY, NODE_ID_DPKEY, SELECTED_EDGES, SELECTED_NODES
 
Constructor Summary
GraphTransformer()
          Creates a new instance of graph transformer.
 
Method Summary
static double applyBestFitRotationAngle(LayoutGraph graph, double width, double height)
          Performs a rotation of the given graph such that its resulting bounding box (approximately) fits best to the given area bounds.
 boolean canLayoutCore(LayoutGraph graph)
          Returns always true.
 void doLayoutCore(LayoutGraph graph)
          Performs the selected transformation.
static double findBestFitRotationAngle(LayoutGraph graph, double width, double height)
          Returns a rotation angle that, if applied to the given graph, would minimize the zoom-level needed to display the graph in an area of the given dimension.
 Layouter getCoreLayouter()
          Returns the core layouter.
 int getOperation()
          Returns the transformation operation this layouter performs.
 double getRotationAngle()
          Returns the angle of rotation.
 double getScaleFactorX()
          Returns the scaling factor used for the x-coordinate.
 double getScaleFactorY()
          Returns the scaling factor used for the y-coordinate.
 boolean getScaleNodeSize()
          Returns whether or not to scale node sizes.
 boolean isBestFitRotationEnabled()
          Returns whether or not the best fit roatiopn angle will be applied.
static double[] scaleToRect(LayoutGraph g, Rectangle rect)
          Scales the coordinates of the given graph in such a way that the resulting bounding box of the graph approximately equals the bounds of the given rectangle.
 void setBestFitRotationEnabled(boolean enabled)
          Set whether or not to choose a best fit rotation angle instead of the one set by GraphTransformer.setRotationAngle(double).
 void setCoreLayouter(Layouter coreLayouter)
          Sets the core layouter.
 void setOperation(int operation)
          Sets the transformation operation this layouter performs.
 void setPreferedLayoutSize(double width, double height)
          Sets the preferred layout size for this layouter.
 void setRotationAngle(double angle)
          Sets the angle of rotation.
 void setScaleFactor(double f)
          Sets the uniform scaling factor used for the SCALE operation.
 void setScaleFactors(double xFactor, double yFactor)
          Sets the scaling factors for the x-coordinates and y-coordinates used for the SCALE operation.
 void setScaleNodeSize(boolean s)
          Whether or not to scale node sizes when performing the SCALE operation.
static void translate(LayoutGraph g, double dx, double dy)
          Translates the layout coordinates by the vector (dx,dy).
 
Methods inherited from class y.layout.CanonicMultiStageLayouter
appendStage, calcLayout, calcLayout, canLayout, doLayout, doLayout, enableOnlyCore, getComponentLayouter, getGroupNodeHider, getLabelLayouter, getLayoutOrientation, getOrientationLayouter, getParallelEdgeLayouter, getSelfLoopLayouter, getSubgraphLayouter, isComponentLayouterEnabled, isGroupNodeHidingEnabled, isLabelLayouterEnabled, isOrientationLayouterEnabled, isParallelEdgeLayouterEnabled, isSelfLoopLayouterEnabled, isSubgraphLayouterEnabled, prependStage, removeStage, setComponentLayouter, setComponentLayouterEnabled, setGroupNodeHider, setGroupNodeHidingEnabled, setLabelLayouter, setLabelLayouterEnabled, setLayoutOrientation, setOrientationLayouter, setOrientationLayouterEnabled, setParallelEdgeLayouter, setParallelEdgeLayouterEnabled, setSelfLoopLayouter, setSelfLoopLayouterEnabled, setSubgraphLayouter, setSubgraphLayouterEnabled
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface y.layout.Layouter
canLayout, doLayout
 

Field Detail

MIRROR_XAXIS

public static final int MIRROR_XAXIS
Operation type constant. Specifies that the graph should be mirrored along the x-axis.

See Also:
Constant Field Values

MIRROR_YAXIS

public static final int MIRROR_YAXIS
Operation type constant. Specifies that the graph should be mirrored along the y-axis.

See Also:
Constant Field Values

ROTATE

public static final int ROTATE
Operation type constant. Specifies that the graph should be rotated.

See Also:
Constant Field Values

SCALE

public static final int SCALE
Operation type constant. Specifies that the graph should be scaled.

See Also:
Constant Field Values
Constructor Detail

GraphTransformer

public GraphTransformer()
Creates a new instance of graph transformer.

Method Detail

setCoreLayouter

public void setCoreLayouter(Layouter coreLayouter)
Description copied from interface: LayoutStage
Sets the core layouter.

Specified by:
setCoreLayouter in interface LayoutStage

getCoreLayouter

public Layouter getCoreLayouter()
Description copied from interface: LayoutStage
Returns the core layouter.

Specified by:
getCoreLayouter in interface LayoutStage

setOperation

public void setOperation(int operation)
Sets the transformation operation this layouter performs.

By default the SCALE operation is set.

See Also:
GraphTransformer.MIRROR_XAXIS, GraphTransformer.MIRROR_YAXIS, GraphTransformer.ROTATE, GraphTransformer.SCALE

getOperation

public int getOperation()
Returns the transformation operation this layouter performs.


setRotationAngle

public void setRotationAngle(double angle)
Sets the angle of rotation. The angle must be given in degrees. This feature is only meningful for the ROTATE operation.

By default the rotation angle is 0.0.


getRotationAngle

public double getRotationAngle()
Returns the angle of rotation.


setBestFitRotationEnabled

public void setBestFitRotationEnabled(boolean enabled)
Set whether or not to choose a best fit rotation angle instead of the one set by GraphTransformer.setRotationAngle(double). Also, to apply the best fit rotation angle, the operation type of this layouter must be set to GraphTransformer.ROTATE.

Use GraphTransformer.setPreferedLayoutSize(double, double) to specify the preferred aspect ratio of the resulting layout.


isBestFitRotationEnabled

public boolean isBestFitRotationEnabled()
Returns whether or not the best fit roatiopn angle will be applied.

See Also:
GraphTransformer.setBestFitRotationEnabled(boolean)

setPreferedLayoutSize

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


setScaleNodeSize

public void setScaleNodeSize(boolean s)
Whether or not to scale node sizes when performing the SCALE operation.

By default this feature is disabled.


getScaleNodeSize

public boolean getScaleNodeSize()
Returns whether or not to scale node sizes.


setScaleFactor

public void setScaleFactor(double f)
Sets the uniform scaling factor used for the SCALE operation.

By default the scaling factor is set to 1.0


setScaleFactors

public void setScaleFactors(double xFactor,
                            double yFactor)
Sets the scaling factors for the x-coordinates and y-coordinates used for the SCALE operation.

By default the scaling factors are set to 1.0


getScaleFactorY

public double getScaleFactorY()
Returns the scaling factor used for the y-coordinate.


getScaleFactorX

public double getScaleFactorX()
Returns the scaling factor used for the x-coordinate.


canLayoutCore

public boolean canLayoutCore(LayoutGraph graph)
Returns always true.

Specified by:
canLayoutCore in class CanonicMultiStageLayouter

doLayoutCore

public void doLayoutCore(LayoutGraph graph)
Performs the selected transformation.

Specified by:
doLayoutCore in class CanonicMultiStageLayouter

applyBestFitRotationAngle

public static double applyBestFitRotationAngle(LayoutGraph graph,
                                               double width,
                                               double height)
Performs a rotation of the given graph such that its resulting bounding box (approximately) fits best to the given area bounds.


findBestFitRotationAngle

public static double findBestFitRotationAngle(LayoutGraph graph,
                                              double width,
                                              double height)
Returns a rotation angle that, if applied to the given graph, would minimize the zoom-level needed to display the graph in an area of the given dimension.


scaleToRect

public static double[] scaleToRect(LayoutGraph g,
                                   Rectangle rect)
Scales the coordinates of the given graph in such a way that the resulting bounding box of the graph approximately equals the bounds of the given rectangle. Note that this operation won't have any effects, if there is only one node in the graph or if there are nodes that are bigger than the requested bounding box size.

The x- and y-scaling factors are returned in a double array of size 2. The first value of the array is the x-scaling factor that has was used and the second value is the y-scaling factor.


translate

public static void translate(LayoutGraph g,
                             double dx,
                             double dy)
Translates the layout coordinates by the vector (dx,dy).


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

2003