Thursday, June 19, 2008

Google Visualization Library (Gap Minder) and a nice little plugin

Google bought Hans Roslings Gap Minder over a year ago and I've been dying for them to release an API ever since. They've finally done it. The animated bubble charts were what I really wanted to sink my teeth into so naturally I've built a rails plugin to do just that. The API itself is javascript and flash. It promises to not store/steal your data, but writing all your data out in javascript is less than desirable. So how about something like this:

<% gap_minder_for(@collection, :width => 500, :height => 300) do |gm| %>
<% gm.label("Department") {|c| c.department } %>
<% gm.time("Time") {|c| c.time } %>
<% gm.x("X Procedure") {|c| c.x_procedure * 2 } %>
<% gm.y("Y Procedure") {|c| c.y } %>
<% gm.bubble_size("Volume of Cases") {|c| c.volume } %>
<% gm.extra_column("Something extra to select") {|c| c.extra_stuff } %>
<% end %>

I like it.

To explain it's simply a block helper calling a templating class and doing some funky meta-programming to make it as extensible as you want it. There are 5 required method calls on the gap minder object passed to the block (label, time, x, y, and bubble_size).

There are 2 other note worthy methods. First, color. Be default the color procedure keeps track of the label procedure values and assigns a color accordingly. You can override that with your own block passed in the same way that the other methods are passed (first argument is the title, the block receives an item of your collection).

The second method of note is extra_column. This can be called any number of times. With this tool x, y, z, and even the color metric used in the graph can be selected from drop downs. By adding extra columns you can add other data as selectable options.

It's that simple. It's up on github. Enjoy!

Special thanks to Mark Daly for trudging through the Google documentation for me and pushing me to meet deadlines. C2X, right?