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 http://downloads.sourceforge.net/jython/jython_installer-2.5.0.jar
    $ java -jar jython_installer-2.5.0.jar
    
  2. 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
    
  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 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
  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.

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 http://downloads.sourceforge.net/jython/jython_installer-2.5.0.jar
    $ java -jar jython_installer-2.5.0.jar
    
  2. 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
    
  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 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
  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.

Prefuse + Jython = Keren

English version of this post can be read at http://ngoprek.fajran.web.id/2009/07/using-prefuse-through-jython.html

Setelah semalem nyobain Jython, jadi kepikiran tuk make Prefuse dari Jython. Ternyata bisa! Utak-atik dikit lagi, dan jadilah sesuatu yg lebih menarik. Silakan lihat di screencast berikut =P

Kodingan bisa dilihat di http://gist.github.com/32288

Kalau mau nyoba:

  1. Download dan install Jython 2.5b0

    $ wget http://downloads.sourceforge.net/jython/jython_installer-2.5b0.jar
    $ java -jar jython_installer-2.5b0.jar
    

    Silakan atur sendiri lokasi instalasi.

  2. Download library prefuse.

    $ wget http://labs.fajran.web.id/p/ubuntu-pkg-vis/lib/prefuse.jar
    
  3. Atur environment variable

    $ export PATH=$PATH:/path/ke/lokasi/instalasi/jython
    $ export JYTHONPATH=$JYTHONPATH:prefuse.jar
    

    Pastikan kalo jalanin jython, muncul interactive shell-nya. Dan bisa ngejalanin yang berikut

    >>> import prefuse
    
  4. Download kodingan yg saya buat.

    $ wget -O igv.py http://gist.github.com/raw/32288/503d011d94c564ffbdca91296b3fc204cf7b5186
    
  5. Jalanin deh..

    $ jython
    >>> from igv import InteractiveGraphVisualization
    >>> ig = InteractiveGraphVisualization()
    
  6. Tambahin node dan edge

    >>> 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)
    

Selamat menikmati =D

Nyoba2 layouting di Prefuse

Bikin sesuatu yg bernama LevelLayout. Terpaksa dibikin berhubung NodeLinkTreeLayout yang diharapkan tuk bekerja ternyata tidak bekerja. Yaa.. sekalian lah.

Pake data versi lengkap tetep aja lemotubbies. Jadi bikin data versi rada kecil namun komplit. Uh, ini apa emang musti dioptimasi atau emang prefusenya aja yang dodolz?

Oya, sekarang kodingan udah ditaro juga di github. Coba diintip di http://github.com/fajran/ubuntu-pkg-vis-prefuse/tree/master

Memvisualisasikan dependensi paket Ubuntu

Sebelum ngerjain tesis, mari kita pemanasan dulu =P

Gambar di atas adalah cuplikan dari aplikasi kecil yang memvisualisasikan dependensi paket-paket di Ubuntu Intrepid Ibex (mudah2an sih ngga salah menyusun data dependensinya =P) Dibuat pake Java dengan bantuan Prefuse.

Kalau mau nyoba2, silakan donlod aplikasinya lalu coba2 masukkan sebuah nama paket. Kalau udah muncul di layar, klik nama paketnya supaya paket-paket lain yg terhubung ikutan muncul.

  1. Download

    $ wget http://labs.fajran.web.id/p/ubuntu-pkg-vis/ubuntu-pkg-vis-0.1.tar.bz2
    
  2. Extract

    $ tar xjf ubuntu-pkg-vis-0.1.tar.bz2
    
  3. Jalankan

    $ cd p
    $ java -Xmx512M -cp .:prefuse.jar id/web/fajran/vis/ubuntupkg/Main orig/
    

Yayaya.. memang sangat berat! Seluruh data paket dibaca dan masuk ke memory. Selain itu, proses layouting dg Force Directed Layout emang berat, apalagi kalau datanya banyak. Walau sebenarnya diharapkan untuk tidak terlalu berat2 amat berhubung tidak seluruh data ditampilkan. Namun sepertinya Prefuse masih bermasalah dalam hanya-mengutak-atik-data-yang-tampil-saja.

Kalau mau pake subset-tidak-lengkap data yang lebih kecil, coba ganti orig/ menjadi small/

$ java -Xmx512M -cp .:prefuse.jar id/web/fajran/vis/ubuntupkg/Main small/

Contoh paket yang lumayan dapat dilihat dalam data kecil ini adalah pinot, jadi coba cari paket tsb.

Source code? err.. berhubung aplikasi ini beneran tuk icip2 Prefuse, saya gak nyimpen source code nya xD ada sih, tapi udah babak belur di sana sini. Nanti aja kalo saya udah gapé pake Prefuse, saya bikin lagi aja yg baru =P