Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to draw edges at an angle in graphviz?

I am looking for a way to draw where i can specify angle at which edge is drawn from the node using graphviz tool.

Example is shown in picture below.

Edges at various angles from the central node.

Here i have taken the line going to north as 0 Degrees.

So i need something like

1--2 [angle="60"]
1--3 [angle="120"]
1--4 [angle="240"] // also can be angle="-120"
1--5 [angle="300"] // or angle ="-60"

I have already tried the following edge attributes = headport, tailport, dir and graph attribute rankdir but i am unable to get desired result.

like image 484
Aman Avatar asked Sep 01 '25 17:09

Aman


2 Answers

The dot renderer allows the use of ports to specify the angle that an edge makes with a node. You can use the notation 1:sw -> 2:ne; to describe the first edge in your graph.

There are limitations to this - for example only 45 degree precision, and the process appears to fail sometimes. If you have simple graphs, you could try to use the other renderers to do more balanced layouts than the hierarchical dot ones and attempt to tune them.

like image 77
Pekka Avatar answered Sep 06 '25 16:09

Pekka


You can achieve the intended result by switching to a circular layout + invisible nodes:

graph G {
    graph[layout="circo"];
    node[shape="circle"];
    
    6[style="invis"];
    1 -- 4;
    1 -- 3;
    1 -- 6[style="invis"];
    1 -- 2;
    1 -- 5;
}

sample

Update

The angles are not as OP asked. Thanks to @albert for pointing it out.

graph G {
    graph[layout="circo"];
    node[shape="circle"];
    
    1 -- 7[style=invis];
    1 -- 2;
    1 -- 5;
    1 -- 6[style=invis];
    1 -- 4;
    1 -- 3;
    
    6[style="invis"];
    7[style="invis"];
    
}

sample2

like image 27
Mahmoud K. Avatar answered Sep 06 '25 18:09

Mahmoud K.