Skip to content

Instantly share code, notes, and snippets.

@ljbrown238
Created January 22, 2014 15: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/8561241 to your computer and use it in GitHub Desktop.
Save ljbrown238/8561241 to your computer and use it in GitHub Desktop.
JSON Traverse Object
{"description":"JSON Traverse Object","endpoint":"","display":"svg","public":true,"require":[],"fileconfigs":{"inlet.js":{"default":true,"vim":false,"emacs":false,"fontSize":12},"_.md":{"default":true,"vim":false,"emacs":false,"fontSize":12},"config.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,"thumbnail":"http://i.imgur.com/PJdiTj4.png"}
// This example shows how to summarize the values of children into each parent
var root = {
"name": "root",
"children": [
{
"name": "a",
"children": [
{
"name": "a1",
"size": "1"
},
{
"name": "a2",
"size": "2"
}
]
},
{
"name": "b",
"children": [
{
"name": "b1",
"size": "3"
}
]
},
{
"name": "c",
"size": "4"
}
]
};
// Create a function that will summarize all children sizes into new property named "value"
var partition = d3.layout.partition()
.value(function(d){return d.size;})
.children(function(d){return d.children;})
//.sort(null); //optional: turns off sorting, comment out defaults to sort by descending size
partition(root); // This process calculates the value to be the sum of the children's sizes
console.log(root);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment