Search this API

y.layout
Class GraphLayoutLineWrapper

java.lang.Object
  extended by y.layout.AbstractLayoutStage
      extended by y.layout.GraphLayoutLineWrapper
All Implemented Interfaces:
Layouter, LayoutStage

public class GraphLayoutLineWrapper
extends AbstractLayoutStage

GraphLayoutLineWrapper can line-wrap or column-wrap a graph layout.

This LayoutStage supports both wrapping a layout at a given width (height) and wrapping a layout automatically at some width (height) such that the resulting overall aspect ratio is close to a desired target ratio.

The GraphLayoutLineWrapper can be used on an existing graph layout or on the result of the core layout algorithm.

 

Field Summary
 
Fields inherited from interface y.layout.Layouter
EDGE_ID_DPKEY, NODE_ID_DPKEY, SELECTED_EDGES, SELECTED_NODES
 
Constructor Summary
GraphLayoutLineWrapper()
          Creates a new GraphLayoutLineWrapper instance with default settings.
 
Method Summary
 boolean canLayout(LayoutGraph graph)
          Accepts all graphs that can be handled by the core layout algorithm.
 void doLayout(LayoutGraph graph)
          Cuts the layout resulting from the core layout algorithm at a specified width/height and shifts the remaining graph into the next row/column until the layout has the desired width/height.
 double getEdgeSpacing()
          Returns the space that should be kept between edges.
 double getFixedWidth()
          Returns the desired width of the lines.
 double getSpacing()
          Returns the space between adjacent lines of the wrapped graph layout.
 double getTargetRatio()
          Returns the desired target aspect ratio for the layout.
 boolean isColumnMode()
          Returns whether this LayoutStage wraps lines/rows or columns.
 boolean isFixedWidthLineBreaks()
          Returns whether the algorithm should use the fixed width or target aspect ratio to determine line breaks.
 boolean isMirroringEnabled()
          Returns whether or not every other line is mirrored.
 void setColumnMode(boolean columnMode)
          Specifies whether this LayoutStage wraps lines/rows or columns.
 void setEdgeSpacing(double edgeSpacing)
          Specifies the space that should be kept between edges.
 void setFixedWidth(double fixedWidth)
          Specifies the desired width of the lines.
 void setFixedWidthLineBreaks(boolean fixedWidthLineBreaks)
          Specifies whether the algorithm should use the fixed width or target aspect ratio to determine line breaks.
 void setMirroringEnabled(boolean mirroringEnabled)
          Specifies whether or not every other line is mirrored.
 void setSpacing(double spacing)
          Specifies the space between adjacent lines of the wrapped graph layout.
 void setTargetRatio(double targetRatio)
          Specifies the desired target aspect ratio for the layout.
 
Methods inherited from class y.layout.AbstractLayoutStage
canLayoutCore, doLayoutCore, getCoreLayouter, setCoreLayouter
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

GraphLayoutLineWrapper

public GraphLayoutLineWrapper()
Creates a new GraphLayoutLineWrapper instance with default settings.

Method Detail

getEdgeSpacing

public double getEdgeSpacing()
Returns the space that should be kept between edges.

The spacing must be non-negative.

Returns:
the space between edges
See Also:
setEdgeSpacing(double)

setEdgeSpacing

public void setEdgeSpacing(double edgeSpacing)
Specifies the space that should be kept between edges.

The spacing must be non-negative.

Default Value:
The default value is 5.
Parameters:
edgeSpacing - the space between edges
Throws:
java.lang.IllegalArgumentException - if the given spacing is a negative value
Sample Graphs:

5

50

isColumnMode

public boolean isColumnMode()
Returns whether this LayoutStage wraps lines/rows or columns.

If this mode is enabled, the layout is wrapped vertically and new columns are appended to the right of the first column. Otherwise, the layout is wrapped horizontally and new rows are appended below the first row.

Also, the setFixedWidth(double) property will be interpreted as a fixed height if this mode is enabled.

Returns:
true for column wrapping mode, false for row wrapping
See Also:
setColumnMode(boolean), setFixedWidth(double)

setColumnMode

public void setColumnMode(boolean columnMode)
Specifies whether this LayoutStage wraps lines/rows or columns.

If this mode is enabled, the layout is wrapped vertically and new columns are appended to the right of the first column. Otherwise, the layout is wrapped horizontally and new rows are appended below the first row.

Also, the setFixedWidth(double) property will be interpreted as a fixed height if this mode is enabled.

Default Value:
The default value is false. The layout is wrapped horizontally, producing rows.
Parameters:
columnMode - true for column wrapping mode, false for row wrapping
See Also:
setFixedWidth(double)

getSpacing

public double getSpacing()
Returns the space between adjacent lines of the wrapped graph layout.

If the column mode is enabled, this spacing defines the distance between adjacent columns.

The spacing should be non-negative.

Returns:
the space between the lines
See Also:
setSpacing(double)

