Search this API

y.layout.hierarchic
Class ConstraintLayerer

java.lang.Object
  extended by y.layout.hierarchic.ConstraintLayerer
All Implemented Interfaces:
Layerer

public class ConstraintLayerer
extends Object
implements Layerer, Layerer

Layerer implementation that uses relative and absolute layering constraints.

This layerer can use two sets of constraints:

Constraints for a given graph can be created with means of a ConstraintLayerer.ConstraintFactory instance, which should be created with createConstraintFactory(y.base.Graph) for a given graph instance.


Nested Class Summary
static interface ConstraintLayerer.ConstraintFactory
          Interface specification for classes that can create suitable constraints for a ConstraintLayerer instance.
 
Field Summary
static String EDGE_WEIGHTS_DPKEY
          DataProvider key for additional edge weights of type int.
 
Constructor Summary
ConstraintLayerer()
           
ConstraintLayerer(Layerer coreLayerer)
           
 
Method Summary
 void assignLayers(LayoutGraph graph, Layers layers, LayoutDataProvider ldp)
          This method assigns all nodes in the graph to layers and registers them in the Layers instance.
 int assignNodeLayer(LayoutGraph g, NodeMap layer, EdgeList reversedEdges)
          This method assigns the nodes in the graph to layers.
protected  void checkConstraints()
          Checks if the current set of strong constraints is consistent (i.e. has no cycles)
static ConstraintLayerer.ConstraintFactory createConstraintFactory(Graph g)
          Create an instance of ConstraintLayerer.ConstraintFactory that is suitable for this layerer implementation.
 Layerer getCoreLayerer()
          Gets the core layerer for this layerer instance.
 boolean isAllowSameLayerEdges()
          Returns whether same layer edges can be created by this layerer instance.
 void setAllowSameLayerEdges(boolean allowSameLayerEdges)
          Set whether same layer edges can be created by this layerer instance.
 void setCoreLayerer(Layerer coreLayerer)
          Sets the core layerer for this layerer instance.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

EDGE_WEIGHTS_DPKEY

public static final String EDGE_WEIGHTS_DPKEY
DataProvider key for additional edge weights of type int. The Layerer tries to keep edges with higher weights short.

See Also:
Constant Field Values
Constructor Detail

ConstraintLayerer

public ConstraintLayerer(Layerer coreLayerer)

ConstraintLayerer

public ConstraintLayerer()
Method Detail

getCoreLayerer

public Layerer getCoreLayerer()
Gets the core layerer for this layerer instance.

The ConstraintLayerer tries to create a layering for the nodes and edges that have no constraints that resembles the layering that would be created by the coreLayerer. This works the better the less constraints exist. Ideally, the constrained nodes are just embedded into the layering created by the coreLayerer. By default, an instance of TopologicalLayerer is used.

Returns:
the layerer that is used for unconstrained nodes

setCoreLayerer

public void setCoreLayerer(Layerer coreLayerer)
Sets the core layerer for this layerer instance.

The ConstraintLayerer tries to create a layering for the nodes and edges that have no constraints that resembles the layering that would be created by the coreLayerer. This works the better the less constraints exist. Ideally, the constrained nodes are just embedded into the layering created by the coreLayerer. By default, an instance of TopologicalLayerer is used.

Parameters:
coreLayerer - the layerer that is used for unconstrained nodes

isAllowSameLayerEdges

public boolean isAllowSameLayerEdges()
Returns whether same layer edges can be created by this layerer instance.

This only concerns edges between nodes that have no hard constraints that will force a same layer edge (i.e. a same layer constraint).

Default value is false.

Returns:
true iff unconstrained same layer edges are allowed.

setAllowSameLayerEdges

public void setAllowSameLayerEdges(boolean allowSameLayerEdges)
Set whether same layer edges can be created by this layerer instance.

This only concerns edges between nodes that have no hard constraints that will force a same layer edge (i.e. a same layer constraint).

Default value is false.

Parameters:
allowSameLayerEdges - true iff unconstrained same layer edges are allowed.

assignNodeLayer

public int assignNodeLayer(LayoutGraph g,
                           NodeMap layer,
                           EdgeList reversedEdges)
This method assigns the nodes in the graph to layers.

Throws:
IllegalArgumentException - if any strong constraints are inconsistent
Parameters:
g - the graph for which the layers are determined.
layer - here the layers are stored
reversedEdges - here the edges are stored which had been reversed.
Returns:
the number of layers

checkConstraints

protected void checkConstraints()
Checks if the current set of strong constraints is consistent (i.e. has no cycles)

Throws:
IllegalArgumentException - if the constraint network is inconsistent

assignLayers

public void assignLayers(LayoutGraph graph,
                         Layers layers,
                         LayoutDataProvider ldp)
Description copied from interface: Layerer
This method assigns all nodes in the graph to layers and registers them in the Layers instance. In order to create new layers, the factory method Layers.insert(byte, int) must be used.

Specified by:
assignLayers in interface Layerer
Parameters:
graph - the graph that contains the nodes that should be distributed into the layers
layers - the object that will be filled with the results of the calculation
ldp - LayoutDataProvider that can be used to query information about the nodes - note that positional information (see NodeData.getPosition() and NodeData.getLayer()) cannot be available at any time.
See Also:
Layers.insert(byte, int), Layer.add(y.base.Node)

createConstraintFactory

public static ConstraintLayerer.ConstraintFactory createConstraintFactory(Graph g)
Create an instance of ConstraintLayerer.ConstraintFactory that is suitable for this layerer implementation. The ConstraintFactory instance is usually bound to the graph instance g, i.e. if the input graph for the layerer changes, a new ConstraintFactory instance must be retrieved. This instance can be used to create constraints for this graph instance.

You can create a ConstraintFactory without binding it to a graph instance initially by passing a null parameter. In that case, you must bind the returned instance to the graph instance before calculating a layering:

 ConstraintFactory cf = ConstraintLayerer.createConstraintFactory(null);
 ...
 Graph g = ...;
 g.addDataProvider(ConstraintFactory.LAYER_CONSTRAINTS_MEMENTO_DPKEY,
    DataProviders.createConstantDataProvider(cf.getMemento())););
 //Calculate layout
 

If you manually registered a DataProvider under Layouter.NODE_ID_DPKEY on the graph, you must use the corresponding node ids stored in this DataProvider as arguments for all methods that create a constraint. Otherwise, you can just use the node instances themselves.

Parameters:
g - the current graph for the layerer
Returns:
a ConstraintFactory bound to this graph.
See Also:
ConstraintLayerer.ConstraintFactory.getMemento(), ConstraintLayerer.ConstraintFactory.LAYER_CONSTRAINTS_MEMENTO_DPKEY

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