Search this API

y.layout.hierarchic
Class AlignmentDrawer

java.lang.Object
  extended by y.layout.hierarchic.AlignmentDrawer
All Implemented Interfaces:
Drawer

public class AlignmentDrawer
extends java.lang.Object
implements Drawer

This class rearranges the nodes within the layers calculated by the HierarchicLayouter such that they are aligned according to the user's specifications.

This class can be used for wrapping another Drawer implementation.

It will rearrange nodes that belong to the same layer such that they are aligned within the layer with respect to a given alignment point, given by a registered AlignmentDrawer.TopAlignmentDataProvider that may provide double values that are interpreted as relative coordinates to the center of the node.

 
Your browser does not support SVG content.

Nested Class Summary
static class AlignmentDrawer.BottomAlignmentDataProvider
          A DataProvider that will make all nodes bottom-aligned (in top-to-bottom layouts) when registered.
static class AlignmentDrawer.LeftAlignmentDataProvider
          A DataProvider that will make all nodes left-aligned (in left-to-right layouts) when registered.
static class AlignmentDrawer.RightAlignmentDataProvider
          A DataProvider that will make all nodes right-aligned (in left-to-right layouts) when registered.
static class AlignmentDrawer.TopAlignmentDataProvider
          A DataProvider that will make all nodes top-aligned (in top-to-bottom layouts) when registered.
 
Field Summary
static java.lang.Object NODE_ALIGNMENT_POINT_DPKEY
          A DataProvider key for depicting the center anchored offset to the alignment point.
 
Fields inherited from interface y.layout.hierarchic.Drawer
NODE_BORDER_BOTTOM, NODE_BORDER_LEFT, NODE_BORDER_RIGHT, NODE_BORDER_TOP, NODE_DISTANCE
 
Constructor Summary
AlignmentDrawer(Drawer inner)
          Creates an AlignmentDrawer instance using the given Drawer instance as the actual drawer.
 
Method Summary
protected  void alignNodes(LayoutGraph graph, NodeList[] layerLists)
          Modifies the given drawing by modifying the y-coordinates only.
 void assignCoordinates(LayoutGraph graph, NodeList[] layerLists, DataProvider layerID)
          Modifies the coordinates retrieved from the wrapped drawer in order to make the y-coordinates comply with the desired node alignment within the layers.
 void setDummyMap(NodeMap dummyMap)
          Specifies a NodeMap instance for identifying the dummy nodes from the real ones.
 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

NODE_ALIGNMENT_POINT_DPKEY

public static final java.lang.Object NODE_ALIGNMENT_POINT_DPKEY
A DataProvider key for depicting the center anchored offset to the alignment point.

More precisely, this AlignmentDrawer.TopAlignmentDataProvider returns a value representing the desired alignment for each node, e.g., 0.5 * height(node) corresponds to bottom alignment, -0.5 * height(node) corresponds to top alignment, 0.5 * width(node) corresponds to right alignment, -0.5 * width(node) corresponds to left alignment and 0 to center alignment.

Constructor Detail

AlignmentDrawer

public AlignmentDrawer(Drawer inner)
Creates an AlignmentDrawer instance using the given Drawer instance as the actual drawer.

Parameters:
inner - the given Drawer instance
Throws:
java.lang.IllegalArgumentException - if the given instance is null
Method Detail

alignNodes

protected void alignNodes(LayoutGraph graph,
                          NodeList[] layerLists)
Modifies the given drawing by modifying the y-coordinates only.

This method recalculates the height of each layer based on the heights of the nodes that belong to each layer and the desired alignment. It also modifies the y-coordinates of the nodes such that they comply with the desired alignment.

It is called by assignCoordinates(LayoutGraph, NodeList[], DataProvider) and can be overridden for custom calculation of the y-coordinates.

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

assignCoordinates

public void assignCoordinates(LayoutGraph graph,
                              NodeList[] layerLists,
                              DataProvider layerID)
Modifies the coordinates retrieved from the wrapped drawer in order to make the y-coordinates comply with the desired node alignment within the layers.

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

setDummyMap

public void setDummyMap(NodeMap dummyMap)
Description copied from interface: Drawer
Specifies a NodeMap instance for identifying the dummy nodes from the real ones.

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

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

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 edges sharing source/target
Throws:
java.lang.IllegalArgumentException - if the minimum distance is negative
Sample Graphs:

Layer distance 40

Layer 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

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

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