high wisdom



Mon Feb 23 12:17:12 IST 2009

Graphviz awesomeness

Graphviz is my newest discovery. I used to meddle with Dia and xfig whenever I needed to publish any diagrams (network diagrams for example), but they have their problems - one has to worry about the layout and spacing among other things. The content becomes secondary to the layout. That's exactly the reason why I don't use word processors. Systems like Textile, Markdown, reStructured Text and the king of them all, TeX let you focus on the content and figure out an appropriate layout (some of them with a little help - but the focus still remains on the content).

Graphviz does that for graphs and it's just awesome! Examples speak louder than words, so here they are:

graph g {
        foo -- bar;
        bar -- baz;
        baz -- spam;
        eggs -- spam;
        spam -- bar;
        foo -- spam;

        label="The foo bar graph"
}

graph g {
        foo;
        {rank=same; bar; baz; spam; eggs;}

        foo -- bar;
        bar -- baz;
        baz -- spam;
        eggs -- spam;
        spam -- bar;
        foo -- spam;

        label="The flatter foo bar graph"
}

digraph G {
        foo;
        {rank=same; bar; baz;}
        {rank=same; spam; eggs;}

        foo -> bar;
        bar -> baz [arrowhead=vee];
        baz -> spam [arrowhead=diamond];
        spam -> eggs [label=" an edge " arrowtail=diamond arrowhead=vee color=red];
}

Posted by gera | Permanent link | File under: tricks | [ 0 ]