Posted by dwalend
on August 11, 2005 at 7:11 PM PDT
Last week, Kohsuke Kawaguchi suggested that we could use GraphViz to generate class diagrams automatically. I built it out of parts on my workbench over a few evenings.
Last week, Kohsuke Kawaguchi suggested that we could use GraphViz to generate class diagrams automatically. This idea caught my imagination. I've been looking for a readily-available set of test data a for JDigraph, plus an excuse to invest time in digraph visualization for another project that uses SVG. Class diagrams are a great fit.
I used methods on Class to populate a Digraph with Classes as nodes and their relationships ("extended by" and "implemented by") as edges. I used digraph iterators to cover the graph and create a dot-formatted String. I pass the String into GraphViz' dot utility to produce an SVG picture. In the test code, I use SVGSalamander to display the picture.
The project came together in three evenings. It deserves a weekend day to refactor some test code into more permanent parts, and maybe another evening or two to put it into a doclet. I hit a few snags that are worth their own blog entries, but I wanted to show the picture now. The effort is on its way to becoming a new project (under Java Tools as soon as I think of a good name). The test code is alive in JDigraph already. It's a work in progress, but here's what one of the first class diagrams looks like:
Here's what it looks like as a gif (a little lumpy) if your browser doesn't support SVG: