Prefuse is a very nice visualization toolkit. It is written in Java, it uses Java2D APIs to draw nodes, edges, and other visual items. It also handles events, supports animations, and other things you need to make the visualization become interactive.
Okay, enough for the introduction. The purpose of this post is I want to show you how to use Prefuse through Jython. Yes, to make Prefuse (er.. Java, actually) scriptable!
First, prepare the Jython installation.
$ wget http://downloads.sourceforge.net/jython/jython_installer-2.5.0.jar $ java -jar jython_installer-2.5.0.jar
Create Prefuse jar file. I have made one and you can freely use it.
$ wget http://labs.fajran.web.id/p/ubuntu-pkg-vis/lib/prefuse.jar
Set environment variables. The first one is path to Jython installation.
$ export PATH=$PATH:/path/ke/lokasi/instalasi/jython
JYTHONPATHso Jython can recognize the Prefuse library.
$ export JYTHONPATH=$JYTHONPATH:prefuse.jar
Make sure the setup is woking.
$ jython >>> import prefuse
If you get no error, then good! Prefuse has been set up properly. Then do whatever you want!
I have made a Jython script that calls Prefuse. Check it out at http://gist.github.com/32288. Let’s try to use it as a demo.
$ wget -O igv.py http://gist.github.com/raw/32288/503d011d94c564ffbdca91296b3fc204cf7b5186
Now you have a Jython module called
igv. It will handle the basic Prefuse initialization things. You just need to do the following to use it.
$ jython >>> from igv import InteractiveGraphVisualization >>> ig = InteractiveGraphVisualization()
That’s for the initialization and now let’s try to add some nodes and edges.
>>> n1 = ig.add_node("satu") >>> n2 = ig.add_node("dua") >>> n3 = ig.add_node("tiga") >>> ig.add_edge(n1, n2) >>> ig.add_edge(n1, n3) >>> ig.add_edge(n2, n3)
And this is the obligatory screencast.
um.. yes, this is the translation of my previous blog entry discussing the same thing.