Search this API

y.layout.hierarchic
Class AbstractDrawer

java.lang.Object
  extended by y.layout.hierarchic.AbstractDrawer
All Implemented Interfaces:
Drawer
Direct Known Subclasses:
LinearSegmentsDrawer, MedianLinearSegmentDrawer, PendularDrawer, PolylineDrawer, SimplexDrawer, TreeDrawer

public abstract class AbstractDrawer
extends java.lang.Object
implements Drawer

This is an abstract base class that implements the drawing phase of the hierarchic layout algorithm.

This class assigns the coordinates to the nodes according to the defined layers. It also provides methods to assign the corresponding y-coordinates.

AbstractDrawer is used by the HierarchicLayouter for assigning the node coordinates and implementations of this class are used for determining specific layout styles (see HierarchicLayouter.setLayoutStyle(byte).

 

Field Summary
protected  NodeMap distanceToNextNode
          Stores the minimum distance between the right border of a node and the left border of its right-hand side neighbor in a layer.
protected  NodeMap dummyMap
          A NodeMap used for identifying dummy nodes.
protected  java.lang.Object edgeLengthKey
          Key for registering a data provider which stores the length of the edges.
protected  LayoutGraph graph
          The graph bound to this drawer instance.
protected  double minimalEdgeDistance
          The minimum distance between two edges in the same layer.
protected  double minimalLayerDistance
          The minimum distance between two layers.
protected  double minimalMultiEdgeDistance
          The minimum distance between two edges sharing source/target in the same layer.
protected  double minimalNodeDistance
          The minimum distance between two nodes in the same layer.
 
Fields inherited from interface y.layout.hierarchic.Drawer
NODE_BORDER_BOTTOM, NODE_BORDER_LEFT, NODE_BORDER_RIGHT, NODE_BORDER_TOP, NODE_DISTANCE
 
Constructor Summary
protected AbstractDrawer()
          Creates an instance of AbstractDrawer with default settings.
 
Method Summary
 void assignCoordinates(LayoutGraph graph, NodeList[] layerLists, DataProvider layerID)
          Assigns coordinates to the nodes of the given graph.
protected abstract  void assignCoordinates(NodeList[] layerLists, DataProvider layerID)
          Assigns the final coordinates to the objects of the graph.
 void assignYCoords(LayoutGraph graph, NodeCursor[] layerCursors)
          Assigns the y-coordinates to the nodes respecting the minimum layer distance.
 void assignYCoords(LayoutGraph graph, NodeList[] layerLists)
          Assigns the y-coordinates to the nodes respecting the minimum layer distance.
protected  void dispose()
          Disposes of allocated resources after the drawer is finished.
 double getBottomBorder(Node node)
          Returns the height of the bottom border of the given node.
 double getBottomHalf(Node node)
          Returns the sum of half the height of the node and its bottom border.
 double getBottomY(Node node)
          Returns the bottommost y-coordinate of the node when considering the bottom border of the node.
protected  double getDistanceToNextNode(Node node)
          Returns the minimum distance between the right border of the given node and the left border of its right-hand side neighbor in the layer.
 double getFullHeight(Node node)
          Returns the height of the node when considering the top and the bottom borders of the node.
 double getFullWidth(Node node)
          Returns the width of the node when considering the left and the right borders of the node.
 double getLeftBorder(Node node)
          Returns the width of the left border of the given node.
 double getLeftHalf(Node node)
          Returns the sum of half the width of the node and its left border.
 double getLeftX(Node node)
          Returns the leftmost x-coordinate of the node when considering the left border of the node.
 double getMinimalEdgeDistance()
          Returns the minimum distance between two edges in the same layer.
 double getMinimalLayerDistance()
          Returns the minimum distance between two layers.
 double getMinimalMultiEdgeDistance()
          Returns the minimum distance between two edges sharing source/target in the same layer.
 double getMinimalNodeDistance()
          Returns the minimum distance between two nodes in the same layer.
 double getRightBorder(Node node)
          Returns the width of the right border of the given node.
 double getRightHalf(Node node)
          Returns the sum of half the width of the node and its right border.
 double getRightX(Node node)
          Returns the rightmost x-coordinate of the node when considering the right border of the node.
 double getTopBorder(Node node)
          Returns the height of the top border of the given node.
 double getTopHalf(Node node)
          Returns the sum of half the height of the node and its top border.
 double getTopY(Node node)
          Returns the topmost y-coordinate of the node when considering the top border of the node.
protected  void initializeDistancesToNextNode(NodeList[] layerLists)
          Initializes the minimum distances between the right border of a node and the left border of its right-hand side neighbor in a layer.
 void setDummyMap(NodeMap dummyMap)
          Specifies a NodeMap instance for identifying the dummy nodes from the real nodes.
 void setEdgeLengthKey(java.lang.Object key)
          Specifies the key for the DataProvider which stores the length of the edges.
 void setMinimalEdgeDistance(double d)
          Specifies the minimum distance between two edges that span the same layer.
 void setMinimalLayerDistance(double d)
          Specifies the minimum distance between two layers.
 void setMinimalMultiEdgeDistance(double d)
          Specifies the minimum distance between two edges sharing source/target in the same layer.
 void setMinimalNodeDistance(double d)
          Specifies the minimum distance between two nodes in the same layer.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

minimalNodeDistance

protected double minimalNodeDistance
The minimum distance between two nodes in the same layer.


minimalLayerDistance

protected double minimalLayerDistance
The minimum distance between two layers.


minimalEdgeDistance

protected double minimalEdgeDistance
The minimum distance between two edges in the same layer.


minimalMultiEdgeDistance

protected double minimalMultiEdgeDistance
The minimum distance between two edges sharing source/target in the same layer.


dummyMap

protected NodeMap dummyMap
A NodeMap used for identifying dummy nodes.

It returns the original edge for each dummy node or null for real nodes.

See Also:
setDummyMap(NodeMap)

edgeLengthKey

protected java.lang.Object edgeLengthKey
Key for registering a data provider which stores the length of the edges. More precisely, the corresponding DataProvider maps each edge of the input graph to a double value representing the edge's length.


graph

protected LayoutGraph graph
The graph bound to this drawer instance.


distanceToNextNode

protected NodeMap distanceToNextNode
Stores the minimum distance between the right border of a node and the left border of its right-hand side neighbor in a layer.

For each node, a double value is stored representing this minimum distance.

Constructor Detail

AbstractDrawer

protected AbstractDrawer()
Creates an instance of AbstractDrawer with default settings.

Method Detail

setMinimalEdgeDistance

public void setMinimalEdgeDistance(double d)
Specifies the minimum distance between two edges that span the same layer.

Minimum distance must be non-negative.

Specified by:
setMinimalEdgeDistance in interface Drawer
Default Value:
The default value is 5.0.
Parameters:
d - the minimum distance between two edges
Throws:
java.lang.IllegalArgumentException - if the minimum distance is negative
Sample Graphs:

Edge distance 10

Edge distance 100

setMinimalMultiEdgeDistance

public void setMinimalMultiEdgeDistance(double d)
Specifies the minimum distance between two edges sharing source/target in the same layer.

Minimum distance must be non-negative.

Specified by:
setMinimalMultiEdgeDistance in interface Drawer
Default Value:
The default value is 0.0.
Parameters:
d - the minimum distance between two edges sharing source/target
Throws:
java.lang.IllegalArgumentException - if the minimum distance is negative
Sample Graphs:

Multi-edge distance 10

Multi-edge distance 200

getMinimalEdgeDistance

public double getMinimalEdgeDistance()
Returns the minimum distance between two edges in the same layer.

Minimum distance must be non-negative.

Returns:
the minimum distance between two edges
See Also:
setMinimalEdgeDistance(double)

getMinimalMultiEdgeDistance

public double getMinimalMultiEdgeDistance()
Returns the minimum distance between two edges sharing source/target in the same layer.

Minimum distance must be non-negative.

Returns:
the minimum distance between two edges sharing source/target
See Also:
setMinimalNodeDistance(double)

setMinimalNodeDistance

public void setMinimalNodeDistance(double d)
Specifies the minimum distance between two nodes in the same layer.

Minimum distance must be non-negative.

Specified by:
setMinimalNodeDistance in interface Drawer
Default Value:
The default value is 20.0.
Parameters:
d - the minimum distance between two edges sharing source/target
Throws:
java.lang.IllegalArgumentException - if the minimum distance is negative
Sample Graphs:

Node distance 20

Node distance 100

setMinimalLayerDistance

public void setMinimalLayerDistance(double d)
Specifies the minimum distance between two layers.

Minimum distance must be non-negative.

Specified by:
setMinimalLayerDistance in interface Drawer
Default Value:
The default value is 60.0.
Parameters:
d - the minimum distance between two layers
Throws:
java.lang.IllegalArgumentException - if the minimum distance is negative
Sample Graphs:

Layer distance 40

Layer distance 100

setDummyMap

public void setDummyMap(NodeMap dummyMap)
Specifies a NodeMap instance for identifying the dummy nodes from the real nodes.

Specified by:
setDummyMap in interface Drawer
Parameters:
dummyMap - the NodeMap that returns the original edge for each dummy node or null for real nodes

getMinimalNodeDistance

public double getMinimalNodeDistance()
Returns the minimum distance between two nodes in the same layer.

Minimum distance must be non-negative.

Returns:
the minimum distance between two nodes
See Also:
setMinimalNodeDistance(double)

getMinimalLayerDistance

public double getMinimalLayerDistance()
Returns the minimum distance between two layers.

Minimum distance must be non-negative.

Returns:
the minimum distance between two layers
See Also:
setMinimalLayerDistance(double)

setEdgeLengthKey

public void setEdgeLengthKey(java.lang.Object key)
Specifies the key for the DataProvider which stores the length of the edges.

 
Edges which are split in the first phase, do no longer supply lengths. This should not be too critical as they span at least two layers and so are hopefully long enough.
Parameters:
key - the given DataProvider key

assignYCoords

public void assignYCoords(LayoutGraph graph,
                          NodeList[] layerLists)
Assigns the y-coordinates to the nodes respecting the minimum layer distance.

This methods calls assignYCoords(LayoutGraph, NodeCursor[]) for each node in the given list.

Parameters:
graph - the graph
layerLists - an array of NodeLists each of which contains nodes that belong to the same layer

assignYCoords

public void assignYCoords(LayoutGraph graph,
                          NodeCursor[] layerCursors)
Assigns the y-coordinates to the nodes respecting the minimum layer distance.

Nodes that belong to the same layers are assigned the same y-coordinates if they are of the same size. Else, the y-coordinates are calculated based on the height of each node and on the maximum height of the nodes that each layer contains while respecting the minimum layer distance between layers.

Parameters:
graph - the graph
layerCursors - an array of NodeCursors each of which iterates over nodes that belong to the same layer

assignCoordinates

public void assignCoordinates(LayoutGraph graph,
                              NodeList[] layerLists,
                              DataProvider layerID)
Assigns coordinates to the nodes of the given graph.

This method binds the specified graph to this drawer and calls the abstract method assignCoordinates(NodeList[],DataProvider).

Specified by:
assignCoordinates in interface Drawer
Parameters:
graph - the input graph
layerLists - an array of NodeLists each of which contains nodes that belong to the same layer
layerID - the DataProvider that returns the zero-based index of the layer to which each node belongs

assignCoordinates

protected abstract void assignCoordinates(NodeList[] layerLists,
                                          DataProvider layerID)
Assigns the final coordinates to the objects of the graph.

This method is called by HierarchicLayouter.doLayoutCore(LayoutGraph) after the nodes are distributed in layers. It has to be implemented to assign the final coordinates to the objects of the graph based on the user's specifications.

Parameters:
layerLists - an array of NodeLists each of which contains nodes that belong to the same layer
layerID - the DataProvider that returns the zero-based index of the layer to which each node belongs

getLeftX

public double getLeftX(Node node)
Returns the leftmost x-coordinate of the node when considering the left border of the node.

The left borders are specified by a DataProvider registered with the graph using key Drawer.NODE_BORDER_LEFT.

Parameters:
node - the given node
Returns:
the leftmost x-coordinate of the node when considering the left border of the node

getRightX

public double getRightX(Node node)
Returns the rightmost x-coordinate of the node when considering the right border of the node.

The right borders are specified by a DataProvider registered with the graph using key Drawer.NODE_BORDER_RIGHT.

Parameters:
node - the given node
Returns:
the rightmost x-coordinate of the node when considering the right border of the node

getTopY

public double getTopY(Node node)
Returns the topmost y-coordinate of the node when considering the top border of the node.

The top borders are specified by a DataProvider registered with the graph using key Drawer.NODE_BORDER_TOP.

Parameters:
node - the given node
Returns:
the topmost y-coordinate of the node when considering the top border of the node

getBottomY

public double getBottomY(Node node)
Returns the bottommost y-coordinate of the node when considering the bottom border of the node.

The bottom borders are specified by a DataProvider registered with the graph using key Drawer.NODE_BORDER_BOTTOM.

Parameters:
node - the given node
Returns:
the bottommost y-coordinate of the node when considering the bottom border of the node

getFullWidth

public double getFullWidth(Node node)
Returns the width of the node when considering the left and the right borders of the node.

The right and left borders are specified by DataProviders registered with the graph using keys Drawer.NODE_BORDER_RIGHT and Drawer.NODE_BORDER_LEFT, respectively.

Parameters:
node - the given node
Returns:
the width of the node when considering the left and the right borders of the node

getFullHeight

public double getFullHeight(Node node)
Returns the height of the node when considering the top and the bottom borders of the node.

The top and bottom borders are specified by DataProviders registered with the graph using keys Drawer.NODE_BORDER_TOP and Drawer.NODE_BORDER_BOTTOM, respectively.

Parameters:
node - the given node
Returns:
the height of the node when considering the top and the bottom borders of the node

getLeftBorder

public double getLeftBorder(Node node)
Returns the width of the left border of the given node.

The left borders are specified by a DataProvider registered with the graph using key Drawer.NODE_BORDER_LEFT.

Parameters:
node - the given node
Returns:
the width of the left border of the given node

getRightBorder

public double getRightBorder(Node node)
Returns the width of the right border of the given node.

The right borders are specified by a DataProvider registered with the graph using key Drawer.NODE_BORDER_RIGHT.

Parameters:
node - the given node
Returns:
the width of the right border of the given node

getTopBorder

public double getTopBorder(Node node)
Returns the height of the top border of the given node.

The top borders are specified by a DataProvider registered with the graph using key Drawer.NODE_BORDER_TOP.

Parameters:
node - the given node
Returns:
the height of the top border of the given node

getBottomBorder

public double getBottomBorder(Node node)
Returns the height of the bottom border of the given node.

The bottom borders are specified by a DataProvider registered with the graph using key Drawer.NODE_BORDER_BOTTOM.

Parameters:
node - the given node
Returns:
the height of the bottom border of the given node

getLeftHalf

public double getLeftHalf(Node node)
Returns the sum of half the width of the node and its left border.

The left borders are specified by a DataProvider registered with the graph using key Drawer.NODE_BORDER_LEFT.

Parameters:
node - the given node
Returns:
the sum of half the width of the node and its left border

getRightHalf

public double getRightHalf(Node node)
Returns the sum of half the width of the node and its right border.

The right borders are specified by a DataProvider registered with the graph using key Drawer.NODE_BORDER_RIGHT.

Parameters:
node - the given node
Returns:
the sum of half the width of the node and its right border

getTopHalf

public double getTopHalf(Node node)
Returns the sum of half the height of the node and its top border.

The top borders are specified by a DataProvider registered with the graph using key Drawer.NODE_BORDER_TOP.

Parameters:
node - the given node
Returns:
the sum of half the height of the node and its top border

getBottomHalf

public double getBottomHalf(Node node)
Returns the sum of half the height of the node and its bottom border.

The bottom borders are specified by a DataProvider registered with the graph using key Drawer.NODE_BORDER_BOTTOM.

Parameters:
node - the given node
Returns:
the sum of half the height of the node and its bottom border

initializeDistancesToNextNode

protected void initializeDistancesToNextNode(NodeList[] layerLists)
Initializes the minimum distances between the right border of a node and the left border of its right-hand side neighbor in a layer.

This method is called by assignCoordinates(LayoutGraph, NodeList[], DataProvider) before the node coordinates assignment is performed. It may be overridden to calculate the minimum distances between nodes in a different way.

Parameters:
layerLists - an array of NodeLists, each of which contains nodes that belong to the same layer
See Also:
getDistanceToNextNode(Node), distanceToNextNode

getDistanceToNextNode

protected double getDistanceToNextNode(Node node)
Returns the minimum distance between the right border of the given node and the left border of its right-hand side neighbor in the layer.

Minimum node distances are constructed by using the values provided by the DataProviders that are registered with the input graph using keys Drawer.NODE_DISTANCE, Drawer.NODE_BORDER_LEFT and Drawer.NODE_BORDER_RIGHT.

Parameters:
node - the given node
Returns:
the minimum distance between the right border of the given node and the left border of its right-hand side neighbor

dispose

protected void dispose()
Disposes of allocated resources after the drawer is finished.

This method disposes of the NodeMap that stores the minimum distance between the right border of a node and the left border of its right-hand side neighbor in a layer.

It may be overridden for custom configurations.


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