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

This layout algorithm applies geometric transformations to (sub-)graphs.

Layout Style

There are several ways to transform the graph that include mirroring, rotating, scaling and translating.


The highlighted subgraph is rotated by 45 degrees

Features

The layout can be scaled with independent factors for the horizontal and vertical scaling. Optionally, the sizes of nodes can be scaled, too.

The layout can be mirrored either on the x-axis or the y-axis.

A rotation can be specified. Instead of defining a rotation angle the angle can be determined automatically to fit specific bounds.

The coordinates in the layout can be translated by a specific vector.

To only apply previously mentioned transformations to a subgraph, the SubgraphLayouter needs to be enabled. Then the nodes in the subgraph must be marked in a DataProvider registered with the according key.

 
Labels are not affected by the transformation. They will stay at the location that is defined by their label model.
 

Field Summary
static int MIRROR_XAXIS
          Operation specifier defining that the graph will be mirrored at the x-axis.
static int MIRROR_YAXIS
          Operation specifier defining that the graph will be mirrored at the y-axis.
static int ROTATE
          Operation specifier defining that the graph will be rotated.
static int SCALE
          Operation specifier defining that the graph will be scaled.
static int TRANSLATE
          Operation specifier defining that the graph will be translated.
 
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 GraphTransformer with default settings.
 
Method Summary
static double applyBestFitRotationAngle(LayoutGraph graph, double width, double height)
          Rotates the given graph so its resulting bounding box fits best to the given bounds.
 boolean canLayoutCore(LayoutGraph graph)
          Accepts all general graphs.
 void doLayoutCore(LayoutGraph graph)
          Applies the selected transformation to the given graph after invoking the optional core layout algorithm.
static double findBestFitRotationAngle(LayoutGraph graph, double width, double height)
          Returns the rotation angle for the graph that will result in a layout that fits best to the given bounds.
 Layouter getCoreLayouter()
          Returns the core layout algorithm.
 int getOperation()
          Returns the transformation operation.
 double getPreferredHeight()
          Returns the preferred height of the layout.
 double getPreferredWidth()
          Returns the preferred width of the layout.
 double getRotationAngle()
          Returns the angle of rotation.
 double getScaleFactorX()
          Returns the horizontal scaling factor used for the scale operation.
 double getScaleFactorY()
          Returns the vertical scaling factor used for the scale operation.
 boolean getScaleNodeSize()
          Returns whether or not to also scale node sizes when performing the scale operation.
 double getTranslateX()
          Returns the horizontal translation distance.
 double getTranslateY()
          Returns the vertical translation distance.
 boolean isBestFitRotationEnabled()
          Returns whether or not to automatically choose the best fitting rotation angle.
static double[] scaleToRect(LayoutGraph graph, java.awt.Rectangle rect)
          Scales the given graph so its resulting bounding box is (approximately) the same as the given rectangular bounds.
 void setBestFitRotationEnabled(boolean enabled)
          Specifies whether or not to automatically choose the best fitting rotation angle.
 void setCoreLayouter(Layouter coreLayouter)
          Specifies the core layout algorithm.
static void setMaximalBounds(LayoutGraph graph, double x, double y, double w, double h)
          Fits the given graph into the specified rectangular bounds.
 void setOperation(int operation)
          Specifies the transformation operation.
 void setPreferedLayoutSize(double width, double height)
          Specifies the preferred size of the layout.
 void setPreferredHeight(double preferredHeight)
          Specifies the preferred height of the layout.
 void setPreferredWidth(double preferredWidth)
          Specifies the preferred width of the layout.
 void setRotationAngle(double angle)
          Specifies the angle of rotation.
 void setScaleFactor(double f)
          Specifies the uniform scaling factor used for the scale operation.
 void setScaleFactors(double xFactor, double yFactor)
          Specifies the horizontal and vertical scaling factor used for the scale operation.
 void setScaleFactorX(double scaleFactorX)
          Specifies the horizontal scaling factor used for the scale operation.
 void setScaleFactorY(double scaleFactorY)
          Specifies the vertical scaling factor used for the scale operation.
 void setScaleNodeSize(boolean s)
          Specifies whether or not to also 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 graph, double dx, double dy)
          Translates the layout coordinates by the given vector.
 
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 specifier defining that the graph will be mirrored at the x-axis.

See Also:
setOperation(int), Constant Field Values

MIRROR_YAXIS

public static final int MIRROR_YAXIS
Operation specifier defining that the graph will be mirrored at the y-axis.

