Skip to content

Instantly share code, notes, and snippets.

@scogle
Last active August 29, 2015 14:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save scogle/0e72d231ade698342582 to your computer and use it in GitHub Desktop.
Save scogle/0e72d231ade698342582 to your computer and use it in GitHub Desktop.
d3.nest example
// 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