Search code examples
graphviz

How to create a graph with a circular layout in Graphviz


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.


Solution

  • 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