-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
136 lines (117 loc) · 4.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
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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
<!DOCTYPE html>
<meta charset="utf-8">
<style>
.province { fill : #ccc; stroke : #ffe; stroke-width: 2px; stroke-dasharray: 2,2; stroke-linejoin: round;}
.region-labels { fill: #aaa; font-size : 14px; font-weight : bold; }
.city-labels { font-size : 12px; }
.bombings { fill: #f00; fill-opacity: 0.15; }
.legend-text { font-size: 10px; }
.legend-line { fill: #ccc; stroke-width: 1px; stroke: #ccc; shape-rendering: crispEdges; opacity: 1; }
.legend { stroke: #ccc; stroke-dasharray: 4, 2; }
.map-title { font-size: 16px; font-weight: bold; fill: #333; }
</style>
<body>
<script src="//d3js.org/d3.v3.min.js" charset="utf-8"></script>
<script src="//d3js.org/topojson.v1.min.js"></script>
<script>
var major_cities = [{"city" : "Pyongyang", "coordinates" : [125.75, 39.033]},
{"city" : "Hamhŭng", "coordinates" : [127.535556, 39.91250]},
{"city" : "Namp'o", "coordinates" : [125.399998, 38.733304]},
{"city" : "Wŏnsan ", "coordinates" : [127.446111, 39.1475]},
{"city" : "Sinŭiju", "coordinates" : [124.4, 40.1]},
{"city" : "Tanch'ŏn", "coordinates" : [128.911, 40.458]},
{"city" : "Kaech'ŏn", "coordinates" : [125.903663052, 39.69249723]},
{"city" : "Kaesŏng", "coordinates" : [126.55444, 37.97083]},
{"city" : "Sariwŏn", "coordinates" : [125.75444, 38.50778]}];
var width = 680,
height = 780;
var svg = d3.select("body").append("svg")
.attr("width", width)
.attr("height", height);
d3.json("PRK_adm1.topojson", function(error, nk) {
if (error) return console.error(error);
console.log(nk);
var projection = d3.geo.mercator()
.center([127.5, 40.3])
.scale(5800)
.translate([width/2, height/2]);
var path = d3.geo.path()
.projection(projection);
var provinces = topojson.feature(nk, nk.objects.PRK_adm1);
svg.append("path")
.datum(provinces)
.attr("d", path);
svg.selectAll(".province")
.data(topojson.feature(nk, nk.objects.PRK_adm1).features)
.enter().append("path")
.attr("class", function(d) { return "province " + d.properties.HASC_1; })
.attr("d", path)
svg.selectAll(".region-labels")
.data(topojson.feature(nk, nk.objects.PRK_adm1).features)
.enter()
.append("text")
.attr("class", "region-labels")
.attr("dx", "-2em")
.attr("transform", function(d) { return "translate(" + path.centroid(d) + ")"; })
.text(function(d) { return d.properties.NAME_1; });
d3.csv("bombs.csv", function(error, bombs) {
if (error) return console.error(error);
console.log(bombs);
svg.selectAll(".bombings")
.data(bombs)
.enter()
.append("circle")
.attr("class", "bombings")
.attr("cy", function (d) { return projection([parseFloat(d.TGT_LONGITUDE_WGS84), parseFloat(d.TGT_LATITUDE_WGS84)])[1]; })
.attr("cx", function (d) { return projection([parseFloat(d.TGT_LONGITUDE_WGS84), parseFloat(d.TGT_LATITUDE_WGS84)])[0]; })
.attr("r", function (d) { return 1 + Math.pow((d.CALCULATED_BOMBLOAD_LBS / 2000), .6); });
});
svg.selectAll(".legend")
.data([2000, 50000, 400000])
.enter()
.append("circle")
.attr("class", "bombings legend")
.attr("cx", 520)
.attr("cy", function (d) { return 500 - (1 + Math.pow((d / 2000), .6)); })
.attr("r", function (d) { return 1 + Math.pow((d / 2000), .6); });
svg.selectAll(".legend-line")
.data([2000, 50000, 400000])
.enter()
.append("line")
.attr("class", "legend-line")
.attr("x1", 520)
.attr("x2", 580)
.attr("y1", function (d) { return 500 - (1 + Math.pow((d / 2000), .6)) * 2; })
.attr("y2", function (d) { return 500 - (1 + Math.pow((d / 2000), .6)) * 2; });
svg.selectAll(".legend-text")
.data([2000, 50000, 400000])
.enter()
.append("text")
.attr("class", "legend-text")
.attr("x", 590)
.attr("y", function (d) { return 500 - (1 + Math.pow((d / 2000), .6)) * 2; })
.text(function (d) { var textbit = d === 2000 ? " ton" : " tons"; return (d / 2000).toString() + textbit; });
svg.append("text")
.attr("class", "map-title")
.attr("x", 40)
.attr("y", 80)
.text("U.S. Air Force Bombings on North Korea (1951-1952)");
svg.selectAll("cities")
.data(major_cities)
.enter()
.append("circle")
.attr("cy", function (d) { return projection(d.coordinates)[1]; })
.attr("cx", function (d) { return projection(d.coordinates)[0]; })
.attr("r", 3)
.style("fill", "black");
svg.selectAll(".city-labels")
.data(major_cities)
.enter()
.append("text")
.attr("transform", function(d) { return "translate(" + projection(d.coordinates) + ")"; })
.attr("class", "city-labels")
.attr("dy", "-1em")
.text(function (d) { return d.city; })
.style("text-anchor", "middle");
});
</script>