See Also:
setOperation(int), Constant Field Values

ROTATE

public static final int ROTATE
Operation specifier defining that the graph will be rotated.

See Also:
setOperation(int), setRotationAngle(double), setBestFitRotationEnabled(boolean), Constant Field Values

SCALE

public static final int SCALE
Operation specifier defining that the graph will be scaled.

See Also:
setOperation(int), setScaleFactor(double), setScaleFactors(double, double), setScaleNodeSize(boolean), Constant Field Values

TRANSLATE

public static final int TRANSLATE
Operation specifier defining that the graph will be translated.

See Also:
setOperation(int), setTranslateX(double), setTranslateY(double), Constant Field Values
Constructor Detail

GraphTransformer

public GraphTransformer()
Creates a new instance of GraphTransformer with default settings.

Method Detail

setCoreLayouter

public void setCoreLayouter(Layouter coreLayouter)
Description copied from interface: LayoutStage
Specifies the core layout algorithm. This algorithm is wrapped by this stage. It is invoked in Layouter.doLayout(LayoutGraph). The LayoutStage may add pre- and post-processing steps before and after calling the core layout algorithm.

Specified by:
setCoreLayouter in interface LayoutStage
Parameters:
coreLayouter - the core layout algorithm

getCoreLayouter

public Layouter getCoreLayouter()
Description copied from interface: LayoutStage
Returns the core layout algorithm. This algorithm is wrapped by this stage. It is invoked in Layouter.doLayout(LayoutGraph). The LayoutStage may add pre- and post-processing steps before and after calling the core layout algorithm.

Specified by:
getCoreLayouter in interface LayoutStage
Returns:
the core layout algorithm

setOperation

public void setOperation(int operation)
Specifies the transformation operation.

Default Value:
The default value is SCALE
Parameters:
operation - one of the valid operation specifiers
Throws:
java.lang.IllegalArgumentException - if the specified operation is unknown

getOperation

public int getOperation()
Returns the transformation operation.

Returns:
one of the valid operation specifiers
See Also:
setOperation(int)

setRotationAngle

public void setRotationAngle(double angle)
Specifies the angle of rotation.

The angle must be given in degrees.

 
This option only has an effect if the layout is rotated.
Default Value:
The default value is 0.0.
Parameters:
angle - the rotation angle in degrees
See Also:
setOperation(int), ROTATE

getRotationAngle

public double getRotationAngle()
Returns the angle of rotation.

The angle must be given in degrees.

 
This option only has an effect if the layout is rotated.
Returns:
the rotation angle in degrees
See Also:
setRotationAngle(double), setOperation(int), ROTATE

setBestFitRotationEnabled

public void setBestFitRotationEnabled(boolean enabled)
Specifies whether or not to automatically choose the best fitting rotation angle.

The angle will be chosen such that the bounding box after the rotation fits best to the preferred aspect ratio.

 
This option only has an effect if the layout is rotated.
Default Value:
The default value is false. The layout is rotated by a specific angle.
Parameters:
enabled - true if the best fitting rotation angle is automatically determined, false if the specified angle is used
See Also:
setOperation(int), ROTATE

isBestFitRotationEnabled

public boolean isBestFitRotationEnabled()
Returns whether or not to automatically choose the best fitting rotation angle.

The angle will be chosen such that the bounding box after the rotation fits best to the preferred aspect ratio.

 
This option only has an effect if the layout is rotated.
Returns:
true if the best fitting rotation angle should be automatically determined, false if the specified angle should be used
See Also:
setBestFitRotationEnabled(boolean), setOperation(int), ROTATE

setPreferedLayoutSize

public void setPreferedLayoutSize(double width,
                                  double height)
Specifies the preferred size of the layout.

If performing a rotation and this rotation should be automatically fitted, then the given preferred size defines the aspect ratio that will be used for fitting the layout rotation.

The preferred width and height need to be non-negative.

 
This option only has an effect if the rotation is fitted to the bounds.
Parameters:
width - the preferred width of the layout
height - the preferred height of the layout
Throws:
java.lang.IllegalArgumentException - if the specified width or height is negative
See Also:
setPreferredWidth(double), setPreferredHeight(double), setBestFitRotationEnabled(boolean), setOperation(int), ROTATE

getPreferredHeight

public double getPreferredHeight()
Returns the preferred height of the layout.

This value will be used for fitting the rotation to preferred bounds.

