[ Launch: JSON Traverse Object ] 8561241 by ljbrown238
-
-
Save ljbrown238/8561241 to your computer and use it in GitHub Desktop.
JSON Traverse Object
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":"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 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
// 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