public class ShuffleLayout extends Object implements ILayoutStage
Note: The usage of RemoveOverlapsStage
instead of this class is recommended for most use cases
involving the mere removal of overlaps. That stage offers a more powerful strategy to do the task.
The style of results often resembles the look of tiles which have been dropped onto each other, where tiles correspond to nodes of the graph. The reason is that overlapping nodes are moved in order to resolve the overlap. During this process, several nodes moving in the same direction may be stacked next to or above each other.
This algorithm does not route the edges of the input graph - edges might although be stretched due to the node movement.
Example with overlaps (left) and after executing the shuffle layout (right) Example with overlaps (left) and after executing the shuffle layout (right)
This layout stage can also be executed
on its own, without specifying a
core layout algorithm
.
A minimum distance between nodes can be specified such that not only overlaps will be removed but nodes will keep this
specified distance to other nodes. This distance can be defined separately for each node using a IDataProvider
registered with key MINIMUM_DISTANCE_DPKEY
. The minimum distance can also be specified globally via
MinimumNodeDistance
.
To specify that specific nodes should not be moved, they can be marked as fixed using a IDataProvider
registered
with key FIXED_NODE_DPKEY
.
Modifier and Type | Field and Description |
---|---|
static NodeDpKey<Boolean> |
FIXED_NODE_DPKEY
A
DataProvider key for marking nodes as fixed
A node marked as fixed will not be moved by this algorithm but stay at its current position. |
static NodeDpKey<Double> |
MINIMUM_DISTANCE_DPKEY
A
DataProvider key for specifying a minimum distance for each node
The default minimum distance specified by MinimumNodeDistance will be ignored
for a node if the IDataProvider registered with this key contains a valid minimum distance for that node. |
Constructor and Description |
---|
ShuffleLayout()
Creates a new instance of
ShuffleLayout with default settings. |
Modifier and Type | Method and Description |
---|---|
void |
applyLayout(LayoutGraph graph)
Performs the overlap removal (shuffle) algorithm on the given graph, after the
core layout algorithm
was applied to it. |
ILayoutAlgorithm |
getCoreLayout()
Gets the core layout algorithm.
|
HorizontalOverlapCriterion |
getHorizontalOverlapCriterion()
Gets the criterion for marking an overlap as horizontal.
|
double |
getMinimumNodeDistance()
Gets the default minimum distance that has to be obeyed between any two nodes.
|
boolean |
isBarycenterModeEnabled()
Gets whether or not the barycenter mode is used for node shuffling when removing overlaps.
|
boolean |
isSimpleModeEnabled()
Gets whether or not the simple, fast layout mode of this algorithm is active.
|
void |
setBarycenterModeEnabled(boolean value)
Sets whether or not the barycenter mode is used for node shuffling when removing overlaps.
|
void |
setCoreLayout(ILayoutAlgorithm value)
Sets the core layout algorithm.
|
void |
setHorizontalOverlapCriterion(HorizontalOverlapCriterion value)
Sets the criterion for marking an overlap as horizontal.
|
void |
setMinimumNodeDistance(double value)
Sets the default minimum distance that has to be obeyed between any two nodes.
|
void |
setSimpleModeEnabled(boolean value)
Sets whether or not the simple, fast layout mode of this algorithm is active.
|
public static final NodeDpKey<Boolean> FIXED_NODE_DPKEY
DataProvider
key for marking nodes as fixed
A node marked as fixed will not be moved by this algorithm but stay at its current position.
public static final NodeDpKey<Double> MINIMUM_DISTANCE_DPKEY
DataProvider
key for specifying a minimum distance for each node
The default minimum distance specified by MinimumNodeDistance
will be ignored
for a node if the IDataProvider
registered with this key contains a valid minimum distance for that node.
Minimum distance values need to be greater than 0
.
IDataProvider
with this key is registered, the minimum distance for all nodes is specified by
MinimumNodeDistance
.public ShuffleLayout()
ShuffleLayout
with default settings.public void applyLayout(LayoutGraph graph)
core layout algorithm
was applied to it.applyLayout
in interface ILayoutAlgorithm
graph
- the input graphpublic 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 HorizontalOverlapCriterion getHorizontalOverlapCriterion()
This criterion influences how overlaps will be resolved. If an overlap is considered horizontal, it will preferably be solved by moving nodes horizontally, else vertically.
IllegalArgumentException
- if the given criterion is unknownsimple mode
is disabled.HorizontalOverlapCriterion.LESS_MOVEMENT
setHorizontalOverlapCriterion(HorizontalOverlapCriterion)
public double getMinimumNodeDistance()
This default distance will be considered for a node if the IDataProvider
registered with the graph with key MINIMUM_DISTANCE_DPKEY
does not contain a valid, positive distance for that node. If there is no IDataProvider
registered with the
mentioned key, then this default distance will be applied to all nodes.
The minimum distance needs to be a non-negative value.
IllegalArgumentException
- if the given distance is negativeMINIMUM_DISTANCE_DPKEY
,
setMinimumNodeDistance(double)
public boolean isBarycenterModeEnabled()
If this mode is active, the overlap removal step will be executed two times for each direction, once with the normal node ordering and once with the reversed ordering. Finally, the barycenter between both results will be used for assigning the node coordinates.
Activating the barycenter mode allows more symmetric results for some graphs. However, the runtime might increase.
false
. The barycenter mode is disabled.true
if the barycenter placement mode is active false
otherwisesetBarycenterModeEnabled(boolean)
public boolean isSimpleModeEnabled()
Enabling this mode, the overlap removal step will be executed using a simpler and less sophisticated approach. All overlaps will only be solved by moving nodes vertically. The algorithm will not try to figure out which direction might be better for overlap removal.
The runtime will improve, but results may be of lower quality when using this mode.
horizontal overlap criterion
will not
have any effect.false
. true
if the simple and fast layout mode is enabled, false
otherwise.setSimpleModeEnabled(boolean)
public void setBarycenterModeEnabled(boolean value)
If this mode is active, the overlap removal step will be executed two times for each direction, once with the normal node ordering and once with the reversed ordering. Finally, the barycenter between both results will be used for assigning the node coordinates.
Activating the barycenter mode allows more symmetric results for some graphs. However, the runtime might increase.
false
. The barycenter mode is disabled.value
- true
if the barycenter placement mode is active false
otherwiseisBarycenterModeEnabled()
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 void setHorizontalOverlapCriterion(HorizontalOverlapCriterion value)
This criterion influences how overlaps will be resolved. If an overlap is considered horizontal, it will preferably be solved by moving nodes horizontally, else vertically.
IllegalArgumentException
- if the given criterion is unknownsimple mode
is disabled.HorizontalOverlapCriterion.LESS_MOVEMENT
value
- one of the predefined overlap criteriagetHorizontalOverlapCriterion()
public void setMinimumNodeDistance(double value)
This default distance will be considered for a node if the IDataProvider
registered with the graph with key MINIMUM_DISTANCE_DPKEY
does not contain a valid, positive distance for that node. If there is no IDataProvider
registered with the
mentioned key, then this default distance will be applied to all nodes.
The minimum distance needs to be a non-negative value.
IllegalArgumentException
- if the given distance is negativevalue
- the non-negative minimum node distanceMINIMUM_DISTANCE_DPKEY
,
getMinimumNodeDistance()
public void setSimpleModeEnabled(boolean value)
Enabling this mode, the overlap removal step will be executed using a simpler and less sophisticated approach. All overlaps will only be solved by moving nodes vertically. The algorithm will not try to figure out which direction might be better for overlap removal.
The runtime will improve, but results may be of lower quality when using this mode.
horizontal overlap criterion
will not
have any effect.false
. value
- true
if the simple and fast layout mode is enabled, false
otherwise.isSimpleModeEnabled()