-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
103 lines (91 loc) · 3.4 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
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<style>
svg { background-color: #eee; }
svg .municipality { fill: rgb(158,202,225); }
svg .municipality:hover { stroke: #333; }
svg .municipality.p0 { fill: rgb(247,251,255); }
svg .municipality.p1 { fill: rgb(222,235,247); }
svg .municipality.p2 { fill: rgb(198,219,239); }
svg .municipality.p3 { fill: rgb(158,202,225); }
svg .municipality.p4 { fill: rgb(107,174,214); }
svg .municipality.p5 { fill: rgb(66,146,198); }
svg .municipality.p6 { fill: rgb(33,113,181); }
svg .municipality.p7 { fill: rgb(8,81,156); }
svg .municipality.p8 { fill: rgb(8,48,107); }
svg text { font-size: 10px; }
svg title { font-size: 10px; color: }
</style>
</head>
<body>
<div id="chart"></div>
<script src="http://d3js.org/d3.v3.min.js"></script>
<script src="http://d3js.org/topojson.v1.min.js"></script>
<script src="http://d3js.org/queue.v1.min.js"></script>
<script>
var width = 960,
height = 500;
var svg = d3.select("#chart").append("svg")
.attr("width", width)
.attr("height", height);
var projection = d3.geo.mercator()
.center([128, 36])
.scale(4000)
.translate([width/2, height/2]);
var path = d3.geo.path()
.projection(projection);
var quantize = d3.scale.quantize()
.domain([0, 1000])
.range(d3.range(9).map(function(i) { return "p" + i; }));
queue()
.defer(d3.json, "municipalities-topo-simple.json")
.defer(d3.json, "nabi.json")
.await(ready);
function ready(error, data, data2) {
// console.log(arguments);
// console.log(error);
// console.log(data);
var values = d3.map();
data2.forEach(function(d) {
values.set(d.local_sub, d);
});
var features = topojson.feature(data, data.objects["municipalities-geo"]).features;
features.forEach(function(d) {
var x = values.get(d.properties.name);
if (x) {
d.properties.usage_5min_MWh = x.usage_5min_MWh;
}
// values.get(d);
// d.properties.population = popByName.get(d.properties.local_sub);
// d.properties.density = d.properties.usage_5min_MWh / path.area(d);
// d.properties.quantized = quantize(d.properties.density);
});
svg.selectAll("path")
.data(features)
.enter().append("path")
.attr("class", function(d) {
return "municipality";
})
.attr("d", path)
.append("title")
.text(function(d) {
return d.properties.name;
});
svg.selectAll("text")
.data(features.filter(function(d) { return d.properties.name.endsWith("시"); }))
.enter().append("text")
.attr("transform", function(d) {
return "translate(" + path.centroid(d) + ")";
})
.attr("dy", ".35em")
.attr("class", "region-label")
.text(function(d) {
return d.properties.usage_5min_MWh + 'MWh';
// return d.properties.name + ' ' + );
});
}
</script>
</body>
</html>