4

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.

TylerH
  • 20,799
  • 66
  • 75
  • 101
Aman
  • 916
  • 11
  • 16

2 Answers2

4

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.

Pekka
  • 3,529
  • 27
  • 45
1

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

Mahmoud
  • 9,729
  • 1
  • 36
  • 47
  • OP specified degrees like 60, 120, 240 and 300. It looks like your example has 45, 135, 225, 315 degrees. – albert Jun 30 '22 at 08:31
  • 1
    @albert: you are right. thanks for pointing it out. answer updated. – Mahmoud Jun 30 '22 at 09:33
  • This looks more like what PP asked, it is a bit of a trick and works fine for the given constellation. It would be nice to have a possibility to explicitly specify the angles, I don't know whether one of the GraphViz engines supports this. I think that it is possible to create an image with arbitrary angles by means of the Tikz package in LaTeX but that is a completely different type of question and not in the direction OP asked. – albert Jun 30 '22 at 09:44