0

I'm using graphviz (dot) to generate time expanded graph to use in my master thesis. However, my drawing results the following graph: Resulting Graph

As you can see, the third line is a little bit shifted to the right.I want all the lines in the same horizontal line. Also i want the x.th node in each line to stay at the same horizontal line of other x.th nodes of lines. Changing the edge weights would not helped me.

I could not find anything related to this problem so far.

What i want to achieve is something like this: Example Graph

Here is my code:

digraph G {
1[label="1"]
2[label="1"]
3[label="1"]
4[label="1"]
5[label="1"]
6[label="1"]
7[label="2"]
8[label="2"]
9[label="2"]
10[label="2"]
11[label="2"]
12[label="2"]
13[label="3"]
14[label="3"]
15[label="3"]
16[label="3"]
17[label="3"]
18[label="3"]
19[label="4"]
20[label="4"]
21[label="4"]
22[label="4"]
23[label="4"]
24[label="4"]

rankdir="LR";
node[width=0.15, height=0.15, shape=point];
edge[weight=500, label="1"];

1 -> 2 -> 3 -> 4 -> 5 -> 6 ;
7 -> 8 -> 9 -> 10 -> 11 -> 12 ;
13 -> 14 -> 15 -> 16 -> 17 -> 18 ;
19 -> 20 -> 21 -> 22 -> 23 -> 24 ;

edge[weight=3];
1 -> 9;
2 -> 9;
3 -> 11;

13 -> 22;
14 -> 22;
15 -> 24;

edge[weight=1];
1 -> 14;
2 -> 15;
3 -> 17;

7 -> 21;
8 -> 23;
9 -> 22;
}

Any help would be appreciated.

Makif
  • 113
  • 2
  • 9

2 Answers2

1

Instead of using weight try using the attribute constraint=false for all edges which go from one "line" to another.

Setting constraint to false makes graphviz to not consider those edges when laying out the nodes of the graph.

See also this very similar question & answer

Community
  • 1
  • 1
marapet
  • 54,856
  • 12
  • 170
  • 184
  • Thanks, that solved my alignment problem. But now, line two and line three swapped. I want them in order of 1,2,3,4 from top to bottom. Is there any way i can do this? – Makif Nov 25 '15 at 13:07
  • Some [invisible edges](http://stackoverflow.com/a/12578764/63733) usually help (some [other useful techniques here](http://stackoverflow.com/a/25776916/63733)). – marapet Nov 25 '15 at 14:28
0

As far as I know, the only way is to specify an explicit position for each individual node.

See: How to force node position (x and y) in graphviz

Community
  • 1
  • 1
Ruud Helderman
  • 10,563
  • 1
  • 26
  • 45