subgraph cluster ranking in dot

前端 未结 3 1157
南方客
南方客 2020-12-14 21:41

I\'m trying to use graphviz on media wiki as a documentation tool for software.

First, I documented some class relationships which worked well. Everything was ranked

3条回答
  •  不知归路
    2020-12-14 22:10

    The layout is an attempt by Dot to minimise the overall height.

    One reason for the more compact than required layout is the use of the edge that goes in the reverse direction from dll1_a to B1. It tries to pull the cluster as close back to the destination node as possible. To avoid this edge affecting the graph, either relax the constraint on the upwards edges as shown, or draw the edge in the forward direction and use the dir attribute to reverse the arrow.

    This will help with many layouts but it alone is not sufficient to fix the example given. To prevent Dot from maintaining the compact layout it prefers you can add a minlen attribute to edges that should remain (near) vertical. This may be difficult to calculate in general but is practical for manually tuned layouts.

    digraph d {
        subgraph cluster0 {
            A -> {B1 B2}    
            B2 -> {C1 C2 C3}
            C1 -> D;
        }
        subgraph cluster1 {
            C2 -> dll1_A [minlen = 2];
            dll1_A -> B1 [constraint = false];
            /* B1 -> dll1_A [dir = back]; */
        }
        subgraph cluster2 {
            C3 -> dll2_A;
        }
        dll1_A -> dll2_A;
    }
    

    Corrected layout

提交回复
热议问题