public class GraphTransformer extends MultiStageLayout implements ILayoutStage
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 SubgraphLayout
needs to be
enabled
. Then the nodes in the subgraph must be marked in
a IDataProvider
registered with the according
key
.
Constructor and Description |
---|
GraphTransformer()
Creates a new instance of
GraphTransformer with default settings. |
Modifier and Type | Method and Description |
---|---|
static double |
applyBestFitRotationAngle(LayoutGraph graph,
double width,
double height)
Rotates the given graph so its resulting bounding box fits best to the given bounds.
|
void |
applyLayoutCore(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.
|
ILayoutAlgorithm |
getCoreLayout()
Gets the core layout algorithm.
|
OperationType |
getOperation()
Gets the transformation operation.
|
double |
getPreferredHeight()
Gets the preferred height of the layout.
|
double |
getPreferredWidth()
Gets the preferred width of the layout.
|
double |
getRotationAngle()
Gets the angle of rotation.
|
double |
getScaleFactorX()
Gets the horizontal scaling factor used for the
scale operation . |
double |
getScaleFactorY()
Gets the vertical scaling factor used for the
scale operation . |
double |
getTranslateX()
Gets the horizontal translation distance.
|
double |
getTranslateY()
Gets the vertical translation distance.
|
boolean |
isBestFitRotationEnabled()
Gets whether or not to automatically choose the best fitting rotation angle.
|
boolean |
isNodeSizeScalingEnabled()
Gets whether or not to also scale node sizes when performing the
scale operation . |
void |
preferredLayoutSize(double width,
double height)
Specifies the preferred size of the layout.
|
void |
setBestFitRotationEnabled(boolean value)
Sets whether or not to automatically choose the best fitting rotation angle.
|
void |
setCoreLayout(ILayoutAlgorithm value)
Sets 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 |
setNodeSizeScalingEnabled(boolean value)
Sets whether or not to also scale node sizes when performing the
scale operation . |
void |
setOperation(OperationType value)
Sets the transformation operation.
|
void |
setPreferredHeight(double value)
Sets the preferred height of the layout.
|
void |
setPreferredWidth(double value)
Sets the preferred width of the layout.
|
void |
setRotationAngle(double value)
Sets the angle of rotation.
|
void |
setScaleFactor(double value)
Sets 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 value)
Sets the horizontal scaling factor used for the
scale operation . |
void |
setScaleFactorY(double value)
Sets the vertical scaling factor used for the
scale operation . |
void |
setTranslateX(double value)
Sets the horizontal translation distance.
|
void |
setTranslateY(double value)
Sets the vertical translation distance.
|
static void |
translate(LayoutGraph graph,
double dx,
double dy)
Translates the layout coordinates by the given vector.
|
appendStage, applyLayout, checkNodeSize, disableAllStages, getComponentLayout, getHideGroupsStage, getLabeling, getLayoutOrientation, getOrientationLayout, getParallelEdgeRouter, getSelfLoopRouter, getSubgraphLayout, isComponentLayoutEnabled, isHideGroupsStageEnabled, isLabelingEnabled, isOrientationLayoutEnabled, isParallelEdgeRouterEnabled, isSelfLoopRouterEnabled, isSubgraphLayoutEnabled, prependStage, removeStage, setComponentLayout, setComponentLayoutEnabled, setHideGroupsStage, setHideGroupsStageEnabled, setLabeling, setLabelingEnabled, setLayoutOrientation, setOrientationLayout, setOrientationLayoutEnabled, setParallelEdgeRouter, setParallelEdgeRouterEnabled, setSelfLoopRouter, setSelfLoopRouterEnabled, setSubgraphLayout, setSubgraphLayoutEnabled
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
applyLayout
public GraphTransformer()
GraphTransformer
with default settings.public static final 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 boundssetBestFitRotationEnabled(boolean)
public void applyLayoutCore(LayoutGraph graph)
core layout algorithm
.applyLayoutCore
in class MultiStageLayout
graph
- the input graphpublic static final 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 boundsapplyBestFitRotationAngle(LayoutGraph, double, double)
public ILayoutAlgorithm getCoreLayout()
ILayoutStage
This algorithm is wrapped by this stage. It is invoked in
ILayoutAlgorithm.applyLayout(com.yworks.yfiles.layout.LayoutGraph)
. The ILayoutStage
may add pre-
and post-processing steps before and after calling the core layout algorithm.
getCoreLayout
in interface ILayoutStage
ILayoutStage.setCoreLayout(ILayoutAlgorithm)
public OperationType getOperation()
IllegalArgumentException
- if the specified operation is unknownOperationType.SCALE
setOperation(OperationType)
public double getPreferredHeight()
This value will be used for fitting the rotation
to preferred bounds.
The preferred height needs to be non-negative.
IllegalArgumentException
- if the specified height is negativerotation
and
the rotation is fitted to the bounds
.getPreferredWidth()
,
setBestFitRotationEnabled(boolean)
,
setOperation(OperationType)
,
OperationType.ROTATE
,
setPreferredHeight(double)
public double getPreferredWidth()
This value will be used for fitting the rotation
to preferred bounds.
The preferred width needs to be non-negative.
IllegalArgumentException
- if the specified width is negativerotation
and
the rotation is fitted to the bounds
.getPreferredHeight()
,
setBestFitRotationEnabled(boolean)
,
setOperation(OperationType)
,
OperationType.ROTATE
,
setPreferredWidth(double)
public double getRotationAngle()
The angle must be given in degrees.
rotated
.setOperation(OperationType)
,
OperationType.ROTATE
,
setRotationAngle(double)
public double getScaleFactorX()
scale operation
.
Only positive scaling factors are allowed.
IllegalArgumentException
- if the specified scaling factor is negative or 0
scaled
.getScaleFactorY()
,
setOperation(OperationType)
,
OperationType.SCALE
,
setScaleFactorX(double)
public double getScaleFactorY()
scale operation
.
Only positive scaling factors are allowed.
IllegalArgumentException
- if the specified scaling factor is negative or 0
scaled
.getScaleFactorX()
,
setOperation(OperationType)
,
OperationType.SCALE
,
setScaleFactorY(double)
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
.getTranslateY()
,
setOperation(OperationType)
,
OperationType.TRANSLATE
,
setTranslateX(double)
public double getTranslateY()
A positive value means the graph is moved downwards, while a negative value means the graph is moved upwards.
translated
.getTranslateX()
,
setOperation(OperationType)
,
OperationType.TRANSLATE
,
setTranslateY(double)
public boolean isBestFitRotationEnabled()
The angle will be chosen such that the bounding box after the rotation fits best to the
preferred aspect ratio
.
rotated
.false
. The layout is rotated by a specific angle.true
if the best fitting rotation angle should be automatically determined, false
if the specified angle
should be usedsetOperation(OperationType)
,
OperationType.ROTATE
,
setBestFitRotationEnabled(boolean)
public boolean isNodeSizeScalingEnabled()
scale operation
.scaled
.false
. Nodes keep their sizes when the layout is scaled.true
if the sizes of the nodes are also scaled, false
otherwisesetOperation(OperationType)
,
OperationType.SCALE
,
setNodeSizeScalingEnabled(boolean)
public void preferredLayoutSize(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.
IllegalArgumentException
- if the specified width or height is negativethe rotation is fitted to the bounds
.width
- the preferred width of the layoutheight
- the preferred height of the layoutsetPreferredWidth(double)
,
setPreferredHeight(double)
,
setBestFitRotationEnabled(boolean)
,
setOperation(OperationType)
,
OperationType.ROTATE
public void setBestFitRotationEnabled(boolean value)
The angle will be chosen such that the bounding box after the rotation fits best to the
preferred aspect ratio
.
rotated
.false
. The layout is rotated by a specific angle.value
- true
if the best fitting rotation angle should be automatically determined, false
if the specified angle
should be usedsetOperation(OperationType)
,
OperationType.ROTATE
,
isBestFitRotationEnabled()
public void setCoreLayout(ILayoutAlgorithm value)
ILayoutStage
This algorithm is wrapped by this stage. It is invoked in
ILayoutAlgorithm.applyLayout(com.yworks.yfiles.layout.LayoutGraph)
. The ILayoutStage
may add pre-
and post-processing steps before and after calling the core layout algorithm.
setCoreLayout
in interface ILayoutStage
value
- the core layout algorithmILayoutStage.getCoreLayout()
public static final 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 void setNodeSizeScalingEnabled(boolean value)
scale operation
.scaled
.false
. Nodes keep their sizes when the layout is scaled.value
- true
if the sizes of the nodes are also scaled, false
otherwisesetOperation(OperationType)
,
OperationType.SCALE
,
isNodeSizeScalingEnabled()
public void setOperation(OperationType value)
IllegalArgumentException
- if the specified operation is unknownOperationType.SCALE
value
- one of the valid operation specifiersgetOperation()
public void setPreferredHeight(double value)
This value will be used for fitting the rotation
to preferred bounds.
The preferred height needs to be non-negative.
IllegalArgumentException
- if the specified height is negativerotation
and
the rotation is fitted to the bounds
.value
- the preferred height of the layoutgetPreferredWidth()
,
setBestFitRotationEnabled(boolean)
,
setOperation(OperationType)
,
OperationType.ROTATE
,
getPreferredHeight()
public void setPreferredWidth(double value)
This value will be used for fitting the rotation
to preferred bounds.
The preferred width needs to be non-negative.
IllegalArgumentException
- if the specified width is negativerotation
and
the rotation is fitted to the bounds
.value
- the preferred width of the layoutgetPreferredHeight()
,
setBestFitRotationEnabled(boolean)
,
setOperation(OperationType)
,
OperationType.ROTATE
,
getPreferredWidth()
public void setRotationAngle(double value)
The angle must be given in degrees.
rotated
.value
- the rotation angle in degreessetOperation(OperationType)
,
OperationType.ROTATE
,
getRotationAngle()
public void setScaleFactor(double value)
scale operation
.
This factor applies vertical and horizontal.
Only positive scaling factors are allowed.
IllegalArgumentException
- if the specified scaling factor is negative or 0
scaled
.value
- the scaling factorsetScaleFactorX(double)
,
setScaleFactorY(double)
,
setOperation(OperationType)
,
OperationType.SCALE
public void setScaleFactors(double xFactor, double yFactor)
scale operation
.
Only positive scaling factors are allowed.
IllegalArgumentException
- if one the specified scaling factors is negative or 0
scaled
.xFactor
- the horizontal scaling factoryFactor
- the vertical scaling factorsetScaleFactorX(double)
,
setScaleFactorY(double)
,
setOperation(OperationType)
,
OperationType.SCALE
public void setScaleFactorX(double value)
scale operation
.
Only positive scaling factors are allowed.
IllegalArgumentException
- if the specified scaling factor is negative or 0
scaled
.value
- the horizontal scaling factorgetScaleFactorY()
,
setOperation(OperationType)
,
OperationType.SCALE
,
getScaleFactorX()
public void setScaleFactorY(double value)
scale operation
.
Only positive scaling factors are allowed.
IllegalArgumentException
- if the specified scaling factor is negative or 0
scaled
.value
- the vertical scaling factorgetScaleFactorX()
,
setOperation(OperationType)
,
OperationType.SCALE
,
getScaleFactorY()
public void setTranslateX(double value)
A positive value means the graph is moved to the right while, a negative value means the graph is moved to the left.
translated
.value
- the translation distance along the x-axisgetTranslateY()
,
setOperation(OperationType)
,
OperationType.TRANSLATE
,
getTranslateX()
public void setTranslateY(double value)
A positive value means the graph is moved downwards, while a negative value means the graph is moved upwards.
translated
.value
- the translation distance along the y-axisgetTranslateX()
,
setOperation(OperationType)
,
OperationType.TRANSLATE
,
getTranslateY()
public static final 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 movedOperationType.TRANSLATE
,
setOperation(OperationType)