The need for mixing layouts arises when at least one
of the following conditions is met:
- The layout algorithm to be applied on subgraphs is not the same as the algorithm needed for the topmost graph.
- Different layouts need to be applied to different subgraphs.
- The same layout algorithm needs to be applied to different graphs but with different settings.
In these cases of advanced
recursion, where you want to apply different layouts
to different subgraphs, you must specify which layout must be used
for which subgraph. You can specify the node or link layout to use
for any Subgraph by calling the setNodeLayout or setLinkLayout methods
of the Subgraph.
Dojo code example
var diagram = dijit.byId("diagram"); // use a tree layout for the top-level graph: var treeLayout = new ibm_ilog.graphlayout.tree.TreeLayout(); diagram.attr("nodeLayout", treeLayout); // use a grid layout for the first subgraph: var gridLayout = new ibm_ilog.graphlayout.grid.GridLayout(); subgraph1.setNodelayout(gridLayout); // use another tree layout with different parameters for the second subgraph: var treeLayout2 = new ibm_ilog.graphlayout.tree.TreeLayout(); treeLayout2.setFlowDirection(ibm_ilog.graphlayout.Direction.BOTTOM); subgraph2.setNodelayout(treeLayout2 ); // perform layout recursively: diagram.performGraphLayout(true);
If no layout is specified for a given Subgraph,
then the layout of its parent is copied. Thus, you do not need to
set the layout on all subgraphs, but only on subgraphs that require
a different layout or different parameters.