Using Prefuse through Jython

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.

The visualization display is implemented on top of JComponent. So it is very easy to embed it on another application, like what I did in LuaDeskSpot (source).

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!

  1. First, prepare the Jython installation.

    $ wget
    $ java -jar jython_installer-2.5.0.jar
  2. Create Prefuse jar file. I have made one and you can freely use it.

    $ wget
  3. Set environment variables. The first one is path to Jython installation.

    $ export PATH=$PATH:/path/ke/lokasi/instalasi/jython

    Secondly, set JYTHONPATH so Jython can recognize the Prefuse library.

    $ export JYTHONPATH=$JYTHONPATH:prefuse.jar
  4. 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!

  5. I have made a Jython script that calls Prefuse. Check it out at Let’s try to use it as a demo.

    $ wget -O
  6. 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.

Have fun!

um.. yes, this is the translation of my previous blog entry discussing the same thing.

Leave a Reply