[ Launch: Nesting With Rollup ] 8611599 by ljbrown238
-
-
Save ljbrown238/8611599 to your computer and use it in GitHub Desktop.
Nesting With Rollup
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
{"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} |
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
// 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 | |
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
[ | |
{ | |
"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