3 ms·
A couple of important tips that the article omits: 1. For manual editing, dot -Tx11 foo.dot displays the graph in a window and updates it automatically wheneve
by kragen 6y ago
A couple of important tips that the article omits:
1. For manual editing, dot -Tx11 foo.dot displays the graph in a window and updates it automatically whenever you save. So you can have an editor window open and the dot window and see the results of every tweak. For automatically generated graphs, this provides you with a window that you can update by overwriting a file with a new graph description.
2. Although HTML nodes are more versatile, shape=record is much easier, and sufficient for a pretty wide range of diagrams.
For doing quick stuff by hand if you don't have Graphviz installed, or if you're stuck on a Mac without X-Windows, there's https://graphviz.christine.website/ https://graphviz.christine.website/. I like Graphviz a lot; as other people point out, TikZ is capable of a wider range of graphics, and also you can write programs to generate graphs in TikZ. But Graphviz is often enough.
A really simple graph like https://graphviz.christine.website/#digraph%20G%20%7Ba-%3E%7Bb-%3E%7Bc-%3E%7Bd-%3E%7Be-%3E%7Bf-%3E%7Bg-%3E%7Bh-%3E%7Bi-%3E%7Bj-%3E%7Bk%7D%7D%7D%7D%7D%7D%7D%7D%7D%7D%3B%7D https://graphviz.christine.website/#digraph%20G%20%7Ba-%3E%7... is sometimes good enough without further tweaking, but for, e.g., the top diagram in https://github.com/kragen/dumpulse#dumpulse-an-embeddable-dumb-heartbeat-daemon-in-260-bytes-of-ram-and-350-bytes-of-code https://github.com/kragen/dumpulse#dumpulse-an-embeddable-du..., you usually have to tweak stuff a bit.
- m000 6y ago3. 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) https://en.wikipedia.org/wiki/M4_(computer_language)
- kragen 6y agoYou 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#calling-interface-diagram 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-types.dot 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 https://github.com/kragen/dumpulse/blob/master/Makefile
- m000 6y agoYou 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"];
- kragen 6y agoRight! 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.
- egwor 6y agoI used xdot in Ubuntu earlier this week and it crashed my Gnome session. Beware!