GraphUtil.treemap(): request for example/documentation on usages with different aggregate functions.

35 views
Skip to first unread message

Jonathan Fan

unread,
Feb 8, 2010, 12:34:14 AM2/8/10
to juicekit
From the doc of
http://www.juicekit.org/flexlib/asdoc/org/juicekit/util/data/GraphUtil.html

It was mentioned in the treemap method that
--------------------------
Metrics will sum by default.

You can perform different calculations on the metrics using flare
query expressions.
--------------------------

However, from the API,
treeMap(dataArray:Array, levels:Array, metrics:Array,
rowFilter:Function = null):Tree

My questions are:
1) It is not clear to how we can assign expressions to each one of the
grouping metrics (for instance, I need to provide an average income
for avg_income in this example), would you please shred some light on
this?
2) To take this example a bit further, there are scenarios which
require the considerations of different fields before rolling up to
the parent level (we have to provide a weighted avg_income depending
on the number of people), can the flare query expression achieve this?


Chris Gemignani

unread,
Feb 8, 2010, 7:21:27 PM2/8/10
to juic...@googlegroups.com
Hi Jonathan:

JuiceKit supports basically anything you could do in a Flare Query select clause as values for the metrics Array. 

The items in the metrics Array can be either strings or Objects. If they're strings they're treated like properties and are summed, as you noted. If they're objects, the keys of the objects are the resulting variable names and the values are Flare Query Expressions that say what you want to calculate. It's simpler if we consider some examples. Imagine you have some demographic data. Each row has gender, state, age, population in 2009, population in 2000, and average income. One row might look like this:

{gender: 'Male', state: 'California', age: 21, population2009: 250250, population2000: 240129, averageIncome: 20145 }


import flare.query.methods.*;

myData = treemap(data, ['state', 'gender'], ['population2009', 'population2000', {avgIncome: weightedavg('averageIncome', 'population2009')})

This gives you a treemap with groupings first by state then by gender. Three variables are available at every level of the treemap, the sum of population in 2009, the sum of population in 2000, and the weighted average of average income weighted by 2009 population.

There are lots of query expressions (check out flare.query.methods) that let you perform calculations. JuiceKit has added a few extras to the basics that Flare provides to support weighted averages (weightedavg) and percentage change (pctchange).  The Flare Query syntax takes a little getting used to, if you have a specific example, I'd be glad to help you gethe result you need.

Cheers,
Chris






--
You received this message because you are subscribed to the Google Groups "juicekit" group.
To post to this group, send email to juic...@googlegroups.com.
To unsubscribe from this group, send email to juicekit+u...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/juicekit?hl=en.




--
Chris Gemignani
Juice Analytics
phone: 571.205.4789
Reply all
Reply to author
Forward
0 new messages