forked from humberto-ortiz/salHUD
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpr-testing-2.html
119 lines (82 loc) · 2.33 KB
/
pr-testing-2.html
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
<!DOCTYPE html>
<html lang = "en">
<head>
<meta charset = "utf-8">
<title>PR Total Population Visualization</title>
<script type = "text/javascript" src = "http://d3js.org/d3.v3.min.js"></script>
<script type = "text/javascript" src="http://d3js.org/queue.v1.min.js"></script>
<script type = "text/javascript" src = "http://d3js.org/topojson.v1.min.js"></script>
<style>
.land {
fill: none;
}
.boundary {
fill: none;
stroke: #999;
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>
</head>
<body>
<h1 style = "text-align: center";>PR Total Population Visualization</h1>
<script type = "text/javascript">
Array.min = function(array) {
return Math.min.apply(Math, array);
};
Array.max = function(array) {
return Math.max.apply(Math, array);
};
var width = 1200;
var height = 700;
var populationByID = d3.map();
var quantize = d3.scale.quantize()
.range(d3.range(9).map(function(i) {
return "q" + i + "-9";
}));
var path = d3.geo.path()
.projection(null);
var svg = d3.select("body")
.append("svg")
.attr("width", width)
.attr("height", height);
var pop_no = [];
queue()
.defer(d3.json, "pr.json")
.defer(d3.csv, "PR-FIPS.csv", function(data, i) {
populationByID.set(data.id, +data.population);
pop_no[i] = parseInt(data.population);
})
.await(ready);
function ready(error, pr) {
quantize.domain([
Array.min(pop_no),
Array.max(pop_no)
]);
svg.append("g")
.attr("class", "land")
.selectAll("path")
.data(topojson.feature(pr, pr.objects.municipios).features)
.enter()
.append("path")
.attr("class", function(d) {
return quantize(populationByID.get(d.properties.id));
})
.attr("d", path);
svg.append("path")
.datum(topojson.mesh(pr, pr.objects.municipios, function(a, b, c) { return a !== b !== c; }))
.attr("class", "boundary")
.attr("d", path);
console.log(pr);
};
</script>
</body>
</html>