Search this API

y.layout.transformer
Class GraphTransformer

java.lang.Object
  extended by y.layout.CanonicMultiStageLayouter
      extended by 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.
static int TRANSLATE
          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.
 double getTranslateX()
          Returns the horizontal translation distance.
 double getTranslateY()
          Returns the vertical translation distance.
 boolean isBestFitRotationEnabled()
          Returns whether or not the best fit rotation 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 setRotationAngle(double).
 void setCoreLayouter(Layouter coreLayouter)
          Sets the core layouter.
static void setMaximalBounds(LayoutGraph graph, double x, double y, double w, double h)
          Assures that the given graph fits into the given rectangular bounds.
 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)
          Specifies whether or not to scale node sizes when performing the SCALE operation.
 void setTranslateX(double dx)
          Specifies the horizontal translation distance.
 void setTranslateY(double dy)
          Specifies the vertical translation distance.
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, checkGroupNodeSize, checkNodeSize, 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:
getOperation(), setOperation(int), 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:
getOperation(), setOperation(int), Constant Field Values

ROTATE

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

See Also:
getOperation(), setOperation(int), Constant Field Values

SCALE

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

See Also:
getOperation(), setOperation(int), Constant Field Values

TRANSLATE

public static final int TRANSLATE
Operation type constant. Specifies that the graph should be translated.

See Also:
getOperation(), setOperation(int), 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:
MIRROR_XAXIS, MIRROR_YAXIS, ROTATE, SCALE, TRANSLATE

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 meaningful 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 setRotationAngle(double). Also, to apply the best fit rotation angle, the operation type of this layouter must be set to ROTATE.

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


isBestFitRotationEnabled

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

See Also:
setBestFitRotationEnabled(boolean)

setPreferedLayoutSize

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


setScaleNodeSize

public void setScaleNodeSize(boolean s)
Specifies 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.


getTranslateX

public double getTranslateX()
Returns the horizontal translation distance. A positive value means the graph is moved to the right; a negative value means the graph is moved to the left. Defaults to 0.

Returns:
the translation distance along the x-axis.
See Also:
setTranslateX(double), setTranslateY(double), getTranslateY(), TRANSLATE, setOperation(int)

setTranslateX

public void setTranslateX(double dx)
Specifies the horizontal translation distance.

Parameters:
dx - the translation distance along the x-axis. A positive value means the graph is moved to the right; a negative value means the graph is moved to the left.
See Also:
getTranslateX(), setTranslateY(double), getTranslateY(), TRANSLATE, setOperation(int)

getTranslateY

public double getTranslateY()
Returns the vertical translation distance. A positive value means the graph is moved downwards; a negative value means the graph is moved upwards. Defaults to 0.

Returns:
the translation distance along the y-axis.
See Also:
setTranslateY(double), setTranslateX(double), getTranslateX(), TRANSLATE, setOperation(int)

setTranslateY

public void setTranslateY(double dy)
Specifies the vertical translation distance.

Parameters:
dy - the translation distance along the y-axis. A positive value means the graph is moved downwards; a negative value means the graph is moved upwards.
See Also:
getTranslateY(), setTranslateX(double), getTranslateX(), TRANSLATE, setOperation(int)

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.


setMaximalBounds

public static void setMaximalBounds(LayoutGraph graph,
                                    double x,
                                    double y,
                                    double w,
                                    double h)
Assures that the given graph fits into the given rectangular bounds. If the bounding box fits in the rectangle, nothing is done. Otherwise the graph is scaled and optionally moved to fit. This algorithm does not modify the node's sizes. Note that this operation won't have any effects, if there are nodes that are bigger than the requested bounding box size.

Parameters:
graph - the graph to modify
x - the upper left x coordinate of the bounds
y - the upper left y coordinate of the bounds
w - the width of the bounds
h - the height of the bounds

translate

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


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