The preferred height needs to be non-negative.

 
This option only has an effect if performing a rotation and the rotation is fitted to the bounds.
Returns:
the preferred height of the layout
See Also:
setPreferredHeight(double), getPreferredWidth(), setBestFitRotationEnabled(boolean), setOperation(int), ROTATE

setPreferredHeight

public void setPreferredHeight(double preferredHeight)
Specifies the preferred height of the layout.

This value will be used for fitting the rotation to preferred bounds.

The preferred height needs to be non-negative.

 
This option only has an effect if performing a rotation and the rotation is fitted to the bounds.
Default Value:
The default value is 1.0.
Parameters:
preferredHeight - the preferred height of the layout
Throws:
java.lang.IllegalArgumentException - if the specified height is negative
See Also:
setPreferredWidth(double), setBestFitRotationEnabled(boolean), setOperation(int), ROTATE

getPreferredWidth

public double getPreferredWidth()
Returns the preferred width of the layout.

This value will be used for fitting the rotation to preferred bounds.

The preferred width needs to be non-negative.

 
This option only has an effect if performing a rotation and the rotation is fitted to the bounds.
Returns:
the preferred width of the layout
See Also:
setPreferredWidth(double), getPreferredHeight(), setBestFitRotationEnabled(boolean), setOperation(int), ROTATE

setPreferredWidth

public void setPreferredWidth(double preferredWidth)
Specifies the preferred width of the layout.

This value will be used for fitting the rotation to preferred bounds.

The preferred width needs to be non-negative.

 
This option only has an effect if performing a rotation and the rotation is fitted to the bounds.
Default Value:
The default value is 1.41.
Parameters:
preferredWidth - the preferred width of the layout
Throws:
java.lang.IllegalArgumentException - if the specified width is negative
See Also:
setPreferredHeight(double), setBestFitRotationEnabled(boolean), setOperation(int), ROTATE

setScaleNodeSize

public void setScaleNodeSize(boolean s)
Specifies whether or not to also scale node sizes when performing the scale operation.

 
This option only has an effect if the layout is scaled.
Default Value:
The default value is false. Nodes keep their sizes when the layout is scaled.
Parameters:
s - true if the sizes of the nodes should also be scaled, false otherwise
See Also:
setOperation(int), SCALE

getScaleNodeSize

public boolean getScaleNodeSize()
Returns whether or not to also scale node sizes when performing the scale operation.

 
This option only has an effect if the layout is scaled.
Returns:
true if the sizes of the nodes are also scaled, false otherwise
See Also:
setScaleNodeSize(boolean), setOperation(int), SCALE

setScaleFactor

public void setScaleFactor(double f)
Specifies the uniform scaling factor used for the scale operation. This factor applies vertical and horizontal.

Only positive scaling factors are allowed.

 
This option only has an effect if the layout is scaled.
Parameters:
f - the scaling factor
Throws:
java.lang.IllegalArgumentException - if the specified scaling factor is negative or 0
See Also:
setScaleFactorX(double), setScaleFactorY(double), setOperation(int), SCALE

setScaleFactors

public void setScaleFactors(double xFactor,
                            double yFactor)
Specifies the horizontal and vertical scaling factor used for the scale operation.

Only positive scaling factors are allowed.

 
This option only has an effect if the layout is scaled.
Parameters:
xFactor - the horizontal scaling factor
yFactor - the vertical scaling factor
Throws:
java.lang.IllegalArgumentException - if one the specified scaling factors is negative or 0
See Also:
setScaleFactorX(double), setScaleFactorY(double), setOperation(int), SCALE

getScaleFactorY

public double getScaleFactorY()
Returns the vertical scaling factor used for the scale operation.

Only positive scaling factors are allowed.

 
This option only has an effect if the layout is scaled.
Returns:
the vertical scaling factor
See Also:
setScaleFactorY(double), getScaleFactorX(), setOperation(int), SCALE

setScaleFactorY

public void setScaleFactorY(double scaleFactorY)
Specifies the vertical scaling factor used for the scale operation.

Only positive scaling factors are allowed.

 
This option only has an effect if the layout is scaled.
Default Value:
The default value is 1.0.
Parameters:
scaleFactorY - the vertical scaling factor
Throws:
java.lang.IllegalArgumentException - if the specified scaling factor is negative or 0
See Also:
setScaleFactorX(double), setOperation(int), SCALE

getScaleFactorX

public double getScaleFactorX()
Returns the horizontal scaling factor used for the scale operation.

