Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Graphviz: how to arrange nodes with circo layout

Tags:

graphviz

I'm trying to draw a graph with circle topology.

Here is what I'm expecting to see: enter image description here

Here is my gv file:

digraph g1 {
    layout="circo";
    node [shape = doublecircle]; N4 N6;
    node [shape = circle];
    N0 -> N1 [ label = "{1,0}"];
    N1 -> N2 [ label = "{1,0}"];
    N2 -> N3 [ label = "{1,0}"];
    N3 -> N4 [ label = "{1,0}"];
    N4 -> N5 [ label = "{1,0}"];
    N5 -> N6 [ label = "{1,0}"];
    N6 -> N0 [ label = "{1,0}"];

    N0 -> N4 [ label = "{1,0}"];
    N1 -> N5 [ label = "{1,0}"];
    N2 -> N6 [ label = "{1,0}"];
    N3 -> N0 [ label = "{1,0}"];
    N4 -> N1 [ label = "{1,0}"];
    N5 -> N2 [ label = "{1,0}"];
    N6 -> N3 [ label = "{1,0}"];    
}

And here is an output image for graph above: enter image description here

How can I arrange nodes in graphviz to make it look like 1?

like image 940
Filipp Avatar asked Sep 17 '12 20:09

Filipp


1 Answers

If the goal is to have a graph which respects the order of the nodes, it's not that simple. You could calculate the position of the nodes with an external script and render it with neato.

Or you could first layout the nodes with the edges which determine the correct order of the nodes only:

digraph g1 {
    node [shape = doublecircle]; N4 N6;
    node [shape = circle];
    edge[label="{1,0}"];
    N0 -> N1 -> N2 -> N3 -> N4 -> N5 -> N6 -> N0;
}

with:

circo graph.gv > tempgraph.gv

Then add the remaining edges to tempgraph.gv - just copy-paste the following before the closing }:

N0 -> N4 [ label = "{1,0}"];
N1 -> N5 [ label = "{1,0}"];
N2 -> N6 [ label = "{1,0}"];
N3 -> N0 [ label = "{1,0}"];
N4 -> N1 [ label = "{1,0}"];
N5 -> N2 [ label = "{1,0}"];
N6 -> N3 [ label = "{1,0}"];

And render it with neato and the -n option:

neato -n tempgraph.gv -Tpng -O

You may want to fine-tune the position of the labels:

circo layout

like image 102
marapet Avatar answered Nov 13 '22 15:11

marapet