protovis part 3: variables and animation
Variables
Simply put, variables are shorthand for code that you want to reuse. We're going to create a set of variables at the top of the script that will allow us to edit the finished chart in the fewest steps possible. Make sure your preview window is open.
Lets start by typing the letters v-a-r, hit space and type w = 150 and add a comma.
We have just written a variable that says if the letter w is found in our code, its value will always be 150. We'll use this as our width.
Hit return and hit Tab then type h = 150, this will be our height.
Hit return and type r = w/2, r will be used to define the radius of our wedge chart. because w = 150, when it's divided by two we get a radius of 75
Hit return and type data = now copy the data array from the wedge chart. Make sure to include the square brackets. paste the array after the "data =" variable then type a comma at the end.
Hit return and type sum = pv.sum(data), We're going to use a different method to calculate the wedges in this chart because we want to preserve the values in the data array to create labels.
Finally, hit return and type colors = [] (square brackets). Now copy the colors from the fill style and paste them into the square brackets. Make sure to end the chain with a semicolon.

