Skip navigation

What is AJaPaD?

AJaPaD stands for Another Java Parser for DOT. It provides programmers with an ANTLR-based DOT parser and a Java API for creating, manipulating and serializing GraphViz/DOT graphs.

AJaPaD is used in a new experimental pipeline for displaying DOT graphs in ZGRViewer. This pipeline no longer relies on SVG output, but on the enriched DOT output. The advantage of this pipeline is that it preserves all information about the graph's logical structure, something that the SVG pipeline does not (SVG documents only contain graphical entities, but no logical information about the structure of what is being displayed). This knowledge will eventually be exploited to enhance the HCI features provided by ZGRViewer (navigation, search, etc.).

AJaPaD is a work in progress, and does not yet support the whole DOT syntax. It is currently in alpha status. See the to do list.


Download

AJaPaD ships with the latest version of ZGRViewer for now. It is however fully independent of ZGRViewer and ZVTM, and will eventually be released on its own.


How to use AJaPaD?

All AJaPaD classes belong to package net.claribole.zgrviewer.dot.

Parsing DOT files

Parsing a DOT file is achieved by instantiating the ANTLR-based DOT lexer and parser and feeding the lexer an input stream. The resultign AST (abstract syntax tree) can then be transformed into a Graph data structure using a tree walker.

import net.claribole.zgrviewer.dot.*; import java.io.DataInputStream; import java.io.File; import java.io.FileInputStream; import java.io.FileNotFoundException; import antlr.CommonAST; import antlr.RecognitionException; import antlr.TokenStreamException; ... String f = ...; File file = new File(f); try { // input stream containing the DOT file DataInputStream input = new DataInputStream(new FileInputStream(file)); // DOT lexer and parser DOTLexer lexer = new DOTLexer(input); DOTParser parser = new DOTParser(lexer); parser.graph(); // parsing produces an abstract syntax tree CommonAST ast = (CommonAST) parser.getAST(); // this AST is transformed into a Graph data structure DOTTreeTransformer trans = new DOTTreeTransformer(); trans.graph(ast); CommonAST astTrans = (CommonAST) trans.getAST(); DOTTreeParser walker = new DOTTreeParser(); Graph g = walker.graph(astTrans); } catch (FileNotFoundException e) { System.err.println("File not found"); } catch (TokenStreamException e) { e.printStackTrace(); } catch (RecognitionException e) { e.printStackTrace(); } catch (Exception e) { e.printStackTrace(); }

Serializing the data structure

Serializing a graph is simply achieved by calling method toString() on the corresponding Graph object.

Graph g = ...; String serialization = g.toString();

Manipulating the data structure

A new graph is created by instantiating Graph and assigning a unique ID to it. Graph attributes can be changed by directly assigning them values.

String id = ...; // either Graph g = new Graph(id); // or Graph g = new Graph(); g.id = id; ... g.rankdir = Graph.LR;

Nodes, edges, subgraphs, etc. can be added by instantiating them and adding them to the graph. An edge can only be created after the nodes it links have been instantiated.

Graph g = ...; // a simple node BasicNode node1 = new BasicNode(g, "1st node"); // a more complex node (record) Record rec1 = new Record(g, "a record"); // a subrecord SubRecord f0 = new SubRecord(g, "f0", rec1);

More information about the AJaPaD API is available in Javadoc format.


To Do List


Credits

Hosted by SourceForge.net Logo