-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
151 lines (131 loc) · 4.3 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
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
<!DOCTYPE html>
<meta charset="utf-8">
<style>
body { background-color: #1A1A1A; }
path {
stroke-linejoin: round;
}
.land {
fill: #4C4C4C;
}
.states {
fill: none;
stroke: darkgray;
}
circle.no_l_1{ fill: #1B2876; }
circle.no_l_2{ fill: #34A939; }
circle.no_l_3{ fill: #FD5C09; }
circle.no_l_4{ fill: #268BD5; }
circle.no_l_5{ fill: #7411D9; }
circle.no_l_6{ fill: #9E3B0B; }
circle.no_l_7{ fill: #566112; }
circle.no_l_8{ fill: #DB005B; }
svg .municipality-label {
fill: white;
font-size: 12px;
font-weight: 300;
text-anchor: middle;
font-family: sans-serif;
}
</style>
<body>
<a href="https://github.com/yoon-gu/gourmet"><img style="position: absolute; top: 0; left: 0; border: 0;" src="https://camo.githubusercontent.com/c6625ac1f3ee0a12250227cf83ce904423abf351/68747470733a2f2f73332e616d617a6f6e6177732e636f6d2f6769746875622f726962626f6e732f666f726b6d655f6c6566745f677261795f3664366436642e706e67" alt="Fork me on GitHub" data-canonical-src="https://s3.amazonaws.com/github/ribbons/forkme_left_gray_6d6d6d.png"></a>
<script src="//d3js.org/d3.v3.min.js"></script>
<script src="//d3js.org/queue.v1.min.js"></script>
<script src="//d3js.org/topojson.v1.min.js"></script>
<script>
var color = d3.scale.category20();
var width = 960,
height = 550;
var centered;
var projection = d3.geo.mercator()
.center([126.9895, 37.5651])
.scale(90000)
.translate([width/2, height/2]);
var path = d3.geo.path().projection(projection);
var svg = d3.select("body").append("svg")
.attr("width", width)
.attr("height", height);
var g = svg.append("g");
svg.append("rect")
.attr("class", "background")
.attr("width", width)
.attr("height", height)
.style("fill", "none")
.on("click", clicked);
var tooltip = d3.select("body")
.append("div")
.style("position", "absolute")
.style("z-index", "10")
.style("visibility", "hidden")
.style("font-family", "sans-serif")
.style("color", "white")
.style("font-size", "11px");
queue()
.defer(d3.json, "https://gist.githubusercontent.com/yoon-gu/b051fd123385303a5c03f0e0a833516c/raw/9fff4a65830be008709112c190c3ed939d42e994/seoul_municipalities_topo.json")
.defer(d3.csv, "data.csv")
.await(ready);
function ready(error, kor, stations) {
if (error) throw error;
var features = topojson.feature(kor, kor.objects.seoul_municipalities_geo).features;
g.selectAll("path")
.data(features)
.enter().append("path")
.attr("class", "land")
.attr("d", path)
.attr("id", function(d) { return d.properties.name; })
.on("click", clicked)
.append("title");
g.append("path")
.datum(topojson.mesh(kor, kor.objects.seoul_municipalities_geo, function(a, b) { return a !== b; }))
.attr("class", "states")
.attr("d", path);
g.selectAll('text')
.data(features)
.enter().append("text")
.attr("transform", function(d) { return "translate(" + path.centroid(d) + ")"; })
.attr("dy", ".35em")
.attr("class", "municipality-label")
.text(function(d) { return d.properties.name; })
g.selectAll("circle")
.data(stations)
.enter().append("circle")
.attr("cx", function(d) { return projection([d.lon, d.lat])[0]; })
.attr("cy", function(d) { return projection([d.lon, d.lat])[1]; })
.attr("r", 2)
.attr("opacity", 0.7)
.attr("class", function(d){ return d.type; })
.attr("fill", function(d){ return color(d.type);})
.on("mouseover", function(d){
tooltip.style("visibility", "visible")
.text(d.name);
})
.on("mousemove", function(){
tooltip.style("top", (event.pageY-10)+"px").style("left",(event.pageX+10)+"px");
})
.on("mouseout", function(){
tooltip.style("visibility", "hidden");
});
}
function clicked(d) {
var x, y, k;
if (d && centered !== d) {
var centroid = path.centroid(d);
x = centroid[0];
y = centroid[1];
k = 3;
centered = d;
} else {
x = width / 2;
y = height / 2;
k = 1;
centered = null;
}
g.selectAll("path")
.classed("active", centered && function(d) { return d === centered; });
g.transition()
.duration(750)
.attr("transform", "translate(" + width / 2 + "," + height / 2 + ")scale(" + k + ")translate(" + -x + "," + -y + ")")
.style("stroke-width", 1.5 / k + "px");
}
</script>