wikiacademia

site
Back.

Prefuse Basics

Prefuse visualizations are built through the creation of three main components :

Datastructure

Visualization

Build Visualization

Now that we have a graph datastructure to visualize, we need to build a visualization to do so. Visualization objects are created and then given passed a datastructure to visualize :
viz = new Visualization(); viz.add("graph", graph);
Once the visualization is created, attributes about the interactivity of various components can be set. The following example sets the edges in the graph to be non-interactive, and the nodes to be interactive. The null value in the example is the predicate field. This field can be used to specify different interactivity rules based on the attributes of the node
viz.setInteractive("graph.edges", null, false); viz.setInteractive("graph.nodes", null, true);

Renderer Factories

The first step in creating a visualization for a particular datastructure is the creation and configuration of a renderer factory. The renderer factory can be used to create many different types of visualizations.

Action Lists

Action Lists are a collection of functions concerned with the drawing and animation of the visualized items.

Register Actionlists with Visualization

Once the actionlists have been created, they need to be registered with the visualization. This is done through the visualization objects putAction function
vis.putAction("draw", draw); vis.putAction("physics", physics);

Display

The final step in creating the prefuse visualization is the creation of the display. The display constructor takes the visualiztaion it will display as an argument
Display disp = new Display(vis);
Once the display is created, the size of the display, foreground and background colors are set.
disp.setSize(800,800); disp.setForeground(Color.GRAY); disp.setBackground(Color.WHITE);
Control listeners are basic interface controls provided by the prefuse toolkit. They are added using the displays addControlListener() function.
The Drag control allow the user to manually reposition nodes with their mouse :
disp.addControlListener(new DragControl());
The Pan control allows the user to move the display field on the X and Y axes :
disp.addControlListener(new PanControl());
The Zoom control allows the user to zoom in or out on selected areas of the visualization.
disp.addControlListener(new ZoomControl());
The ZoomToFit control allows the user to zoom the display to a size which fits all nodes present in the visualization:
disp.addControlListener(new ZoomToFitControl());

The Rest

Before the visualization is displayed, the actionlists must be run for the visualization. This is done with the visualizations run() function, taking the name of the actionlist as it's argument
vis.run("draw"); vis.run("physics");
The final task required is to create a JFrame, add the display to the frame and make it visible.
JFrame myFrame = new JFrame("Application"); myFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); myFrame.add(disp); myFrame.pack(); myFrame.setVisible(true);

Any questions, send me mail