Platinum Solutions Corporate Website


Graphviz - another tool for your toolbox

The answer you entered to the math problem is incorrect.

If you have ever needed to produce a diagram of shapes connected by lines -- and what software developer hasn't? -- you've probably thought to yourself "there's got to be a better way to do this" as you open up your graphics editor and start dragging around rectangles and lines.

One tool you owe it to yourself to learning about is Graphviz (www.graphviz.org).  With this tool, you prepare an input text file listing the nodes, and the connections between them, and it produces diagrams for you.  The input files can be as simple as this:

graph {
a;
b;
c;
a -- b;
b -- c;
a -- c;
}

In this diagram, there are three nodes, a, b, and c, and the three nodes are all connected. Running this input file through Graphviz will produce a diagram with the three nodes, and lines between them.

graph {
a [label="State 1"];
b [label="State 2"];
c [label="State 3"];
a -> b;
b -> c;
a -> c [label="bypass"];
}

In this file, the node names have been changed by specifying a label attribute, and the graph is now a directed graph (the lines have arrow heads).  The line connecting nodes A and C also has a label on it.

Graphviz diagrams are highly customizable and you can produce graphics in a variety of output file formats.  Graphviz can even produce client-side and server-side image maps so the images it produces can become clickable when embedded in web-pages.  I won't go into all the options that are available here.

The cool part is that you don't lay out the shapes - Graphviz does.  You just specify what nodes need to go in the diagram and which ones are connected, and what the nodes should look like and what the connections should look like, and Graphviz does the rest.  If you need to add a new node, or change how they are connected, you change the input file and regenerate the diagram.  No more dragging things around trying to keep the lines from crossing and trying to make room for one more rectangle.

But here is why Graphviz is such a valuable tool for you, the developer -- it makes it easy to produce visualizations of code artifacts from code artifacts, particularly those that are XML based.  This is because an XSL transform can quickly and easily turn an XML file into a Graphviz input file, which can then become a well organized and automatically generated diagram that is guaranteed to be in sync with your code.  This is the very process behind Vizant, an Ant task that analyzes Ant build files and uses Graphviz to produce diagrams of their structure.

I find Graphviz particularly useful for preparing Finite State Machine digrams or State Transition diagrams, and for preparing dependancy diagrams from code and configuration files.   I have also used Graphviz to prepare developer documentation, with complicated diagrams of screen flows with client image maps that are linked to javadocs.

There are some things I wish Graphviz did differently however.  Predominant among these is the fact that Graphviz is not a library with an API, but a set of standalone applications.  Also, since it is not Java software (which is the area I work in) its integration into Ant is not as nice as it could be if it were a class in a jar file.  Others are nitpicky things that won't make sense to go into unless you are familiar with the tool.

Comments

Post new comment

Please solve the math problem above and type in the result. e.g. for 1+1, type 2.
The content of this field is kept private and will not be shown publicly.
  • Lines and paragraphs break automatically.

More information about formatting options