You can apply the same layout where both the following
conditions hold:
- The same layout algorithm needs to be applied to the topmost graph and all its subgraphs.
- The settings of the layout algorithm (that is, the layout parameters) need to be the same for the topmost graph as for all the subgraphs.
The following figure shows an example where a Tree Layout
is applied to the topmost graph as well as to all its subgraphs. Moreover,
the settings of the Tree Layout algorithm are the same for all the
graphs: the application does not need, for example, one flow direction
in the topmost graph and a different one in the subgraphs.

Example of a recursive layout of a nested graph
Obtaining such recursive layouts is easy. You must specify
the graph layout on the top-level Diagram or Graph instance
and call the performGraphLayout method.
The layout is done recursively, because the recursive argument
of the method is
true
by default. Internal mechanism
The internal mechanism is based on the principle that
a layout instance is used for only one graph and is not reused for
its subgraphs. Therefore, the Tree Layout instance is automatically
“cloned” using the ibm_ilog.graphlayout.GraphLayout.copy() method.
The graph layout is applied to a graph model, and the
same principle holds for the graph models: a graph model instance
is used for only one graph and is not reused for subgraphs.
The graph models for the subgraphs are created by calls
to the ibm_ilog.graphlayout.GraphLayout.copy() method,
which in turn creates the graph model using the method ibm_ilog.graphlayout.GraphLayout.getGraphModel().
All these operations are done automatically, in a transparent
way. All you have to do is to call the method
performGraphLayout
with
the recursive
argument set to true
or
omitted. Dojo code example
The following code example shows how to apply a single
layout algorithm to a nested graph:
var diagram = dijit.byId("diagram"); var treeLayout = new ibm_ilog.graphlayout.tree.TreeLayout(); diagram.attr("nodeLayout", treeLayout); diagram.performGraphLayout(true);