-
Notifications
You must be signed in to change notification settings - Fork 3
/
index.html
81 lines (69 loc) · 1.85 KB
/
index.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
<!DOCTYPE html>
<meta charset="utf-8">
<style>
body {
width:960px;
margin:0 auto;
background:#000;
color:#eee;
}
h1 {
text-align:center;
font-family:monospace;
}
p {
text-align:center;
}
a {
color:magenta;
}
</style>
<body>
<h1>englewood.js</h1>
<p><a href='https://github.com/tmcw/englewood.js'>dot density maps in javascript</a> using canvas</p>
<script src="d3.v3.min.js"></script>
<script src="http://d3js.org/topojson.v0.min.js"></script>
<script src="index.js"></script>
<script>
var width = 960,
height = 500;
var projection = d3.geo.albers()
.scale(1000);
var canvas = d3.select("body").append("canvas")
.attr("width", width)
.attr("height", height)
.style('display', 'none');
var canvas2 = d3.select("body").append("canvas")
.attr("width", width)
.attr("height", height);
var context = canvas.node().getContext('2d');
var c2 = canvas2.node().getContext('2d');
var path = d3.geo.path()
.projection(projection)
.context(context);
var path2 = d3.geo.path()
.projection(projection)
.context(c2);
d3.csv('census_pop.csv', function(error, pop) {
d3.json('us.json', function(error, us) {
topojson.object(us, us.objects.states).geometries.forEach(function(state) {
context.fillStyle = 'rgb(255, 255, ' + (255 - state.id) + ')';
context.beginPath();
path(state);
context.fill();
});
var data = englewood.getData(context);
pop.forEach(function(p) {
if (p.State && p.CENSUS2010POP) {
englewood.fill(data, c2, +p.CENSUS2010POP / 20000, {
onto: [255, 255, 255 - (+p.State)],
fillStyle: '#fff'
});
}
});
path2(topojson.object(us, us.objects.states));
c2.strokeStyle = '#0ff';
c2.stroke();
});
});
</script>