
Search this API  
PREV CLASS NEXT CLASS  FRAMES NO FRAMES  
SUMMARY: NESTED  FIELD  CONSTR  METHOD  DETAIL: FIELD  CONSTR  METHOD 
java.lang.Object y.layout.grouping.Grouping
public class Grouping
This class provides convenient and efficient access to the hierarchic graph structure.
The grouping information is provided through DataProvider
s registered with the graph with keys
GroupingKeys.NODE_ID_DPKEY
, GroupingKeys.PARENT_NODE_ID_DPKEY
and GroupingKeys.GROUP_DPKEY
.
It describes the hierarchy as a tree where a group node is the parent of the nodes that it contains.
virtual root
.
Leaf nodes can either be normal nodes or empty groups.
Grouping
is not needed anymore, it should be disposed of
.Field Summary 

Fields inherited from interface y.layout.grouping.GroupingKeys 

GROUP_DPKEY, GROUP_NODE_INSETS_DPKEY, MINIMUM_NODE_SIZE_DPKEY, NODE_ID_DPKEY, PARENT_NODE_ID_DPKEY 
Constructor Summary  

Grouping(Graph graph)
Creates a new Grouping instance that represents the hierarchy of the graph. 
Method Summary  

protected NodeMap 
createInfoMap(Graph graph)
Creates a NodeMap to store hierarchy information for each node. 
void 
dispose()
Disposes of all internal data structures held by this instance . 
protected void 
disposeInfoMap(Graph graph,
NodeMap infoMap)
Disposes of the NodeMap created to store hierarchy information for each node. 
NodeList 
getChildren(Node parent)
Returns the direct children of the given group node. 
NodeList 
getDescendants(Node parent)
Returns all descendants of the given group node. 
EdgeList 
getEdgesGoingIn(Node group)
Returns all edges crossing the bounds of the given group node such that their targets are inside the group node while their sources lie outside the group node. 
EdgeList 
getEdgesGoingOut(Node group)
Returns all edges crossing the bounds of the given group node such that their sources are inside the group node while their targets lie outside the group node. 
Graph 
getGraph()
Returns the Graph instance for which this Grouping object provides hierarchy information. 
LayoutGraph 
getLayoutGraph()
Returns the LayoutGraph instance for which this Grouping object provides hierarchy information. 
Node 
getNearestCommonAncestor(Node node1,
Node node2)
Returns the nearest common ancestor of the given nodes in the hierarchy structure. 
Node 
getParent(Node node)
Returns the parent for the given node. 
Node 
getRepresentative(Node node,
Node group)
Returns an immediate child of the group node that represents the given node. 
Node 
getRoot()
Returns a Node instance associated with the virtual root of the hierarchy tree. 
boolean 
hasChildren(Node node)
Determines whether or not the given node is a group node with children. 
protected void 
init()
Initializes internal data structures. 
static boolean 
isFlat(Graph graph)
Returns whether or not the given graph is flat. 
static boolean 
isGrouped(Graph graph)
Returns whether or not the given graph is grouped. 
boolean 
isGroupNode(Node node)
Determines whether or not the given node is a group node. 
boolean 
isNormalEdge(Edge edge)
Determines whether or not the given edge is a normal edge as opposed to an edge that crosses any group node bounds. 
Methods inherited from class java.lang.Object 

clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait 
Constructor Detail 

public Grouping(Graph graph)
Grouping
instance that represents the hierarchy of the graph.
The hierarchy information is cached during the constructor call. Later modifications to the graph are not
considered and may lead to errors when using this Grouping
instance.
Grouping
holds the current state of the graph instance, it should be
disposed of
once it is not needed anymore.graph
 the graph instance from which the hierarchy information is obtainedMethod Detail 

protected void init()
This method is called from Grouping(Graph)
and retrieves the state of the hierarchic graph at the moment
of invocation. It may be overridden to append additional information used for group handling.
disposed of
if this instance of
Grouping
is not needed anymore.dispose()
public LayoutGraph getLayoutGraph()
LayoutGraph
instance for which this Grouping
object provides hierarchy information.
LayoutGraph
is only possible if this Grouping
is associated with an
instance of LayoutGraph
class.public Graph getGraph()
Graph
instance for which this Grouping
object provides hierarchy information.
null
if this instance was
already disposed of
.protected NodeMap createInfoMap(Graph graph)
NodeMap
to store hierarchy information for each node.
This method is called in init()
and may be overridden to customize how the NodeMap
is created.
graph
 the current graph
NodeMap
init()
,
disposeInfoMap(Graph, NodeMap)
protected void disposeInfoMap(Graph graph, NodeMap infoMap)
NodeMap
created to store hierarchy information for each node.
This method is called in dispose()
and may be overridden to revert changes from
createInfoMap(Graph)
.
graph
 the current graphinfoMap
 the NodeMap
which contains the hierarchy information for each nodedispose()
,
createInfoMap(Graph)
public Node getParent(Node node)
node
 the node for which the parent is determined
null
for a toplevel node
java.lang.IllegalArgumentException
 if the given node is null
getChildren(Node)
,
getDescendants(Node)
,
getNearestCommonAncestor(Node, Node)
public Node getRoot()
Node
instance associated with the virtual root of the hierarchy tree.
This instance can be given to the getChildren(Node)
to obtain the nodes of the top level of the
hierarchy.
Node
instance is not part of the graph.getChildren(Node)
public NodeList getChildren(Node parent)
If the virtual root of the hierarchy tree
is passed, all toplevel nodes are returned.
public NodeList getDescendants(Node parent)
If the virtual root of the hierarchy tree
is passed, all nodes in the graph are returned.
parent
 the group node
getRoot()
,
getParent(Node)
,
getChildren(Node)
The marked nodes are descendants of group node 5 (grouped graph)  The marked nodes are descendants of group node 5 (hierarchy tree) 
public boolean isGroupNode(Node node)
node
 the potential group node
true
if the given node is a group node or is null
, false
otherwisehasChildren(Node)
public boolean hasChildren(Node node)
node
 the potential parent
true
if the given node has children, false
otherwisegetChildren(Node)
,
isGroupNode(Node)
public boolean isNormalEdge(Edge edge)
edge
 the edge to check
true
if the given edge is normal, false
otherwisegetEdgesGoingIn(Node)
,
getEdgesGoingOut(Node)
public EdgeList getEdgesGoingIn(Node group)
public EdgeList getEdgesGoingOut(Node group)
public Node getRepresentative(Node node, Node group)
node
 the node for which a representative is searchedgroup
 the group node to which the representative should belong
null
if the node is not a descendant of the group
java.lang.IllegalArgumentException
 if the given node is null
Node 4 is the representative for node 2 in group node 5 (grouped graph)  Node 4 is the representative for node 2 in group node 5 (hierarchy tree) 
public void dispose()
instance
.
Grouping
should be disposed of when it is not needed anymore, or if the state of the graph changes (e.g.
new nodes are added).
Grouping
instance needs to be created.public static boolean isGrouped(Graph graph)
DataProvider
s registered with the graph with keys
GroupingKeys.GROUP_DPKEY
, GroupingKeys.NODE_ID_DPKEY
and GroupingKeys.PARENT_NODE_ID_DPKEY
.
graph
 the input graph
true
if the graph contains hierarchic information, false
otherwiseisFlat(Graph)
public static boolean isFlat(Graph graph)
graph
 the input graph
true
if there are no groups or only empty groups in the graph, false
otherwiseisGrouped(Graph)
public Node getNearestCommonAncestor(Node node1, Node node2)
The nearest common ancestor is the local root of the smallest subtree in the hierarchy tree that contains both
nodes. This group is the first node that contains these two nodes. If no such node exists, the
virtual root
is returned.
node1 == node2
: the parent of node1
/node2
node1 is parent of node2
: the parent of node1
node2 is parent of node1
: the parent of node2
node1
 one of the two nodes whose common ancestor is determinednode2
 one of the two nodes whose common ancestor is determined
getRoot()
The nearest common ancestor of the nodes 1 and 2 is group node 5 (grouped graph)  The nearest common ancestor of the nodes 1 and 2 is group node 5 (hierarchy tree) 

© Copyright 20002022, yWorks GmbH. All rights reserved. 

PREV CLASS NEXT CLASS  FRAMES NO FRAMES  
SUMMARY: NESTED  FIELD  CONSTR  METHOD  DETAIL: FIELD  CONSTR  METHOD 