Last active
August 29, 2015 14:07
-
-
Save scogle/0e72d231ade698342582 to your computer and use it in GitHub Desktop.
d3.nest example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Insert this at the top of the process() function | |
// This part just converts the flat objec to a flat array, nothing fancy | |
var flatty = []; | |
_.each(data, function(obj, key) { | |
if ( key !== 'keys' ) { flatty.push(obj); } | |
}); | |
console.log(flatty); | |
var nested_data = d3.nest() // create the nest object | |
// this is the top level groupby | |
// I'm just using the momen() function to conver the StartTime into the day of the month | |
.key(function(entry){ return moment(entry.StartTime).date() }) | |
// this is the subgroup below the day of the month | |
.key(function(entry){ return entry.Sponsor }) | |
// This is the third level where it's grouped by Task | |
.key(function(entry){ return entry.Task }) | |
// I have no idea why the data is inserted last | |
.entries(flatty); | |
console.log(nested_data); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment