0

I've got a simple graph that I would like to format into a circular layout. The source of the graph looks like this:

digraph g1 {
layout="circo";
node [shape = circle];

JB -> ML [label = "1"];
JB -> VS [label = "2"];
AM -> ML [label = "2"];
AM -> VS [label = "2"];
JR -> EL [label = "2"];
JR -> VS [label = "2"];
LL -> ML [label = "1"];
LL -> VS [label = "1"];
OO -> TK [label = "2"];
JJ -> PL [label = "1"];
VS -> JB [label = "2"];
VS -> JR [label = "2"];
VS -> VP [label = "4"];
}

Now, however, when I render it, it turns out anything but a circle:

Graph rendered the wrong way

What am I missing here? The result is the same on my local machine (after "circo -Tpng input.gv -o output.png") and at Graphviz Online. On my local machine Graphviz is at version 2.43.0 but I doubt that has to do with it as the online version fails equally? None of the online resources I've browsed mention that the circo layout might fail for any reason. I also tried making the graph not directed, with no better luck.

ZeroOne
  • 3,041
  • 3
  • 31
  • 52
  • Please describe "circular layout" goal. Node in the middle? All nodes with same radius from center? Maybe sketch an example. – sroush Jun 07 '22 at 15:40
  • p.s. the man page (https://www.graphviz.org/pdf/dot.1.pdf) helps explain what you are seeing. – sroush Jun 07 '22 at 15:50
  • @sroush Here's a question with an example of nodes in a circular layout: https://stackoverflow.com/questions/12466951/graphviz-how-to-arrange-nodes-with-circo-layout However, that question is about the specific order of nodes: I just cannot get them into ANY circular order. :( – ZeroOne Jun 07 '22 at 19:26

2 Answers2

1

(Is this what you want?)
The man page says you really want twopi, not circo. And it requires a few modifications:

  • establish (invisible) center node
  • establish (invisible) edge from center to each node
// https://stackoverflow.com/questions/72531363/how-to-create-a-graph-with-a-circular-layout-in-graphviz?noredirect=1#comment128135175_72531363
digraph g1 {
//layout="circo";
layout="twopi";
ranksep=3 // set radius, in inches

root=CENTER  // establish the (invisible) center node
edge [style=invis]
CENTER [style=invis]
// set equidistance all nodes from CENTER
CENTER -> {
JB
ML
VS
AM
JR
EL
LL
ML
OO 
TK
JJ
PL
VP
}

// now the actual edges
edge [style=solid]
node [shape = circle];
JB -> ML [label = "1"];
JB -> VS [label = "2"];
AM -> ML [label = "2"];
AM -> VS [label = "2"];
JR -> EL [label = "2"];
JR -> VS [label = "2"];
LL -> ML [label = "1"];
LL -> VS [label = "1"];
OO -> TK [label = "2"];
JJ -> PL [label = "1"];
VS -> JB [label = "2"];
VS -> JR [label = "2"];
VS -> VP [label = "4"];
}

Giving:
enter image description here

sroush
  • 5,375
  • 2
  • 5
  • 11
  • Ooh, nice hack, that does seem to do the trick for this graph! However, it turns out the actual solution for me was to just add more edges to the graph, which I've posted as a new answer (that I can only accept tomorrow, it seems). I'll grant you an upvote though, thanks for helping! – ZeroOne Jun 08 '22 at 06:03
0

Well, guess what. Answering my own question here. It turns out the circo layout needs more connections than what I gave to it. Adding just a few more edges, such as these:

JJ -> AM;
OO -> VP;
PL -> TK;
EL -> VP;

...produces a nice, round graph:

Nice and round graph

ZeroOne
  • 3,041
  • 3
  • 31
  • 52