skip to main content
Programmer's documentation > Using graph layout algorithms > Nested layouts > Layout of nested graphs in Rogue Wave JViews Diagrammer
 
Layout of nested graphs in Rogue Wave JViews Diagrammer
Describes how to use styling and SDM renderers with nested graphs to perform graph layout.
*Nested SDM models and nested graphers
*Explains how nested graphs relate to SDM models.
*Specification in CSS for nested graphs
*Explains how to specify the layout of nested graphs in CSS.
*Accessing sublayouts of subgraphs
*Explains how to access sublayouts of subgraphs.
Nested SDM models and nested graphers
Rogue Wave®  JViews Diagrammer uses an SDM data model that specifies the application objects (also called model objects). The data model contains nested graphs if any model objects have a parent-child relationship. The parent-child relationship is expressed in the interface IlvSDMModel by the following two methods:
 
Enumeration getChildren(Object parent);
 
Object getParent(Object parent);
If for any model node, the call model.getChildren(node) returns a non-null value, then this model node is a subgraph and all its child nodes must return this node as their parent. In this case, the entire SDM model is called nested.
The SubGraph renderer translates a nested SDM model into a display of nested graphers. A nested grapher is an instance of IlvGrapher that contains other instances of IlvGrapher as graphic nodes. A subgrapher can be expanded (its inner node and links are shown) or collapsed (its contents is hidden and the collapsed subgrapher looks like a normal node). The SubGraph renderer is responsible only for creating the nested graphers and managing the collapse/expand state, but it does not perform any layout on the nested graphers. For more details on the SubGraph renderer, see The SubGraph renderer in JViews Diagrammer SDK.
Specification in CSS for nested graphs
In a diagram component, a recursive layout instance is used internally and is called automatically when needed. In Rogue Wave®  JViews Diagrammer, the handling of nested graphs is thus completely automatic.
Layout renderers perform the layout of nested graphs. The node layout renderer performs the arrangement of the nodes, and depending on the layout style, also the reshaping of the normal links (for example, in Hierarchical or Tree Layout). The link layout renderer performs the arrangement of the links, in particular of the intergraph links. The label layout renderer places all labels in the nested graph.
NOTE If the nested graph has intergraph links, the link layout renderer must be enabled, otherwise the intergraph links will not be routed at all.
Same layout style everywhere
By default, layout renderers apply the same layout style to all subgraphs. The following example shows a specification in CSS that applies the Tree layout to all subgraphs.
 
SDM {
    GraphLayout: "true";
    LinkLayout: "true";
}
 
GraphLayout {
    graphLayout: "Tree";
}
 
LinkLayout {
    layoutMode: "LONG_LINKS";
    interGraphLinksMode: "true";
    combinedInterGraphLinksMode: "false";
}
This example specifies that the Tree layout algorithm is applied to all nodes and links. The Link layout algorithm is applied only to the intergraph links, not to the normal links. The IlvLinkLayout instance is in mode LONG_LINKS, because intergraph links are often very long.
If you change the specification in the LinkLayout section to:
 
interGraphLinksMode: "true";
combinedInterGraphLinksMode: "true";
the Link layout algorithm is applied to both normal links and intergraph links.
If you change the specification in the LinkLayout section to:
 
interGraphLinksMode: "false";
the Link layout algorithm is applied only to normal links, not to intergraph links. The intergraph links are in this case not routed at all. Of course, this is useful only if the graph does not contain any intergraph links.
Since the link layout renderer can reuse the Hierarchical layout as the link layout, the specification is slightly more comfortable, as shown in the following example:
 
SDM {
    GraphLayout: "true";
    LinkLayout: "true";
}
 
GraphLayout {
    graphLayout: "Hierarchical";
}
 
LinkLayout {
    hierarchical: "true";
    interGraphLinksMode: "true";
}
If the hierarchical flag of the link layout renderer is set to true, the normal links are routed by the Hierarchical layout. However, the intergraph links are routed by an instance of IlvLinkLayout, independent from the combinedInterGraphLinksMode setting.
Individual layout styles per subgraph
It is possible to specify the graph layout style for each subgraph individually. To do so, you need to create a style rule that selects the corresponding subgraph, like this:
 
#subgraph15 {
    GraphLayout: "@#sublayout15";
}
 
Subobject#sublayout15 {
    class: "ilog.views.graphlayout.tree.IlvTreeLayout";
    flowDirection: "Right";
... further parameters of Tree layout ...
}
In the SDM model, the subgraph with ID “ subgraph15 ” is selected by the first rule. The rule specifies that an object with ID “ sublayout15 ” must be created. The name sublayout15 is arbitrary and has the only purpose of distinguishing it from all other objects. The second rule selects the object “ sublayout15 ” that must be created, and specifies that this is a Tree layout. As result, a Tree layout is applied to the subgraph.
If the layout of an individual subgraph uses only default parameters, it can be specified in a shorter way, because no parameters need to be set:
 
#subgraph15 {
    GraphLayout: "Tree";
}
NOTE Specifying hierarchical: "true" for the link layout works only if no individual layout styles are specified per subgraph. It works only if the entire nested graph is laid out by Hierarchical layout.
Accessing sublayouts of subgraphs
Internally, the graph layout renderer uses a different instance of IlvGraphLayout for each nested graph. In Accessing graph layout instances, we mentioned how to access the layout instance of the node layout renderer:
 
nodeLayoutRenderer.getGraphLayout();
This returns the layout instance of the top-level grapher.
The following example shows how to access all graph layout instances of all subgraphs.
 
IlvSDMEngine engine = diagrammer.getEngine();
Enumeration e = engine.getNodeLayoutRenderer().getLayouts(engine, true);
while (e.hasMoreElements()) {
  IlvGraphLayout layout = (IlvGraphLayout)e.nextElement();
  ... do something with this layout instance ...
}
You can also access the layout instance of an individual subgrapher, by using the following method of IlvGraphLayoutRenderer:
 
getGraphLayout(IlvSDMEngine engine, IlvGrapher grapher);
The mechanism for accessing the different link layout instances of a link layout renderer is exactly the same.
The API of the graph layout and link layout renderers is documented in the Java™ API Reference Manual of the classes IlvGraphLayoutRenderer and IlvLinkLayoutRenderer.

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