-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.js
54 lines (39 loc) · 1.24 KB
/
main.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
var width = 960,
height = 600;
var rateById = d3.map();
var quantize = d3.scale.quantize()
.domain([0, .15])
.range(d3.range(9).map(function(i) {
var result = "q" + i + "-9";
console.log(result);
return result;
}));
var projection = d3.geo.albersUsa()
.scale(1280)
.translate([width / 2, height / 2]);
var path = d3.geo.path()
.projection(projection);
var svg = d3.select(".map").append("svg")
.attr("width", width)
.attr("height", height);
queue()
.defer(d3.json, "us-topo.json")
.defer(d3.csv, "2016_cand_scrubbed.csv", function(d) {
rateById.set(d.id, +d.TransactionAmount); })
.await(ready);
function ready(error, us) {
console.log('the fuck is this');
if (error) throw error;
svg.append("g")
.attr("class", "counties")
.selectAll("path")
.data(topojson.feature(us, us.objects.counties).features)
.enter().append("path")
.attr("class", function(d) { return quantize(rateById.get(d.id)); })
.attr("d", path);
svg.append("path")
.datum(topojson.mesh(us, us.objects.states, function(a, b) { return a !== b; }))
.attr("class", "states")
.attr("d", path);
};
d3.select(self.frameElement).style("height", height + "px");