My Profile Photo

Concrète Mixer


An internet radio station dedicated to shredded field recording ambience


Now playing


Using dot to make charts

As this is a software blog I may as well mention how I generated the charts in the last post. As background I’ve had experience in the past drawing flow charts in Visio and Fireworks (those were the days), and was looking for something similar. Being in Linux land I tried Inkscape and dia, but Inkscape was a bit bewildering and dia was a bit rubbish (sorry dia developers!). I knew vaguely of tools that could generate charts from text and tried flowchart.js, but found the whole business of rendering a chart by loading a web page a bit inelegant. In the end I found dot, part of the GraphViz package.

The output flow diagram

To refresh your memory, here’s the output file:

Concrete Mixer flow diagram simplified

The markup

And here’s the underlying ‘dot’ code used to generate the file (sorry the syntax highlighting is a bit rubbish, but the pygments lexer I found for this is a bit minimal):

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
digraph  {
    /* declare chartwide settings */
    penwidth=2.0;
    labeljust=left;
    node [fontname="Helvetica",penwidth="2.0",fontcolor=white,style=filled];
    edge [penwidth="2.0"];
    fontname=helvetica;
    fontsize=16;

    /* subgraphs allow you to group nodes */
    subgraph cluster_0 {
        node [fillcolor=chocolate,color=chocolate];
        graph [color=chocolate];
        label="Perl";
        fontcolor=chocolate;
        concretepm [label="Concrete.pm\nOSC server"];
        node [fillcolor=brown,color=brown];
    }

    subgraph cluster_1 {
        node [fillcolor=darkorchid,color=darkorchid];
        graph [color=darkorchid];
        label="WAV files";
        fontcolor=darkorchid;
        main [label="Main"];
        alt [label="Alt"];
    }

    subgraph cluster_2 {
        graph [color=forestgreen];
        fontcolor=forestgreen;
        label="ChucK";
        node [fillcolor=forestgreen,color=forestgreen];
        playsound [label="playSound.ck"];
        playfx [label="playFxChain.ck"];
    }

    /* the rest of the chart markup defines edges between nodes plus non subgraph nodes */
    node [fillcolor=hotpink,color=hotpink];
    shell [label="Linux shell $",color=hotpink];
    edge [color=hotpink];
    shell -> concretepm;

    /* wav file flow */
    edge [color=darkorchid];
    main -> concretepm;
    alt -> concretepm;
    concretepm -> playsound;

    /* play*-OSC server interactions */
    edge [color=chocolate];
    concretepm -> playsound;
    concretepm -> playfx;
    playfx -> concretepm;
    playsound -> concretepm;

    /* audio connections through to the dac */
    node [fillcolor=steelblue,color=steelblue];
    edge [color=steelblue];
    playsound -> DAC;
    playsound -> playfx;
    playfx -> DAC;
}

The bulk of the markup is colour declarations and changes, so while this looks like a lot of work, the subgroup and and node interrelationships can be defined in about half the number of lines.

Installation and invocation

Installing graphviz in debian/ubuntu land requires the following:

$ sudo apt-get install graphviz

To generate an SVG all you have to run is:

$ dot -T svg -O cm-schematic-minimal.dot

…and an SVG file called cm-schematic-minimal.dot.svg is created.

Concludings

I’m not sure everyone will think writing 63 lines of code is better than spending 10 minutes with a graphical flowchart package to make the same chart. As a non-designer I likein the idea of marking up a text file and feeding it into a program so that it takes care of the layout, and it’s quite elegant (and portable) to have everything encapsulated in a single text file.

If you want to learn more about dot this excellent guide will help you out.

comments powered by Disqus