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?

5 comments:

  1. Will you be expanding this to cover all of GV API, a la QGoogleVisualizationAPI for PHP?

    ReplyDelete
  2. Sadly my time to work on this is limited by other priorities. I have talked to another developer on github about combining projects. He's written a gem and it covers most of the visualization api with the exception of the google motion chart, which is the only thing that I cover. Here is a link to his gem.

    ReplyDelete
  3. Hi Max, this is a great gem. Do you plan on covering the Annotated Time Line in the Visualization API?

    I'm using Matteti's gem right now for charts. It's nice, but it would be great to have the interaction as with the Visualization graphs.

    ReplyDelete
  4. I've recently updated the wiki for this plugin on github. Adding the timeline shouldn't be much of a problem. I'll find the time to do it soon. Keep on bugging me.

    ReplyDelete
  5. Thanks Max, you the man.

    I actually found plugin for the timeline and Ben (the creator) told me he is updating the features this week. I've been using it and it works nicely.

    http://github.com/benstein/annotatedtimeline-for-rails/tree/master

    I'm going to try out your gapminder plugin this week too.

    Thanks.

    ReplyDelete