Skip to content

Instantly share code, notes, and snippets.

@adg29
Forked from mbostock/.block
Last active April 27, 2017 18:00
Show Gist options
  • Save adg29/4411249 to your computer and use it in GitHub Desktop.
Save adg29/4411249 to your computer and use it in GitHub Desktop.
County Circles

This symbol map encodes the area of each county using a circle at the county's centroid.

Display the source blob
Display the rendered blob
Raw
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
<!DOCTYPE html>
<meta charset="utf-8">
<style>
circle {
fill: none;
stroke: steelblue;
}
circle.wood-gyprock-base{
fill: #FFC162;
stroke: #FFC162;
}
circle.wood-gyprock-first{
fill: #7F6131;
fill: #FFC162;
}
</style>
<body>
<script src="http://d3js.org/d3.v3.min.js"></script>
<script src="http://d3js.org/topojson.v0.min.js"></script>
<script>
var width = 960,
height = 500;
var path = d3.geo.path();
var svg = d3.select("body").append("svg")
.attr("width", width)
.attr("height", height);
d3.json("../4090846/us.json", function(error, us) {
svg.selectAll("circle")
.data(topojson.object(us, us.objects.counties).geometries)
.enter().append("circle")
.attr("class", functiion(d) { var hue_name = "wood-gyprock-base"; if(d%2==0) { hue_name = "wood-gyprock-first"; } return hue_name; })
.attr("transform", function(d) { return "translate(" + path.centroid(d) + ")"; })
.attr("r", function(d) { return Math.sqrt(path.area(d) / Math.PI); });
});
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment