Skip to content

Instantly share code, notes, and snippets.

@lalyos
Forked from mbostock/.block
Last active December 12, 2015 05:08
Show Gist options
  • Save lalyos/4719658 to your computer and use it in GitHub Desktop.
Save lalyos/4719658 to your computer and use it in GitHub Desktop.

Let's see where are the buyers of g360!

<!DOCTYPE html>
<meta charset="utf-8">
<style>
.states {
fill: none;
stroke: #fff;
stroke-linejoin: round;
}
.q0-9 { fill:rgb(247,251,255); }
.q1-9 { fill:rgb(222,235,247); }
.q2-9 { fill:rgb(198,219,239); }
.q3-9 { fill:rgb(158,202,225); }
.q4-9 { fill:rgb(107,174,214); }
.q5-9 { fill:rgb(66,146,198); }
.q6-9 { fill:rgb(33,113,181); }
.q7-9 { fill:rgb(8,81,156); }
.q8-9 { fill:rgb(8,48,107); }
</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.v0.min.js"></script>
<script>
var width = 960,
height = 500;
var quantize = d3.scale.quantize()
.domain([0, .15])
.range(d3.range(9).map(function(i) { return "q" + i + "-9"; }));
var path = d3.geo.path();
var svg = d3.select("body").append("svg")
.attr("width", width)
.attr("height", height);
queue()
.defer(d3.json, "/d/4090846/us.json")
.defer(d3.tsv, "unemployment.tsv")
.await(ready);
function ready(error, us, unemployment) {
var rateById = {};
unemployment.forEach(function(d) { rateById[d.id] = +d.rate; });
svg.append("g")
.attr("class", "counties")
.selectAll("path")
.data(topojson.object(us, us.objects.counties).geometries)
.enter().append("path")
.attr("class", function(d) { return quantize(rateById[d.id]); })
.attr("d", path);
svg.append("path")
.datum(topojson.mesh(us, us.objects.states, function(a, b) { return a.id !== b.id; }))
.attr("class", "states")
.attr("d", path);
}
</script>
We can make this file beautiful and searchable if this error is corrected: It looks like row 2 should actually have 2 columns, instead of 1. in line 1.
id rate
12342 400.9900016784668
12345 0.0
22301 13118.940175781026
22314 120.68000030517578
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment