March 4, 2014

Create Graphs with Scripts

If you ever have spent hours with a drawing, dragging boxes and formatting arrows, you will appreciate the following possibility: Create your flow charts and UML diagrams with a script, and let a tool draw the lines. It has the following advantages:
  • You will not spend your time with drawing and formatting the elements and dragging them around. Instead, you can focus only on the pure information you want to document.
  • As a result you will have a small and platform-independent text file, which you can store like a source code, and even put in a version control system.
  • It is very useful to document the classes hierarchies since the syntax of the code (e.g. Java) and the syntax of the UML script is very similar.


Explanation


DOT


The basis is the DOT language. It describes graphs in general. It contains the elements graph, node and edge, and their several attributes. Check out the gallery of possible graphs with DOT.

Graphviz


Graphviz is a runtime API library. It will draw the graphs from the scripts. Every tool or plug-in based on Graphviz will create exactly the same drawings from the same scripts. We only have to download and install it. (Note: Check out the version supported by PlantUML because it might not be the latest one.)

It can create the drawings in three different form: PNG, SVG and Text. It is worth to check out the SVG format since it is a vector graph, so you can magnify it without losing image quality.

PlantUML


PlantUML is a plug-in, that is built on Graphviz, and which extends the DOT language with UML elements. This plug-in is provided for Eclipse and other tools (e.g. MS WordConfluence, LaTeX). They also offer an online tool where we can test our scripts. The documentation of PlantUML is the complete set pf examples on the home page. :-)

Example for using PlantUML: The Eclipse plug-in creates the scripts and the drawing of the selected Java class. Though it can describe only one class at once, you can easily copy-and-paste the generated scripts and create a more complex class diagram.

Example


Here is a graph about these UML tools, and the DOT script that creates it.

    
digraph Tools {

    // Common layout for nodes
    node [shape=box3d, fontsize=10, fontname=arial]

    // Nodes and edges
    PlantUML -> Graphviz -> DOT 
}

No comments :

Post a Comment