skip to main content
Diagrammer > Programmer's documentation > Developing hypergraphs > Using more advanced features > Nested hypergraphs
 
Nested hypergraphs
Discusses intergraph hyperedges, how to add and access them.
*Overview
*Provides an overview of nested hypergraphs.
*Intergraph hyperedges
*Defines intergraph hyperedges (a hyperedge with its end nodes in different hypergraphs).
*Adding intergraph hyperedges
*Shows how to add an intergraph hyperedge in a hierarchy of hypergraphs.
*Accessing intergraph hyperedges
*Describes the class and methods used to access intergraph hyperedges.
Overview
Instances of IlvGrapher can be nested and can be collapsed or expanded. Nested graphers allow you to create applications that define graphs that contain subgraphs with links crossing the graph boundaries (intergraph links). See Nested managers and nested graphers in the Advanced Features of JViews Framework user documentation for details.
Similarly, IlvHyperGrapher objects can be nested and can contain intergraph hyperedges..
Nested hypergraphs
Intergraph hyperedges
An intergraph hyperedge is a hyperedge with its end nodes in different hypergraphs.
The end nodes must all belong to the same nested hierarchy, that is, they must all be nested inside the same root hypergraph. The concept of intergraph hyperedges is similar to the concept of intergraph links. See Intergraph links in the Advanced Features of JViews Framework user documentation.
In the following figure, the intergraph hyperedge is shown in red and normal hyperedges are shown in black.
Intergraph hyperedges and normal hyperedges
To test whether a hyperedge in an intergraph hyperedge, call this method of IlvHyperEdge:
 
boolean isInterGraphHyperEdge()
This test method works only when the end nodes are already present in the hypergraphs. Since you can add source and target nodes after a hyperedge has been added to a hypergraph, a normal hyperedge can become an intergraph hyperedge. See the following code example.
How a normal hyperedge can become an intergraph hyperedge
 
IlvHyperGrapher rootGrapher = new IlvHyperGrapher();
...
rootGrapher.addNode(node1, false);
IlvGraphicVector fromNodes = new IlvGraphicVector();
IlvGraphicVector toNodes = new IlvGraphicVector();
fromNodes.addElement(node1);
toNodes.addElement(node1);
IlvHyperEdge edge = new IlvHyperEdge(fromNodes, toNodes);
rootGrapher.addHyperEdge(edge, false);
// the edge is a normal hyperedge
...
 
IlvHyperGrapher subGrapher = new IlvHyperGrapher();
rootGrapher.addNode(subGrapher, true);
subGrapher.addNode(node2, false);
grapher.applyToObject(edge,
  new IlvApplyObject() {
    public void apply(IlvGraphic obj, Object arg) {
      ((IlvHyperEdge)obj).addFrom(node2);
    }
  }, arg, redraw);
// now, the edge is an intergraph hyperedge, since it ends at
// node1 and node2 but both are in different graphers
...
NOTE If the hyperedge is contained in a hypergraph, you can add source or target nodes to the hyperedge only if these nodes belong to the same hypergraph as the hyperedge, or to subgraphs nested inside the hypergraph to which the hyperedge belongs. In all other cases you should remove the hyperedge from its hypergraph and then add the new sources and new targets. Finally, add the hyperedge back to a hypergraph as described in Adding intergraph hyperedges.
Adding intergraph hyperedges
Since the intergraph hyperedge has sources and targets in different hypergraphs, the question arises in which hypergraph the hyperedge is stored. As for intergraph links, an intergraph hyperedge must be stored in the first common ancestor of all its end nodes.
Intergraph hyperedge in a hierarchy of hypergraphs
In the above figure, the red intergraph hyperedge that connects the objects of A and B must be stored in hypergraph C, the first common ancestor of A and B.
The IlvHyperGrapher class provides a static utility method that allows you to determine the first common hypergraph:
 
static IlvHyperGrapher getLowestCommonHyperGrapher(IlvHyperEdge edge)
The following code example shows how to create an intergraph hyperedge.
Creating an intergraph hyperedge
 
...
IlvHyperEdge edge = new IlvHyperEdge(fromNodes, toNodes);
IlvHyperGrapher common = IlvHyperGrapher.getLowestCommonHyperGrapher(edge);
common.addHyperEdge(edge, false);
The static utility method IlvHyperGrapher.addInterGraphHyperEdge allows you to add the edge directly to the common parent hypergraph. Therefore, this code example can be shortened as follows:
Short code for creating an intergraph hyperedge
 
...
IlvHyperEdge edge = new IlvHyperEdge(fromNodes, toNodes);
IlvHyperGrapher.addInterGraphHyperEdge(edge, false);
Accessing intergraph hyperedges
The IlvHyperGrapher class provides methods that let you access in an efficient way normal hyperedges and intergraph hyperedges stored in a hypergraph. These methods are shown in the following table:
Methods for accessing normal and intergraph hyperedges
Method
Description
Returns all normal hyperedges stored in the hypergraph.
Returns the number of normal hyperedges stored in the hypergraph.
Returns all intergraph hyperedges stored in the hypergraph.
Returns the number of intergraph hyperedges stored in the hypergraph.
Since intergraph hyperedges are stored in the same way as other graphic objects in the hypergraph or graph, they are also included in the list of all objects contained in the hypergraph that is returned by the getObjects method of the class IlvManager:
 
IlvGraphicEnumeration getObjects()
Calling the specific methods shown in the above table is much more efficient than traversing all the objects in a hypergraph.

Copyright © 2018, Rogue Wave Software, Inc. All Rights Reserved.