Monday, April 6th, 2009

Great visualizations with Protovis

Category: Canvas, JavaScript

I have been very impressed with Andrew Sutherland of the Mozilla Messaging team (which is one reason that I have faith that I will dump Gmail for something he and the Messaging team come up with one day ;) and the visualizations that he is playing with are quite cool indeed. Seeing your email in different ways (not just in a table) can open the eyes.

Andrew is using Protovis “a visualization toolkit for JavaScript using the canvas element. It takes a graphical approach to data visualization, composing custom views of data with simple graphical primitives like bars and dots. These primitives are called marks, and each mark encodes data visually through dynamic properties such as color and position.”

There are some cool examples such as:


  1. new pv.Panel().width(150).height(150)
  2.     .add(pv.Panel)
  3.       .data([[Math.sin(x / y)
  4.              for (x in pv.range(50))]
  5.              for (y in pv.range(3, 9))])
  6.     .add(pv.Area)
  7.       .data(function(d) d)
  8.       .fillStyle(pv.Colors.category19.unique)
  9.       .bottom(function() let (c = this.cousin())
  10.           c ? (c.bottom + c.height) : 0)
  11.       .height(function(d) (d + 1) * 13)
  12.       .left(function() this.index * 3)
  13.     .root.render();

which produces .

Very cool indeed!

Posted by Dion Almaer at 8:29 am

4 rating from 20 votes


Comments feed TrackBack URI

Hah! what a not-so-subtle teaser, “for something he and the Messaging team come up with one day ;).”

Protovis looks very interesting.

Comment by britg — April 6, 2009

Protovis looks very nice, runs slick. the PolarClock demo is something I want in my house. haha.

Comment by bladesling — April 6, 2009

very cool… but can we try to not make the code snippet a single line of code which is far too complicated to understand what is going on… why do people constantly feel that writing code in fewer lines is better?

There may be some slight (and I nanosecond) gains from doing this, but if you are trying to illustrate a point in terms of how easy it is to use this framework, wouldn’t you want the code to be understandable?

Comment by PuckPuck — April 6, 2009

@PuckPuck – There is nothing wrong, and many things right, with a simple, declarative style. This looks to me like the design pattern where the methods of an object return the object itself, which lets the user chain the calls together. In this example the calls are nested to reflect the structure of the object itself. It looks like you could build a Panel object in the traditional way, assigning it to a named variable and calling the methods in order.

Comment by JonathanLeech — April 6, 2009

@JonathanLeech – I understand there is nothing wrong with the coding style, in fact i do it myself all the time…. BUT when you are trying to illustrate examples, for people to understand the code, does it really hurt to write code that explains itself? Does your right pinky hurt that much from hitting semi-colon?

It’s obvious the developers who wrote this code are quite advanced, and they want to target other advanced developers, yet because they wrote the code as complicated as possible, they just shunned the junior developers away… simplification isn’t always fewer characters.

Comment by PuckPuck — April 6, 2009

Leave a comment

You must be logged in to post a comment.