Choosing the layout algorithm dynamically

If nothing is known about the graphs that the application needs to lay out, the developer can write a routine that automatically chooses the layout algorithm at run time. The following simple rules could be applied:
  1. If the nodes of the graph cannot be moved (they are geopositioned), use a Link Layout.
  2. If the graph is a tree, use the Tree Layout.
  3. Otherwise, use one of the layout algorithms that are less restricted to a specific category of graph, especially the Force-directed Layout. (The preferred length of the links could also be computed with respect to the size of the nodes.)
  4. If the graph is too large, apply a “divide-and-conquer” strategy. Cut the graph into several subgraphs and apply the layout separately to each subgraph. If the graph is disconnected, you can use the built-in support provided by the layout library to perform this task automatically. (See Layout of connected components.)