Search code examples
layoutvisualizationgraphviz

Best layout for graph with long node labels


My graph has long node labels. Neato makes things overlap; Circo does what I want, it just creates too much space between nodes. I would like to use the Circo result and bring the nodes closer together.

Graph code: https://clbin.com/BbsNP

digraph {
graph [overlap=scale];
graph [bgcolor=white];
node [shape=box];
0 [label="long node label"
  ,shape=box];
1 [label="long node label"
  ,shape=box];
2 [label="aoeu aoe uaoeu oae ueaoo"
  ,shape=box];
3 [label="long node labelau"
  ,shape=box];
4 [label="aoeu aoe uaoeu oae ueaooeu"
  ,shape=box];
5 [label="long node labelaoeu"
  ,shape=box];
6 [label="aoeu aoe uaoeu oae ueaoe"
  ,shape=box];
7 [label="long node labelaoeuo"
  ,shape=box];
8 [label="aoeu aoe uaoeu oae ueao"
  ,shape=box];
9 [label="234 aoeua",shape=box];
10 [label="long node labeluu"
   ,shape=box];
11 [label="aoeu aoe uaoeu oae ueao"
   ,shape=box];
12 [label=oeuaoeu,shape=box];
13 [label="long node labelaa"
   ,shape=box];
14 [label="aoeu aoe uaoeu oae ueao"
   ,shape=box];
15 [label=aoeu,shape=box];
16 [label=aoeu,shape=box];
0 -> 1 [color=blue];
1 -> 0 [color=blue];
2 -> 1 [color=blue];
3 -> 0 [color=blue];
4 -> 3 [color=blue];
5 -> 0 [color=blue];
6 -> 5 [color=blue];
7 -> 0 [color=blue];
8 -> 7 [color=blue];
9 -> 7 [color=blue];
10 -> 0 [color=blue];
11 -> 10 [color=blue];
12 -> 10 [color=blue];
13 -> 0 [color=blue];
14 -> 13 [color=blue];
15 -> 13 [color=blue];
16 -> 13 [color=blue];
}

Image: http://postimage.org/image/mrcak2021/

circo -T jpg Test.Layout.LongNodeLabel.dot > Test.Layou.LongNodeLabel.jpg

Solution

  • The problem is similar to the one in this recent question. If you're willing to use twopi rather than circo, you can set ranksep to pull in or push out the nodes -- to change "the radial separation of concentric circles," as the documentation describes it.

    I changed your graph code to begin like so:

    digraph {
        graph [bgcolor=white, overlap=true, ranksep=2.75];
    

    Then graphed it using twopi: twopi test_graph.txt -Tpng -otest_graph.png. This produces the following graph:

    graph using twopi

    Here is the original for comparison:

    graph using circo