James Riely : Java Visualization Software

Here is some software to make visualizations of Java code, using graphviz.

For example, to draw every step of your running program, simply add the following two lines to the beginning of the main function.

Trace.run ();
Trace.drawSteps ();

For example, if you run XFixedCapacityStack.java, you will get output like this:

and this:

Null references are not shown (configurable for objects via Trace.showNullFields).

Here is a glossary for shapes:

Here is a glossary for arrows:

There are several ways to create drawings.

There are lots of options. See the javadoc for details.

One useful option is Trace.setGraphizOutputDir(dirName), which allows you to change where the drawings are place on your system. By default they go on the user Desktop. You can specify an absolute or relative path for dirName. Relative paths are interpreted with respect to the user home directory.

Another useful option is Trace.showBuiltInObjects(true), which results in the following style of output:

The following results from Trace.showBuiltInObjectsVerbose(true);

The following results from Trace.showObjectIdsRedundantly(true);

Methods that being with draw may be called at any time. Other option methods must be called before Trace.run() in order to have any effect. Thus Trace.run(); Trace.showBuiltInObjects(true) is the same as Trace.run(). Correct usage is Trace.showBuiltInObjects(true); Trace.run().

Here is a longer example: ZTraceExample.java

It produces output like this, which shows an exception being caught:

Here is a complete sequence of drawings: ZTraceExample-graphviz.pdf

It is also possible to get console output using Trace.consoleShow(true) or Trace.consoleShowVerbose(true): ZTraceExample-console.txt

To install, you need tools.jar from your JDK installation (or from here), as well as the following two files.

The socket file is necessary on some operating systems to avoid problems with reverse DNS. Install it if you are having trouble getting an exception that says that the debugger cannot be started.

A related project is GraphvizBuilder.java (javadoc).

I use this to draw trees and graphs. For example:

	public void toGraphviz(String filename) {
		GraphvizBuilder gb = new GraphvizBuilder ();
		toGraphviz (gb, null, root);
		gb.toFileUndirected (filename, "ordering=\"out\"");
	private static void toGraphviz (GraphvizBuilder gb, Node parent, Node n) {
		if (n == null) { gb.addNullEdge (parent); return; }
		gb.addLabeledNode (n, Integer.toString (n.key));
		if (parent != null) gb.addEdge (parent, n);
		toGraphviz (gb, n, n.left);
		toGraphviz (gb, n, n.right);

will draw trees such as

Last modified: Thu Nov 3 17:02:05 CDT 2016