Search this API

y.layout.organic
Class RemoveOverlapsLayoutStage

java.lang.Object
  extended by y.layout.organic.RemoveOverlapsLayoutStage
All Implemented Interfaces:
Layouter, LayoutStage

public class RemoveOverlapsLayoutStage
extends Object
implements LayoutStage

This LayoutStage removes node overlaps and guarantees a certain minimum distance between nodes.

Layout Style

This stage only removes overlaps between nodes of the input graph. To do so, overlapping nodes will be moved apart. Results often look like a stretched version of the original graph. A graph containing overlaps (left) and the result after the overlap removal

Features

It is possible to define a minimum distance between nodes. This feature allows to not only remove overlaps but forces nodes to keep a specified distance to other nodes.

 
Overlaps between nodes and edges are not removed by this stage.
 

Field Summary
protected  LayoutGraph graph
          The input graph.
protected  double[] h
          The height values of nodes, ordered within the array based on node indices.
protected  Node[] nodes
          The node array of the input graph.
protected  YRandom random
          The source of randomness used during the layout process.
protected  double[] w
          The width values of nodes, ordered within the array based on node indices.
protected  double[] x
          The x-coordinates of nodes, ordered within the array based on node indices.
protected  double[] y
          The y-coordinates of nodes, ordered within the array based on node indices.
 
Fields inherited from interface y.layout.Layouter
EDGE_ID_DPKEY, NODE_ID_DPKEY, SELECTED_EDGES, SELECTED_NODES
 
Constructor Summary
RemoveOverlapsLayoutStage(double minimumNodeDistance)
          Creates a new RemoveOverlapsLayoutStage instance with a given minimum node distance.
RemoveOverlapsLayoutStage(YRandom random, double minimumNodeDistance)
          Creates a new RemoveOverlapsLayoutStage instance with a given minimum node distance and a YRandom instance representing the source of randomness for this layout stage.
 
Method Summary
 boolean canLayout(LayoutGraph graph)
          Accepts all graphs which are accepted by the specified core layout algorithm.
 void doLayout(LayoutGraph graph)
          Removes node overlaps and displaces nodes of the given graph such that they keep the specified minimum distance to each other.
 Layouter getCoreLayouter()
          Returns the core layout algorithm.
 double getMinimumNodeDistance()
          Returns the minimum distance to be kept between any two nodes of the graph.
 void setCoreLayouter(Layouter l)
          Specifies the core layout algorithm.
 void setMinimumNodeDistance(double minimumNodeDistance)
          Specifies the minimum distance to be kept between any two nodes of the graph.
protected  void updatePos()
          Updates the data structure holding x-coordinates and y-coordinates of the nodes according to the current center coordinates.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

graph

protected LayoutGraph graph
The input graph.


random

protected YRandom random
The source of randomness used during the layout process.


x

protected double[] x
The x-coordinates of nodes, ordered within the array based on node indices.


y

protected double[] y
The y-coordinates of nodes, ordered within the array based on node indices.


w

protected double[] w
The width values of nodes, ordered within the array based on node indices.


h

protected double[] h
The height values of nodes, ordered within the array based on node indices.


nodes

protected Node[] nodes
The node array of the input graph.

Constructor Detail

RemoveOverlapsLayoutStage

public RemoveOverlapsLayoutStage(double minimumNodeDistance)
Creates a new RemoveOverlapsLayoutStage instance with a given minimum node distance.

The minimum node distance needs to be non-negative.

Parameters:
minimumNodeDistance - a non-negative minimum distance value
Throws:
IllegalArgumentException - if the given distance is negative

RemoveOverlapsLayoutStage

public RemoveOverlapsLayoutStage(YRandom random,
                                 double minimumNodeDistance)
Creates a new RemoveOverlapsLayoutStage instance with a given minimum node distance and a YRandom instance representing the source of randomness for this layout stage.

The minimum node distance needs to be non-negative.

Parameters:
random - the source of randomness for this layout stage
minimumNodeDistance - a non-negative minimum distance value
Throws:
IllegalArgumentException - if the given distance is negative
Method Detail

getMinimumNodeDistance

public double getMinimumNodeDistance()
Returns the minimum distance to be kept between any two nodes of the graph.

Due to this distance not only nodes that overlap will be moved to resolve the overlap, but also nodes which are too close to each other with respect to this distance will be displaced.

The minimum node distance needs to be non-negative.

Returns:
the non-negative minimum node distance
See Also:
setMinimumNodeDistance(double)

setMinimumNodeDistance

public void setMinimumNodeDistance(double minimumNodeDistance)
Specifies the minimum distance to be kept between any two nodes of the graph.

Due to this distance not only nodes that overlap will be moved to resolve the overlap, but also nodes which are too close to each other with respect to this distance will be displaced.

The minimum node distance needs to be non-negative.

Parameters:
minimumNodeDistance - the non-negative minimum node distance
Throws:
IllegalArgumentException - if the given minimum distance is negative

canLayout

public boolean canLayout(LayoutGraph graph)
Accepts all graphs which are accepted by the specified core layout algorithm.

Specified by:
canLayout in interface Layouter
Parameters:
graph - the input graph
Returns:
true if the core algorithm is null or can handle the given graph, false otherwise
See Also:
Layouter.doLayout(LayoutGraph)

doLayout

public void doLayout(LayoutGraph graph)
Removes node overlaps and displaces nodes of the given graph such that they keep the specified minimum distance to each other.

If a core layout algorithm is specified, it will be executed first.

Specified by:
doLayout in interface Layouter
 
The given graph will not be copied during the layout process and the layout will be immediately applied to the given graph.
Parameters:
graph - the input graph
See Also:
Layouter.canLayout(LayoutGraph)

updatePos

protected void updatePos()
Updates the data structure holding x-coordinates and y-coordinates of the nodes according to the current center coordinates.


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

setCoreLayouter

public void setCoreLayouter(Layouter l)
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:
l - the core layout algorithm

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