Only positive scaling factors are allowed.

 
This option only has an effect if the layout is scaled.
Returns:
the horizontal scaling factor
See Also:
setScaleFactorX(double), getScaleFactorY(), setOperation(int), SCALE

setScaleFactorX

public void setScaleFactorX(double scaleFactorX)
Specifies the horizontal scaling factor used for the scale operation.

Only positive scaling factors are allowed.

 
This option only has an effect if the layout is scaled.
Default Value:
The default value is 1.0.
Parameters:
scaleFactorX - the horizontal scaling factor
Throws:
java.lang.IllegalArgumentException - if the specified scaling factor is negative or 0
See Also:
setScaleFactorY(double), setOperation(int), SCALE

getTranslateX

public double getTranslateX()
Returns the horizontal translation distance.

A positive value means the graph is moved to the right, while a negative value means the graph is moved to the left.

 
This option only has an effect if the layout is translated.
Returns:
the translation distance along the x-axis
See Also:
setTranslateX(double), getTranslateY(), setOperation(int), TRANSLATE

setTranslateX

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

A positive value means the graph is moved to the right while, a negative value means the graph is moved to the left.

 
This option only has an effect if the layout is translated.
Default Value:
The default value is 0.0.
Parameters:
dx - the translation distance along the x-axis
See Also:
setTranslateY(double), setOperation(int), TRANSLATE

getTranslateY

public double getTranslateY()
Returns the vertical translation distance.

A positive value means the graph is moved downwards, while a negative value means the graph is moved upwards.

 
This option only has an effect if the layout is translated.
Returns:
the translation distance along the y-axis
See Also:
setTranslateY(double), getTranslateX(), setOperation(int), TRANSLATE

setTranslateY

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

A positive value means the graph is moved downwards, while a negative value means the graph is moved upwards.

 
This option only has an effect if the layout is translated.
Default Value:
The default value is 0.0.
Parameters:
dy - the translation distance along the y-axis
See Also:
setTranslateX(double), setOperation(int), TRANSLATE

canLayoutCore

public boolean canLayoutCore(LayoutGraph graph)
Accepts all general graphs.

Specified by:
canLayoutCore in class CanonicMultiStageLayouter
Parameters:
graph - the input graph
Returns:
true for all graphs

doLayoutCore

public void doLayoutCore(LayoutGraph graph)
Applies the selected transformation to the given graph after invoking the optional core layout algorithm.

Specified by:
doLayoutCore in class CanonicMultiStageLayouter
Parameters:
graph - the input graph

applyBestFitRotationAngle

public static double applyBestFitRotationAngle(LayoutGraph graph,
                                               double width,
                                               double height)
Rotates the given graph so its resulting bounding box fits best to the given bounds.

Parameters:
graph - the graph that is rotated
width - the width of the preferred layout bounds
height - the height of the preferred layout bounds
Returns:
the rotation angle
See Also:
setBestFitRotationEnabled(boolean)

findBestFitRotationAngle

public static double findBestFitRotationAngle(LayoutGraph graph,
                                              double width,
                                              double height)
Returns the rotation angle for the graph that will result in a layout that fits best to the given bounds.

Parameters:
graph - the graph that is rotated
width - the width of the preferred layout bounds
height - the height of the preferred layout bounds
Returns:
the rotation angle
See Also:
applyBestFitRotationAngle(LayoutGraph, double, double)

scaleToRect

public static double[] scaleToRect(LayoutGraph graph,
                                   java.awt.Rectangle rect)
Scales the given graph so its resulting bounding box is (approximately) the same as the given rectangular bounds.

 
This operation won't have any effects if there is only one node in the graph or if there are nodes that are larger than the requested bounding box size.
Parameters:
graph - the graph to scale
rect - the rectangle into which to fit the graph
Returns:
the horizontal and vertical scaling factor

setMaximalBounds

public static void setMaximalBounds(LayoutGraph graph,
                                    double x,
                                    double y,
                                    double w,
                                    double h)
Fits the given graph into the specified rectangular bounds.

If the bounding box fits in the given bounds, nothing is done. Otherwise, the graph is scaled and optionally moved to fit.

 
The algorithm does not modify the node's sizes.
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 graph,
                             double dx,
                             double dy)
Translates the layout coordinates by the given vector.

Parameters:
graph - the graph that is translated
dx - the horizontal distance the given graph is moved
dy - the vertical distance the given graph is moved
See Also:
TRANSLATE, setOperation(int)

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