Last active
January 17, 2016 22:45
-
-
Save cflavs/314e7236c8af9170ed66 to your computer and use it in GitHub Desktop.
Pack
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
<!doctype html> | |
<html> | |
<head> | |
<title> D3 Tutorial </title> | |
<script src="//d3js.org/d3.v3.min.js"></script> | |
</head> | |
<body> | |
<script> | |
var width = 800, height = 600; | |
var canvas = d3.select("body").append("svg") | |
.attr("width", width) | |
.attr("height",height) | |
.append("g") | |
.attr("transform", "translate(50,50"); | |
var pack = d3.layout.pack() | |
.size([width, height -50]) | |
.padding(10); | |
d3.json("mydata.json", function(data){ | |
var nodes = pack.nodes(data); | |
var node = canvas.selectAll(".node") | |
.data(nodes) | |
.enter() | |
.append("g") | |
.attr("class", "node") | |
.attr("transform", function(d){ | |
return "translate("+ d.x + "," + d.y + ")";}); | |
node.append("circle") | |
.attr("r", function (d) {return d.r;}) | |
.attr("fill", "steelblue") | |
.attr("opacity", 0.25) | |
.attr("stroke", "#ADADAD") | |
.attr("stroke-width", "2"); | |
node.append("text") | |
.text(function (d) { return d.children ? "" : d.name}) | |
}); | |
</script> | |
</body> | |
</html> |
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
{ | |
"name": "Max", | |
"value": 100, | |
"children": [ | |
{ | |
"name": "Sylvia", | |
"value": 75, | |
"children": [ | |
{"name": "Craig", "value": 25}, | |
{"name": "Robin", "value": 25}, | |
{"name": "Anna", "value": 25} | |
] | |
}, | |
{ | |
"name": "David", | |
"children":[ | |
{"name": "Jeff", "value": 25}, | |
{"name": "Buffy", "value": 25} | |
] | |
}, | |
{ | |
"name": "Mr. X", | |
"value": 75 | |
} | |
] | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment