0
votes

I have two graphs being rendered by dot:

   graph G {
    graph[rankdir=LR]
    node[shape=circle, fontname="Courier-Bold", fontsize=10, width=0.4, height=0.4, fixedsize=true]
    edge[arrowsize=0.6, fontname="Courier-Bold", fontsize=10, arrowhead=vee]
    v0 -- i0 [label=11]
    v1 -- i0 [label=2]
    v2 -- i0 [label=10]
    i0 -- i1 [label=4]
    i1 -- i2 [label=3]
    i2 -- v3 [label=3]
    i2 -- v4 [label=4]
    i1 -- v5 [label=0, style=dashed]
   }
   graph G {
    graph[rankdir=LR]
    node[shape=circle, fontname="Courier-Bold", fontsize=10, width=0.4, height=0.4, fixedsize=true]
    edge[arrowsize=0.6, fontname="Courier-Bold", fontsize=10, arrowhead=vee]
    subgraph cluster_two {
     fontname="Courier-Bold"
     fontsize=10
     v0 -- i0 [label=11]
     v1 -- i0 [label=2]
     v2 -- i0 [label=10]
     i0 -- i1 [label=4]
     i1 -- i2 [label=3]
     i2 -- v3 [label=3]
     i2 -- v4 [label=4]
     i1 -- v5 [label=0, style=dashed]
    }
   }

The 2nd graph is exactly the same as the first, except that it's wrapped in subgraph. For whatever reason, the subgraph wrapping makes it so that node separation is much wider than normal:

Graph 1 output

Graph 2 output

The nodesep attribute doesn't control the nodes under a subgraph. Is there anything to get node placement to unstretch back to normal (as in the 1st picture)?

1
Perhaps this might be useful? - Sherif
@Sherif I saw that post as well but I don't know if it applies. But if it does, I'm not understanding it. Maybe someone with a better handle on graphviz/dot can help me unpack it. - offbynull
What version of Graphviz are you using (dot -V) and what OS. I am not encountering this problem on Linux w/ graphviz version 2.43.0. p.s. look at ranksep, not nodesep - sroush
@sroush 2.40.1 on Alpine Linux. As per your recommendation, setting ranksep=0.25 on the main graph (not the subgraphs) fixes the render. But, I have no idea why. Do you have any insight as to what's going on with subgraphs and nodesep/ranksep?Also, if you can post your comment as an answer to the question I can accept it so you get credit. - offbynull

1 Answers

1
votes

Ranksep is the attribute that sets the distance from one rank to the next. Ranksep is a graph-level attribute. When it is set, it applies to the entire graph. This is also true for nodesep, except nodesep sets the distance between two adjacent nodes on the same rank.
p.s. 2.40.1 is a rather old release. Many fixes have been applied over the last 18 months or so (I take no credit).