Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

3. dot pairs nicely with m4 [1] and a Makefile. Without m4, it's a pain to apply a uniform style on groups of nodes.

[1] https://en.wikipedia.org/wiki/M4_(computer_language)



You can put the group of nodes in a subgraph and apply the uniform style to the subgraph. In https://gitlab.com/kragen/bubbleos/-/tree/master/yeso#callin... I did that for example as follows in https://gitlab.com/kragen/bubbleos/-/blob/master/yeso/api-ty...:

        subgraph types {
                node [shape=square];
                subgraph ints {
                        node [label=int];
                        int bool fd u32in die stride;
                }
                long int s32 u8 u32 -> ypix ywin;
                ...
Its expressivity is limited, since it depends on a hierarchical classification of your nodes and arcs that doesn't always eliminate all duplication, but it's usually enough to manually style the nodes the way I want without too much hassle. Because "types" and "ints" aren't "clusters", they don't affect the layout. (If you do want to use clusters, that can make this approach more difficult.)dnl

I haven't ever been quite desperate enough to use m4 to generate Graphviz files, although clearly it is a good fit. My experiences with m4 are more in the nature of getting way too much rope to hang myself with and then having a terrible time debugging. I wrote an HTML-generating macro language in m4 in 1994 and have never stopped regretting it.dnl

I do agree about the Makefile. In Dumpulse I used the following Makefile rule:

    %.png: %.dot
     dot -Tpng < $< > $@
That way I can rebuild the README diagrams (if outdated) just by listing "diagram.png heartbeat.png health-report.png" as dependencies of the "all" target. https://github.com/kragen/dumpulse/blob/master/Makefile


You only need a couple of line to plug in automatic m4 preprocessing in Makefile. And perhaps add a .SECONDARY line if you are debugging to prevent the intermediate .dot files from being deleted.

    %.dot: %.dot.m4
        m4 < $< > $@

I use m4 to implement something akin to css classes, only a bit more powerful because you can do pseudo-subclassing. E.g.

    define(`base_node', `width=1.75, height=1.0, fontname="Menlo", fontsize=13')
    define(`file',`base_node, shape=note')
    define(`directory',`base_node, shape=folder')
    define(`important', `fontname="Menlo Italic"')

    ...

    tarball [file, label="foo.tar"];
    vardir  [directory, label="/var"];
    etcdir  [directory, important, label="/etc"];


Right! That kind of crosscutting thing is tricky to do with the hierarchical nature of subgraphs. Without some kind of macro preprocessor you'd end up doing something like

    node [width=1.75, height=1.0, fontname="Menlo"];

    subgraph files {
        node [shape=note];
        tarball [label="foo.tar"];
        subgraph importantfiles {
            node [fontname="Menlo Italic"];
            ...
        }
    }

    subgraph dirs {
        node [shape=folder];
        vardir [label="/var"];
        subgraph importantdirs {
            node [fontname="Menlo Italic"];
            etcdir [label="/etc"];
        }
    }
This obviously has the drawback that if you change the importance font, you have to change it twice instead of once, and you might forget. And clearly there are cases where that kind of duplication is a bigger problem than the difficulties with m4.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: