Nanik
Nanik

Reputation: 633

Graphviz – horizontal edges between nodes

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.

Upvotes: 10

Views: 8176

Answers (2)

marapet
marapet

Reputation: 56466

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).

Upvotes: 7

apmasell
apmasell

Reputation: 7153

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.

Upvotes: 7

Related Questions