9

Good evening, I'm trying to generate graph using graphviz.

I can't figure out how to model horizontal edges between some nodes. I use the next code to generate this graph:

Graph

digraph{ rankdir=LR;
//{rank=same; "[0]"; "[10B1]"; "[62]"; "[8]"; "[9]"; "[10]";}
"[0]"->"[37]"; "[37]"->"[4]"; "[37]"->"[8]";
"[8]"->"[9]"; "[9]"->"[10]"; "[62]"->"[8]";
"[0]"->"[10B1]"; "[10B1]"->"[62]"; "[0]"->"[2]";
"[2]"->"[3]"; "[7]"->"[8]"; "[4]"->"[7]";
}

I would like to align the nodes [8], [10B1], [62] [8], [9] and [10] in one horizontal line.

Nanik
  • 603
  • 1
  • 12
  • 19

2 Answers2

6

You need to place those nodes in a cluster. Inside that cluster, you can then set rank=lr to have the nodes placed left-to-right. It's important that you define the cluster and the nodes you want in it before you add the connecting edges to the rest of the graph.

apmasell
  • 7,033
  • 19
  • 28
6

An other solution is to have the nodes which have to be aligned share the same value of the group attribute:

digraph{
rankdir=LR;

node[group=main];
"[0]"; "[10B1]"; "[62]"; "[8]"; "[9]";
node[group=""];

"[0]"->"[37]";
"[37]"->"[4]";
"[37]"->"[8]";
"[8]"->"[9]";
"[9]"->"[10]";
"[62]"->"[8]";
"[0]"->"[10B1]";
"[10B1]"->"[62]";
"[0]"->"[2]";
"[2]"->"[3]";
"[7]"->"[8]";
"[4]"->"[7]";
}

You could achieve something similar by adjusting weight or using constraint=false for some edges.

Here's an other example using group, and an other example using weight (same question).

Community
  • 1
  • 1
marapet
  • 54,856
  • 12
  • 170
  • 184
  • Bad graph with this data (http://pastebin.com/1YeaJPtt). It is posible to fix it? – Nanik Apr 29 '12 at 21:19
  • Yep: http://pastebin.com/NjTN6wC7 - changed the order of the nodes a bit, and added `constraint=false` for one edge – marapet Apr 29 '12 at 23:23