PlantUML

Open-Source tool in Java to draw UML Diagram

The context

PlantUML is using GraphViz/DOT to compute node positionning for every UML diagrams (except Sequence Diagram). The fact that DOT computes automatically the position of node is a key feature, and algorithms implemented in DOT usually give very good result. However, there are some drawbacks of using DOT : the computation is done by an external program (dot.exe on Windows, dot on linux), and that means that : Another way of using DOT would be to use it as a library, and to link it with PlantUML using JNI (Java Native Interface) but that would not be perfect thought.

If a Java version of GraphViz/DOT would exist, this would allow to greatly simplify the installation and the use of PlantUML.

Unfortunatly, this does not exist today...

So what about porting GraphViz/DOT to Java ? As GraphViz/DOT is written in C, and as Java syntax is close to C syntax, it is possible to translate the C source of GraphViz to Java source, although this is a large and complex task.

The good news is that we don't need to translate the whole GraphViz sources to Java : this is due to the fact that PlantUML uses only a limited portion of GraphViz. Firstly, only DOT algorithm is used (neato, ... and other are not used). Secondly, the parsing of the DOT language is not need : PlantUML could directly build the diagram in memory without generating DOT language. And thirdly all the drawing code of GraphViz is not needed anymore, since the drawing is done in Java

This translation of DOT to Java is a new project called JDot. This project will not depend on PlantUML : classes will be completely independent of PlantUML and other open source Java projects would be able to use it, if they wish.

The project

You will find here some information about how to translate C to Java.

The first step is to have a minimal version that compiles and runs.

Some Junit tests have also been written to check that the basic classes and converted C code are working.

You can checkout two projects:

Project name Description URL
prejdot Java project that runs the C preprocessor and generates HTML sources https://svn.code.sf.net/p/jdot/code/trunk/prejdot/
JDot The converted version of DOT to Java https://svn.code.sf.net/p/jdot/code/trunk/jdot/

You also have to download graphviz-2.28.0 sources and put them in the graphviz-2.28.0 directory of prejdot.

Special credit for those two projects that are very usefull for converting C to Java:


import lib.graph.Graph_h.Agraph_t;

import static core.Utils.ARG;
import static core.Utils.asStarChar;
import static lib.graph.Graph.agopen;
import static lib.graph.Graph_h.AGDIGRAPH;
import static lib.graph.Graph_h.aginit;
import static lib.graph.Node.agnode;

public class Main1 {

  /**
   * Create a empty graph
   @param args
   */
  public static void main(String[] args) {
    // C version
    //
    // Agraph_t* G = agopen(name, type);
    //
    // Java version
    Agraph_t G = agopen("name", AGDIGRAPH;
    Agnode_t n1 = agnode(G, ARG(asStarChar("a")));
    Agnode_t n2 = agnode(G, ARG(asStarChar("b")));
  }

As you can see, this is really minimal. To do so, the following translation have been done.

C code and Java code are displayed side by side, to facilitate comparaison and reviews.

Package H files C files
ast Ast_h.java
 
cdt Cdt_h.java
Dtdisc_c.java
Dtflatten_c.java
Dtopen_c.java
Dtrestore_c.java
Dtsize_c.java
Dtstrhash_c.java
Dttree_c.java
common Color_h.java
Geom_h.java
Htmltable_h.java
Logic_h.java
Textpara_h.java
Types_h.java
Usershape_h.java
Emit_c.java
Global_c.java
Htmltable_c.java
Input_c.java
Labels_c.java
Memory_c.java
Shapes_c.java
Strcasecmp_c.java
Utils_c.java
dotgen   Dotinit_c.java
graph Agxbuf_h.java
Graph_h.java
Libgraph_h.java
Agxbuf_c.java
Attribs_c.java
Edge_c.java
Graph_c.java
Lexer_c.java
Node_c.java
Refstr_c.java
gvc Gvcext_h.java
Gvcint_h.java
Gvcjob_h.java
Gvcommon_h.java
Gvplugin_device_h.java
Gvplugin_h.java
Gvplugin_layout_h.java
Gvplugin_loadimage_h.java
Gvplugin_render_h.java
Gvplugin_textlayout_h.java
Gvc_c.java
Gvconfig_c.java
Gvcontext_c.java
Gvlayout_c.java
Gvplugin_c.java
Gvtextlayout_c.java
Gvusershape_c.java
xdot Xdot_h.java
Xdot_c.java

Next steps

First, if you find errors in the conversion or in the methodology, you are welcome to react.
Before going further, we have to write some JUnit tests to validate that graph creation is working fine.

Then we will have to add an edge to this graph.

And then to run the layout.

Support This ProjectOffer 250 Mo!Follow PlantUML on TwitterPlantUML on Google Reader