UMLGraph is a great tool from Diomidis Spinellis that uses GraphViz and the GNU plotutils package for "the declarative specification of UML class and sequence diagrams". My initial thought was that this would make it possible to insert sequence diagrams into DocBook documentation without human intervention, and it comes close.There are a couple of twists and turns required to get a properly cropped SVG image.The first obstacle is getting the pic2plot utility to work with Ant. The Ant <apply> task can run a command against a group of files, but it doesn't have the ability to redirect standard out to a target file on each iteration. (How could such an obvious use case get missed? Most UNIX commandline tools take input from standard in and produce output to standard out, as they should. Not being able to capture standard out on a iteration-by-iteration basis is silly.) The solution is an ugly hack that uses the <for> and <variable> tasks from the ant-contrib project.The second obstacle is that the XSL-FO engine I'm using requires that the SVG document be in the SVG namespace. but Ant makes it relatively easy to insert the SVG namespace into the SVG document, like so:<replace file="${generated.images.dir}/${lang}/${output}.svg"
token="<svg"
value="<svg xmlns="http://www.w3.org/2000/svg"" />CAVEAT: This is really an awful thing to do; manipulating XML markup as text is generally a bad idea, but this particular case hardly merits writing an XSLT.The third obstacle, and the one that makes it impossible to work on a purely declarative basis, is that the SVG that gets generated is always 8"x8", no matter what dimensions are specified in the sequence diagram script. It is possible to traverse an SVG document and compute a minimal clipping rectangle (based on the points referenced), but I couldn't find anyone who'd done it already. One solution is to load the documents into Batik's "squiggle" viewer and then use the reporting of the cursor's canvas coordinates to compute a viewport for insertion into the <svg> element.For example, if the bounding box should have corners (0.05,0.33) and (0.95,0.67) according to the coordinates that squiggle reports, the attributes on the <svg> element would read:<svg xmlns="http://www.w3.org/2000/svg"
width="7.2in" height="2.72"
viewbox="0.05 0.33 0.9 0.34"
preserveAspectRatio="none">In the end, the results are worth the trouble: