Skip to content

Instantly share code, notes, and snippets.

@ljbrown238
Created January 25, 2014 03:54
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 ljbrown238/8611599 to your computer and use it in GitHub Desktop.
Save ljbrown238/8611599 to your computer and use it in GitHub Desktop.
Nesting With Rollup
{"description":"Nesting With Rollup","endpoint":"","display":"svg","public":true,"require":[],"fileconfigs":{"inlet.js":{"default":true,"vim":false,"emacs":false,"fontSize":12},"myData.json":{"default":true,"vim":false,"emacs":false,"fontSize":12}},"fullscreen":false,"play":false,"loop":false,"restart":false,"autoinit":true,"pause":true,"loop_type":"pingpong","bv":false,"nclones":15,"clone_opacity":0.4,"duration":3000,"ease":"linear","dt":0.01}
// Tributary specific
var svg = d3.select("svg");
// This is how you access a JSON file added in Tributary.io
// In this case the json file was called "data.json" so the file
// data is accessed by the variable "tributary.data" or "tributary.[filenameWithoutExtension]
var people = tributary.myData;
// console.log(people);
var nestedData = d3.nest()
.key(function(d) {return d.gender;})
.sortKeys(d3.ascending)
.rollup(function(d) {
return {
age:d
};
})
.entries(people);
console.log(nestedData);
console.log(nestedData[0].values.age[0]); // Kandi
console.log(nestedData[0].values.age[1]); // Laura
console.log(nestedData[1].values.age[0]); // Loren
console.log(nestedData[1].values.age[1]); // LorenJoe
[
{
"first":"Loren",
"last":"Brown",
"gender":"Male",
"Age":"47"
},
{
"first":"Kandi",
"last":"Brown",
"gender":"Female",
"Age":"50"
},
{
"first":"Laura",
"last":"Brown",
"gender":"Female",
"Age":"19"
},
{
"first":"LorenJoe",
"last":"Brown",
"gender":"Male",
"Age":"47"
}
]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment