Generating Graphs from an Org Mode File

I came across this tweet from Sacha Chua

and decided to take a look. I’m glad I did. The page is a detailed list of Chua’s goals. If you’re a Chua fan like me, the existence of such a page is not a surprise but why should we care? Aside from what we might learn from the goals themselves, the generation of the page has a lot to teach us.

One of the features of the page is a graph that maps her goals and how they relate to each other. What’s nice is that the graph is generated programmatically from the text on the page. That would involve a lot of work but for the fact that the page was generated from an Org source file. There are some interesting things about that file.

First is that, in the manner of reproducible research, everything to generate the page is included in the Org file including the Elisp code that generates the graphviz dot file for the graph, and the invocation of graphviz that produces the png for the graph.

The second interesting thing is her use of org-map-entries to iterate through the goals. This eliminates at lot of the parsing that she would otherwise have to do.

Finally, Chua came up with a nice trick to wrap the labels in the graph. To see the advantage of this, she includes an old copy of the graph, without the wrapping, at the end of page. In order to keep the nodes reasonably small, she wraps the longer lines into two or more lines by inserting the label string into a buffer with the appropriate fill-column value and calling fill-region.

If you’re interested in using Babel and Org-mode in a reproducible research manner, studying Chua’s code will pay dividends.

This entry was posted in Programming and tagged , . Bookmark the permalink.