Skip to content

Instantly share code, notes, and snippets.

@mbostock

mbostock/.block Secret

Forked from mbostock/.block
Last active Feb 9, 2016
Embed
What would you like to do?
Circle Packing Zero Values
license: gpl-3.0
<!DOCTYPE html>
<meta charset="utf-8">
<body>
<style>
circle {
stroke: #000;
fill-opacity: .1;
}
</style>
<script src="//d3js.org/d3.v3.min.js"></script>
<script>
var data = {
children: [
{value: 1.94},
{value: 0.42},
{value: 0},
{value: 3.95},
{value: 0.06},
{value: 0.91}
]
};
var width = 960,
height = 500;
var pack = d3.layout.pack()
.sort(d3.descending)
.size([width, height]);
var svg = d3.select("body").append("svg")
.attr("width", width)
.attr("height", height);
svg.data([data]).selectAll(".node")
.data(pack.nodes)
.enter().append("circle")
.attr("class", "node")
.attr("transform", function(d) { return "translate(" + d.x + "," + d.y + ")"; })
.attr("r", function(d) { return d.r; });
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.