3

Trying to use rank=same to control ordering of nodes in graphviz see e.g. e.g. I found this extraordinary behaviour. What I want is to get the nodes a, b, and c in the expected order, i.e. a then b then c:

digraph foo{
newrank=true
"o4"->"x3"
"o4"->"x4"
"o5"->"x3"
"o5"->"x4"

subgraph cluster_7 {

"a"->"i"
"b"->"i"
"c"->"i"

} 
{rank="same";"a"->"b";"b"->"c"}

}

unexpected behaviour

I see no reason why graphviz would go out of its way to mess up the order of a, b, and c. If I change any aspect of the code, e.g. removing one of the edges between the o nodes and the x nodes, the problem disappears. It also disappears if I delete newrank=true, but I need this because otherwise the rank=same specification shifts the nodes out of the subgraph. It disappears if I make the subgraph into an ordinary cluster, i.e. don't start the name with cluster_ but I need this too. It disappears if I delete the rank=same line but I also need this. Any ideas?

ash
  • 5,139
  • 2
  • 27
  • 39
user43018
  • 63
  • 5

1 Answers1

1

I was able to get a better result by turning off constraint on a couple of edges:

digraph foo{
newrank=true
"o4"->"x3"
"o4"->"x4"
"o5"->"x3"
"o5"->"x4"

subgraph cluster_7 {

"a"->"i" [constraint=false]
"b"->"i"
"c"->"i" [constraint=false]

} 
{rank="same";"a"->"b";"b"->"c"}

}

enter image description here

I can't explain why this helps, however.

jasonharper
  • 9,450
  • 2
  • 18
  • 42