In this example, we want to produce an orthogonal layout of an ER-diagram. We will use the class PlanarizationLayout which implements the planarization approach for drawing graphs. This approach divides the layout process into two steps: The crossing minimization step seeks for a planarized representation of the graph with as few crossings as possible (a planarized representation is a planar graph, where a dummy vertex is “put” on each edge crossing) and the planar layout step applies a planar drawing algorithm (usually an orthogonal layout algorithm) to the planarized representation. The final layout is then simply obtained by replacing the dummy vertices again with edge crossings.

In our example, we proceed as follows. First, we declare a GraphG with GraphAttributesGA storing all the layout information we need (these include in our case also colors and line styles, since these shall be preserved in the output GML file). Then, we declare an instance pl of PlanarizationLayout and set various module options:

The crossing minimization step consists of computing a planar subgraph and reinserting the remaining edges. We use FastPlanarSubgraph for computing the planar subgraph and set its number of randomized runs to 100, and we use VariableEmbeddingInserter with very high postprocessing (EdgeInsertionModule::rrAll) as edge inserter, giving us a high-quality crossing minimization heuristic.

The computed (planar) orthogonal layout is influenced by the choice of the planar embedding and planar layout algorithm. We use an algorithm that minimizes the block nesting depth and tries to have large faces at the outside of the drawing (EmbedderMinDepthMaxFaceLayers), since such embeddings are well-suited for clear planar layouts. Our planar layout algorithm is OGDF's standard orthogonal layout, but we need to set it as module option, since we want to adjust the spacing parameters. The separation specifies the minimum distance between vertices and edges, the cOverhang specifies how close edges can attach at vertex corners (in this case 40% of the node size, but the algorithm can also reduce this if required), and the additional options which are set to 2+4 turn on the scaling and progressive options of OrthoLayout.

Finally, we call the planarization layout algorithm in the usual way by passing the graph attributes object, which will then be assigned the produced layout. This layout is saved in the file er-diagram-layout.gml.