Skip to content

Instantly share code, notes, and snippets.

@wilson428
Last active December 16, 2015 20:39
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wilson428/5493576 to your computer and use it in GitHub Desktop.
Save wilson428/5493576 to your computer and use it in GitHub Desktop.
Binify example
Display the source blob
Display the rendered blob
Raw
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>
.counties {
fill: #900;
}
.states {
fill: none;
stroke: #ccc;
stroke-linejoin: round;
}
</style>
<body>
<script src="http://d3js.org/d3.v3.min.js"></script>
<script src="http://d3js.org/queue.v1.min.js"></script>
<script src="http://d3js.org/topojson.v1.min.js"></script>
<script>
var width = 600,
height = 500;
var projection = d3.geo.albersUsa();
var path = d3.geo.path()
.projection(projection);
var svg = d3.select("body").append("svg")
.attr("width", width)
.attr("height", height);
var us, hexagons, remaining = 2;
d3.json("/d/4090846/us.json", function(json) {
us = json;
if (!--remaining) ready(us, hexagons);
});
d3.json("coordinates.json", function(json) {
hexagons = json;
if (!--remaining) ready(us, hexagons);
});
function ready(us, hexagons) {
var bins = topojson.feature(hexagons, hexagons.objects.binned).features;
var max = d3.max(bins, function(d) { return d.properties.COUNT; });
svg.append("g")
.attr("transform", "scale(0.6,0.6)")
.attr("class", "counties")
.selectAll("path")
.data(bins)
.enter().append("path")
.style("fill-opacity", function(d) { return Math.sqrt(d.properties.COUNT / max); })
.attr("d", path);
svg.append("path")
.datum(topojson.mesh(us, us.objects.states))
.attr("class", "states")
.attr("d", path)
.attr("transform", "scale(0.6,0.6)");
}
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment