Skip navigation links

Package diva.graphx

The diva.graphx package provides extensible and interactive viewing of graph data structures.

See: Description

Package diva.graphx Description

The diva.graphx package provides extensible and interactive viewing of graph data structures. The name stands for "graph extension," by which we mean that the package is designed to be used with your existing graph data structure to make it visible and editable. Your graph data structure does not have to be modified to be used this way.

To be able to read and manipulate your graph structure, the package requires that you implement two interfaces, NodeModel and EdgeModel. Each of these is an adapter (perhaps we should have named them that way) to nodes or edges of your graph. For example, EdgeModel has method such as

java.lang.Object getHead(java.lang.Object edge);
java.lang.Object getTail(java.lang.Object edge);
boolean isDirected(java.lang.Object edge);
By implementing this interface, you provide diva.graphx with enough access to your graph structure to read and manipulate it. You will notice that the argument types above are all Object, so we are losing some type-safety in trade for this flexibility.

To draw your graph in a canvas pane, diva.graphx needs you to also implement the interfaces NodeRenderer and EdgeRenderer. Each of these has a method that takes a node or edge object as argument, constructs a diva.canvas.Figure, and returns it. diva.graphx will add this figure to the canvas, and place or route it appropriately.

The key strength of diva.graphx is thus its ability to allow you to quickly construct an interactive, MVC-architecture, editing pane for your graphs. More complex editors can be built on top of this functionality if desired. For simple applications, diva.graphx provides a simple attributed graph data structure that can be used.

Graphs can also be constructed programmatically. Here is an example of instantiating a simple graph with two nodes connected by an edge ( A -> B ).

// Construct the widgets
Frame f = new Frame();
JGraph g = new JGraph();
f.add("Center", g);

// Construct the graph
BasicNode a = new BasicNode("a");
BasicNode b = new BasicNode("b");
BasicEdge e = new BasicEdge("e");
jg.getModel().addNode(a);
jg.getModel().addNode(b);
jg.getModel().connect(e, a, b);

// Display it all
f.setVisible(true);

Skip navigation links

Copyright © 2023 Central Laboratory of the Research Councils. All Rights Reserved.