7.7.06

Old S|<0oL tools

CS Lab on Wednesday introduced us to something new and exciting: the dot utility. Er, it's actually around 15 years old, but it's still as functional as ever. Here's how to draw a simple flowchart, for example:

First, I type this bit of extremely simple code into the file Flowchart.dot, so simple that many people reading this should be able to understand it:

digraph Flowchart {
node1 [label="Program starts", shape=rect, style=rounded];
node2 [label="Ask user's age", shape=parallelogram];
{
rank=same;
node3 [label="18 or older?", shape=diamond];
branch [label="Quit the game", shape=rect, style=rounded];
}
node4 [label="Finish starting up", shape=rect, style=rounded];

node1 -> node2 -> node3;
node3 -> branch [label="NO"];
node3 -> node4 [label="YES"];
}

...then I type dot -Tpng Flowchart.dot -o Flowchart.png on the command line, and I get this:



Very slick, no? All I need to specify are the nodes and the connections between them, along with a few parameters for node shape, etc., in order to produce a nice, polished flowchart/graph/thing. Why are we fiddling with graphics and flowcharts, though? Well, we're currently studying directed graphs and shortest-path problems, and in order to help visualize the problem, we use dot.

Even neater is the fact that this utility, as well as several other similar ones (e.g. that draw radial or circular graphs), were recently packaged up with the name GraphViz and released under an open-source license, so that anyone can easily make a graph of the courses needed to complete their major:



Not that anyone besides me actually opts for Computer Engineering.

No comments: