Programming Visualization

Fun With Prefuse

Couple of things I found using Prefuse that I’ll document here for reference (I had a hard time finding the answer to these).

1. NullPointerException thrown by GraphMLReader

This means there’s an issue in the XML, even if it’s valid according to W3Schools (which mine was). Double check it, for me it was an issue where I declare my keys – I’d created a key called “dist” but then I was referring to it by “type”. That kind of thing will cause an NPE, but no better explanation (and can be a total pain to fix).

2. NullPointerException thrown in ColorAction

If  you create an OrdinalMap for your DataColorAction, but at run time you’re getting an NPE or other exception (colors not showing) check that everything you have for that field is in your OrdinalMap. For instance, if your map contains “A”, “B” and “C”, but your GraphML refers to a “D” you’ll get an exception but no explanation as to what is missing, which can make it difficult to work out what’s going on.

3. Converting to Applet

Use JPrefuseApplet for this. Extend that for your applet class, and then you’ll want something like:

this.getContentPane().add(new MyPrefuseCreation(graph));

Where MyPrefuseCreation extends the Prefuse Display Object. You’ll probably need to change some bits of your code in accordance with this. Also, Display has a field called m_vis, which holds the visualization when you call the Display(Visualization) constructor.

You’ll need to get in your graph by loading it from a URL, which you can make a parameter in your applet html embed code.

Finally, when it came to embedding the applets, the html was fairly simple working from an example applet – check out the prefuse gallery and click view source to see how they do it.

Loads of new graphs uploaded, see them here.