Skip to content

Instantly share code, notes, and snippets.

@mbostock

mbostock/.block Secret

Last active February 9, 2016 01:07
Show Gist options
  • Save mbostock/1627378 to your computer and use it in GitHub Desktop.
Save mbostock/1627378 to your computer and use it in GitHub Desktop.
Circle Packing with 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()
.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