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
must start the layouts in the correct order. This is called recursive layout.
The class
IlvRecursiveLayout
is a subclass of IlvGraphLayout, but it is not a real
layout algorithm. It is rather a facility to apply other layout
algorithms recursively on a nested graph.
The class
IlvRecursiveLayout
can also be used to apply the same layout to all subgraphs. In
fact, when using the API explained in subsection Simple recursion: applying the same layout
to all subgraphs, an instance of
IlvRecursiveLayout
is used internally.
The class
IlvRecursiveLayout
can be used to apply multiple layouts to the same nested graph.
This is necessary if for each subgraph, a node layout and a
separate link layout must be applied.
Further details and code samples of the class
IlvRecursiveLayout
are explained in the following section Recursive
layout.
To apply layout algorithms recursively:
-
Allocate and attach an instance of
IlvRecursiveLayout
. Since it is a subclass ofIlvGraphLayout
, you use the same mechanism as for all other graph layout classes:IlvRecursiveLayout recLayout = new IlvRecursiveLayout(); IlvGrapher topLevelGrapher = ... recLayout.attach(topLevelGrapher);
-
Specify which layout style should be used for each subgraph.You must allocate an individual instance of
IlvGraphLayout
for each subgraph.recLayout.setLayout(subgraph1, new IlvTreeLayout()); recLayout.setLayout(subgraph2, new IlvBusLayout()); recLayout.setLayout(subgraph3, new IlvGridLayout());
-
Set the layout parameters of these individual layouts of the subgraphs as needed.
-
Apply the recursive layout to the top-level grapher. This automatically applies the sublayouts to the subgraphs as well. You use the same method as for all other graph layout classes, because
IlvRecursiveLayout
is a subclass ofIlvGraphLayout
.try { recLayout.performLayout(); } catch (IlvGraphLayoutException e) { System.err.println(e.getMessage()); }
-
Detach the recursive layout from the top-level grapher when it is no longer needed. This automatically detaches all sublayouts from all subgraphers.
recLayout.detach();