setSpacing

public void setSpacing(double spacing)
Specifies the space between adjacent lines of the wrapped graph layout.

If the column mode is enabled, this spacing defines the distance between adjacent columns.

The spacing should be non-negative.

Default Value:
The default value is 10.
Parameters:
spacing - the space between the lines
Throws:
java.lang.IllegalArgumentException - if the spacing is negative
Sample Graphs:

10

50

isMirroringEnabled

public boolean isMirroringEnabled()
Returns whether or not every other line is mirrored.

When breaking a line and placing the remaining line below, this remainder can be rotated by 180 degrees. Then, the edges connecting both lines stay short. In case the remainder is not rotated, the edges are routed between the two lines to connect to the front of the non-mirrored line.

Returns:
true if every second line is rotated by 180 degrees, false otherwise
See Also:
setMirroringEnabled(boolean)

isFixedWidthLineBreaks

public boolean isFixedWidthLineBreaks()
Returns whether the algorithm should use the fixed width or target aspect ratio to determine line breaks.

Returns:
true if a fixed line width is used, false otherwise
See Also:
setFixedWidthLineBreaks(boolean), setFixedWidth(double), setTargetRatio(double)

setFixedWidthLineBreaks

public void setFixedWidthLineBreaks(boolean fixedWidthLineBreaks)
Specifies whether the algorithm should use the fixed width or target aspect ratio to determine line breaks.

Default Value:
The default value is false. The target aspect ratio defines how the line width is chosen.
Parameters:
fixedWidthLineBreaks - true if a fixed line width should be used, false otherwise
See Also:
setFixedWidth(double), setTargetRatio(double)

getTargetRatio

public double getTargetRatio()
Returns the desired target aspect ratio for the layout.

The aspect ratio needs to be greater than 0.

 
The specified width is only considered if isFixedWidthLineBreaks() returns false.
Returns:
the desired target aspect ratio in terms of width/height
See Also:
setTargetRatio(double), setFixedWidthLineBreaks(boolean)

setTargetRatio

public void setTargetRatio(double targetRatio)
Specifies the desired target aspect ratio for the layout.

The aspect ratio needs to be greater than 0.

 
The specified width is only considered if isFixedWidthLineBreaks() returns false.
Default Value:
The default value is 1.
Parameters:
targetRatio - the desired target aspect ratio in terms of width/height
Throws:
java.lang.IllegalArgumentException - if the target ratio is 0 or less
See Also:
setFixedWidthLineBreaks(boolean)
Sample Graphs:

0.5

1

2

getFixedWidth

public double getFixedWidth()
Returns the desired width of the lines.

The GraphLayoutLineWrapper breaks the lines at the specified width.

In column mode, the fixed width is interpreted as fixed height for a column.

 
The algorithm will not necessarily be able to satisfy very small values, since the nodes need to fit completely into a line.
 
The specified width is only considered if isFixedWidthLineBreaks() returns true.
Returns:
the width of the lines
See Also:
setFixedWidth(double), setFixedWidthLineBreaks(boolean), setColumnMode(boolean)

setFixedWidth

public void setFixedWidth(double fixedWidth)
Specifies the desired width of the lines.

The GraphLayoutLineWrapper breaks the lines at the specified width.

In column mode, the fixed width is interpreted as fixed height for a column.

 
The algorithm will not necessarily be able to satisfy very small values, since the nodes need to fit completely into a line.
 
The specified width is only considered if isFixedWidthLineBreaks() returns true.
Default Value:
The default value is 500.
Parameters:
fixedWidth - the width of the lines
See Also:
setFixedWidthLineBreaks(boolean), setColumnMode(boolean)
Sample Graphs:

500

300

setMirroringEnabled

public void setMirroringEnabled(boolean mirroringEnabled)
Specifies whether or not every other line is mirrored.

When breaking a line and placing the remaining line below, this remainder can be rotated by 180 degrees. Then, the edges connecting both lines stay short. In case the remainder is not rotated, the edges are routed between the two lines to connect to the front of the non-mirrored line.

Default Value:
The default value is true. Every other line is mirrored.
Parameters:
mirroringEnabled - true if every second line should be rotated by 180 degrees, false otherwise
Sample Graphs:

false

true

canLayout

public boolean canLayout(LayoutGraph graph)
Accepts all graphs that can be handled by the core layout algorithm.

If there is no core layout algorithm, all graphs are accepted.

Parameters:
graph - the input graph
Returns:
true if there is no core layout algorithm or the core layout algorithm accepts the graph, false otherwise
See Also:
Layouter.doLayout(LayoutGraph)

doLayout

public void doLayout(LayoutGraph graph)
Cuts the layout resulting from the core layout algorithm at a specified width/height and shifts the remaining graph into the next row/column until the layout has the desired width/height.

Parameters:
graph - the input graph
See Also:
Layouter.canLayout(LayoutGraph)

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