|
Search this API | ||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object y.layout.CanonicMultiStageLayouter y.layout.transformer.GraphTransformer
public class GraphTransformer
This layout algorithm applies geometric transformations to (sub-)graphs.
There are several ways to transform the graph that include mirroring, rotating, scaling and translating.
The highlighted subgraph is rotated by 45
degrees
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
.
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, NODE_TYPE_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 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 |
---|
public static final int MIRROR_XAXIS
setOperation(int)
,
Constant Field Valuespublic static final int MIRROR_YAXIS
setOperation(int)
,
Constant Field Valuespublic static final int ROTATE
setOperation(int)
,
setRotationAngle(double)
,
setBestFitRotationEnabled(boolean)
,
Constant Field Valuespublic static final int SCALE
setOperation(int)
,
setScaleFactor(double)
,
setScaleFactors(double, double)
,
setScaleNodeSize(boolean)
,
Constant Field Valuespublic static final int TRANSLATE
setOperation(int)
,
setTranslateX(double)
,
setTranslateY(double)
,
Constant Field ValuesConstructor Detail |
---|
public GraphTransformer()
GraphTransformer
with default settings.
Method Detail |
---|
public void setCoreLayouter(Layouter coreLayouter)
LayoutStage
Layouter.doLayout(LayoutGraph)
. The LayoutStage
may add pre- and post-processing steps before and after calling the core layout algorithm.
setCoreLayouter
in interface LayoutStage
coreLayouter
- the core layout algorithmpublic Layouter getCoreLayouter()
LayoutStage
Layouter.doLayout(LayoutGraph)
. The LayoutStage
may add pre- and post-processing steps before and after calling the core layout algorithm.
getCoreLayouter
in interface LayoutStage
public void setOperation(int operation)
SCALE
operation
- one of the valid operation specifiers
java.lang.IllegalArgumentException
- if the specified operation is unknownpublic int getOperation()
setOperation(int)
public void setRotationAngle(double angle)
The angle must be given in degrees.
rotated
.angle
- the rotation angle in degreessetOperation(int)
,
ROTATE
public double getRotationAngle()
The angle must be given in degrees.
rotated
.setRotationAngle(double)
,
setOperation(int)
,
ROTATE
public void setBestFitRotationEnabled(boolean enabled)
The angle will be chosen such that the bounding box after the rotation fits best to the
preferred aspect ratio
.
rotated
.enabled
- true
if the best fitting rotation angle is automatically determined,
false
if the specified angle is usedsetOperation(int)
,
ROTATE
public boolean isBestFitRotationEnabled()
The angle will be chosen such that the bounding box after the rotation fits best to the
preferred aspect ratio
.
rotated
.true
if the best fitting rotation angle should be automatically determined,
false
if the specified angle should be usedsetBestFitRotationEnabled(boolean)
,
setOperation(int)
,
ROTATE
public void setPreferedLayoutSize(double width, double height)
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.
the rotation is fitted to the bounds
.width
- the preferred width of the layoutheight
- the preferred height of the layout
java.lang.IllegalArgumentException
- if the specified width or height is negativesetPreferredWidth(double)
,
setPreferredHeight(double)
,
setBestFitRotationEnabled(boolean)
,
setOperation(int)
,
ROTATE
public double getPreferredHeight()
This value will be used for fitting the rotation
to preferred bounds.
The preferred height needs to be non-negative.
rotation
and
the rotation is fitted to the bounds
.setPreferredHeight(double)
,
getPreferredWidth()
,
setBestFitRotationEnabled(boolean)
,
setOperation(int)
,
ROTATE
public void setPreferredHeight(double preferredHeight)
This value will be used for fitting the rotation
to preferred bounds.
The preferred height needs to be non-negative.
rotation
and
the rotation is fitted to the bounds
.preferredHeight
- the preferred height of the layout
java.lang.IllegalArgumentException
- if the specified height is negativesetPreferredWidth(double)
,
setBestFitRotationEnabled(boolean)
,
setOperation(int)
,
ROTATE
public double getPreferredWidth()
This value will be used for fitting the rotation
to preferred bounds.
The preferred width needs to be non-negative.
rotation
and
the rotation is fitted to the bounds
.setPreferredWidth(double)
,
getPreferredHeight()
,
setBestFitRotationEnabled(boolean)
,
setOperation(int)
,
ROTATE
public void setPreferredWidth(double preferredWidth)
This value will be used for fitting the rotation
to preferred bounds.
The preferred width needs to be non-negative.
rotation
and
the rotation is fitted to the bounds
.preferredWidth
- the preferred width of the layout
java.lang.IllegalArgumentException
- if the specified width is negativesetPreferredHeight(double)
,
setBestFitRotationEnabled(boolean)
,
setOperation(int)
,
ROTATE
public void setScaleNodeSize(boolean s)
scale operation
.
scaled
.s
- true
if the sizes of the nodes should also be scaled, false
otherwisesetOperation(int)
,
SCALE
public boolean getScaleNodeSize()
scale operation
.
scaled
.true
if the sizes of the nodes are also scaled, false
otherwisesetScaleNodeSize(boolean)
,
setOperation(int)
,
SCALE
public void setScaleFactor(double f)
scale operation
.
This factor applies vertical and horizontal.
Only positive scaling factors are allowed.
scaled
.f
- the scaling factor
java.lang.IllegalArgumentException
- if the specified scaling factor is negative or 0
setScaleFactorX(double)
,
setScaleFactorY(double)
,
setOperation(int)
,
SCALE
public void setScaleFactors(double xFactor, double yFactor)
scale operation
.
Only positive scaling factors are allowed.
scaled
.xFactor
- the horizontal scaling factoryFactor
- the vertical scaling factor
java.lang.IllegalArgumentException
- if one the specified scaling factors is negative or 0
setScaleFactorX(double)
,
setScaleFactorY(double)
,
setOperation(int)
,
SCALE
public double getScaleFactorY()
scale operation
.
Only positive scaling factors are allowed.
scaled
.setScaleFactorY(double)
,
getScaleFactorX()
,
setOperation(int)
,
SCALE
public void setScaleFactorY(double scaleFactorY)
scale operation
.
Only positive scaling factors are allowed.
scaled
.scaleFactorY
- the vertical scaling factor
java.lang.IllegalArgumentException
- if the specified scaling factor is negative or 0
setScaleFactorX(double)
,
setOperation(int)
,
SCALE
public double getScaleFactorX()
scale operation
.
Only positive scaling factors are allowed.
scaled
.setScaleFactorX(double)
,
getScaleFactorY()
,
setOperation(int)
,
SCALE
public void setScaleFactorX(double scaleFactorX)
scale operation
.
Only positive scaling factors are allowed.
scaled
.scaleFactorX
- the horizontal scaling factor
java.lang.IllegalArgumentException
- if the specified scaling factor is negative or 0
setScaleFactorY(double)
,
setOperation(int)
,
SCALE
public double getTranslateX()
A positive value means the graph is moved to the right, while a negative value means the graph is moved to the left.
translated
.setTranslateX(double)
,
getTranslateY()
,
setOperation(int)
,
TRANSLATE
public void setTranslateX(double dx)
A positive value means the graph is moved to the right while, a negative value means the graph is moved to the left.
translated
.dx
- the translation distance along the x-axissetTranslateY(double)
,
setOperation(int)
,
TRANSLATE
public double getTranslateY()
A positive value means the graph is moved downwards, while a negative value means the graph is moved upwards.
translated
.setTranslateY(double)
,
getTranslateX()
,
setOperation(int)
,
TRANSLATE
public void setTranslateY(double dy)
A positive value means the graph is moved downwards, while a negative value means the graph is moved upwards.
translated
.dy
- the translation distance along the y-axissetTranslateX(double)
,
setOperation(int)
,
TRANSLATE
public boolean canLayoutCore(LayoutGraph graph)
canLayoutCore
in class CanonicMultiStageLayouter
graph
- the input graph
true
for all graphspublic void doLayoutCore(LayoutGraph graph)
core layout algorithm
.
doLayoutCore
in class CanonicMultiStageLayouter
graph
- the input graphpublic static double applyBestFitRotationAngle(LayoutGraph graph, double width, double height)
graph
- the graph that is rotatedwidth
- the width of the preferred layout boundsheight
- the height of the preferred layout bounds
setBestFitRotationEnabled(boolean)
public static double findBestFitRotationAngle(LayoutGraph graph, double width, double height)
graph
- the graph that is rotatedwidth
- the width of the preferred layout boundsheight
- the height of the preferred layout bounds
applyBestFitRotationAngle(LayoutGraph, double, double)
public static double[] scaleToRect(LayoutGraph graph, java.awt.Rectangle rect)
graph
- the graph to scalerect
- the rectangle into which to fit the graph
public static void setMaximalBounds(LayoutGraph graph, double x, double y, double w, double h)
If the bounding box fits in the given bounds, nothing is done. Otherwise, the graph is scaled and optionally moved to fit.
graph
- the graph to modifyx
- the upper left x-coordinate of the boundsy
- the upper left y-coordinate of the boundsw
- the width of the boundsh
- the height of the boundspublic static void translate(LayoutGraph graph, double dx, double dy)
graph
- the graph that is translateddx
- the horizontal distance the given graph is moveddy
- the vertical distance the given graph is movedTRANSLATE
,
setOperation(int)
|
© Copyright 2000-2022, yWorks GmbH. All rights reserved. |
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |