How to visualize DEX graph database? (export) with Java

37 views
Skip to first unread message

DEX graphdb

unread,
Feb 14, 2013, 8:53:02 AM2/14/13
to dex...@googlegroups.com
In order to visualize DEX graph database you should export the database to a format such as graphml, that is able to be visualized. DEX also supports graphviz.

To export the graph you should add this code in your application:

DefaultExport exp = new DefaultExport();
g.export("HelloDex.graphviz", ExportType.Graphviz, exp);
g.export("HelloDex.graphml", ExportType.YGraphML, exp);

One or other export method depending on the type you wish to export it to. 

This would use the default exporter, to make your own:

public class MyExport extends com.sparsity.dex.gdb.ExportManager
    {
        private com.sparsity.dex.gdb.Graph g = null;
       
        public MyExport() {
        }
        @Override public void prepare(com.sparsity.dex.gdb.Graph graph) {
            // This method will be called once at the beginning of the export.
            // So we keep the graph being exported.
            g = graph;
        }
        @Override public void release() {
            // Called once at the end of the export process.
            g = null;
        }
        @Override public boolean getGraph(com.sparsity.dex.gdb.GraphExport graphExport) {
            // Called once to get the Graph details (a label)
            graphExport.setLabel("[dexjava] MyGraph");
            return true;
        }
        @Override public boolean enableType(int type) {
            // Will be called once for each type to allow or deny the export of
            // the nodes/edges of each type
            return true; // We enable the export of all types
        }
        @Override public boolean getNode(long node, com.sparsity.dex.gdb.NodeExport nodeExport) {
            // Called once for each node of an allowed type to get it's export definition.
            // The definition will be used if it returns true, or the default
            // node type definition from getNodeType will be used if this method
            // returns false.
            // It can set the label, shape, color, ...
            nodeExport.setLabel("[dexjava] MyNode " + node);
            return true;
        }
        @Override public boolean getNodeType(int type, com.sparsity.dex.gdb.NodeExport nodeExport) {
            // Used to get a node type generic export definition.
            // Called once for each node only if the call to GetNode returned false.
            // It can set the label, shape, color, ...
            nodeExport.setLabel("[dexjava] MyNodeType " + type);
            return true;
        }
        @Override public boolean getEdge(long edge, com.sparsity.dex.gdb.EdgeExport edgeExport) {
            // Called once for each edge of an allowed type to get it's export definition.
            // The definition will be used if it returns true, or the default
            // edge type definition from getEdgeType will be used if this method
            // returns false.
            // It can set the label, shape, color, ...
            edgeExport.setLabel("[dexjava] MyEdge " + edge);
            return true;
        }
        @Override public boolean getEdgeType(int type, com.sparsity.dex.gdb.EdgeExport edgeExport) {
            // Used to get an edge type generic export definition.
            // Called once for each edge only if the call to GetEdge returned false.
            // It can set the label, shape, color, ...
            edgeExport.setLabel("[dexjava] MyEdgeType " + type);
            return true;
        }
    }

Use your new exporter like this: 

        MyExport myExp = new MyExport();
        g.export("HelloDex.graphviz", ExportType.Graphviz, myExp); 
        g.export("HelloDex.graphml", ExportType.YGraphML, myExp); 

You can use any visual graph application that supports the formats, and import your HelloDex.graphml or HelloDex.graphviz file.

Reply all
Reply to author
Forward
0 new messages