-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.html
200 lines (186 loc) · 5.27 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
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<!--Bootstrap CSS dependencies-->
<link href="css/style.css" rel="stylesheet">
<link href="css/bootstrap.min.css" rel="stylesheet">
<link href="css/bootstrap-theme.min.css" rel="stylesheet">
<!--Bootstrap JS dependencies-->
<script src="js/bootstrap.min.js"></script>
<script src="js/jquery.min.js"></script>
<script src="js/scripts.js"></script>
<!--D3 JS dependency-->
<script src="https://cdnjs.cloudflare.com/ajax/libs/d3/3.5.5/d3.min.js"></script>
</head>
<body>
<!-- <input type="number" id="numberOfRefugees" value="1000000"> -->
<div class="container-fluid">
<div class="row">
<div class="col-md-12">
<h3 class="text-center">
Es kommen dieses Jahr
</h3>
<br />
<form class="form-horizontal" role="form">
<div class="form-group">
<div class="col-sm-12">
<input type="number" class="form-control" id="numberOfRefugees" value="1000000" style="max-width: 150px; margin: 0 auto"/>
</div>
</div>
</form>
<h3 class="text-center text-muted">
Flüchtlinge nach Deutschland
</h3>
<h3 class="text-center text-danger">
Wie werden sie verteilt?
</h3>
<center>
<div id="pieChart">
</div>
<h1>Andere</h1>
<table id="residueData"></table>
</center>
<div class="panel panel-xs">
<div class="panel-body"> <p class="text-right text-muted">Made by Anna Agafonova and Ketoma Kemanji</p> </div>
</div>
</div>
</div>
</div>
</body>
<script>
var width = 960,
height = 500,
radius = Math.min(width, height) / 2;
var color = d3.scale.linear()
.domain([1, 30])
.range(["rgb(200, 220, 250)", "rgb(71, 137, 237)"]);
var arc = d3.svg.arc()
.outerRadius(radius - 10)
.innerRadius(0);
var pie = d3.layout.pie()
.sort(null)
.value(function(entry) { return entry.percentage; });
var svg = d3.select("#pieChart").append("svg")
.attr("width", width)
.attr("height", height)
.append("g")
.attr("transform", "translate(" + width / 2 + "," + height / 2 + ")");
var data = [
{
percentage: 21.24,
region: "NW"
},
{
percentage: 15.33,
region: "BY"
},
{
percentage: 12.97,
region: "BW"
},
{
percentage: 9.36,
region: "NI"
},
{
percentage: 7.32,
region: "HE"
},
{
percentage: 5.10,
region: "SN"
},
{
percentage: 5.05,
region: "BE"
},
{
percentage: 4.83,
region: "RP"
},
{
percentage: 3.39,
region: "SH"
},
{
percentage: 3.08,
region: "BB"
},
{
percentage: 2.86,
region: "ST"
},
{
percentage: 2.75,
region: "TH"
},
{
percentage: 2.53,
region: "HH"
},
{
percentage: 2.04,
region: "MV"
},
{
percentage: 1.22,
region: "SL"
},
{
percentage: 0.94,
region: "HB"
}
]
var reducedData = [].concat(data);
reducedData = reducedData.filter(function(entry){
return entry.percentage > 3.5
});
var residueData = [].concat(data);
residueData = residueData.filter(function(entry){
return entry.percentage <= 3.5
});
var percentSum = 0;
reducedData.forEach(function(entry) {
percentSum += entry.percentage;
});
reducedData.push({
percentage: 100 - percentSum,
region: "Andere"
});
var g = svg.selectAll(".arc")
.data(pie(reducedData))
.enter().append("g")
.attr("class", "arc");
g.append("path")
.attr("d", arc)
.style("fill", function(entry) { return color(entry.data.percentage); });
var getNumberOfRefugees = function(entry) {
var totalNumberOfRefugees = document.getElementById('numberOfRefugees').value;
var numberOfRefugees = totalNumberOfRefugees * (entry.percentage / 100);
return Math.round(numberOfRefugees); }
var getTextValue = function(entry) {
return entry.data.region + " - " + getNumberOfRefugees(entry.data);
}
var tableElement = document.getElementById("residueData");
var setTableContent = function(){
var tableContent = '';
residueData.forEach(function(entry) {
tableContent += "<tr><td>"+entry.region+"</td><td>"+getNumberOfRefugees(entry)+"</td></tr>";
});
return tableContent;
}
var textElement = g.append("text")
.attr("transform", function(entry) { return "translate(" + arc.centroid(entry) + ")"; })
.attr("dy", ".35em")
.style("text-anchor", "middle")
.text(getTextValue);
var updateData = function() {
textElement.text(getTextValue);
tableElement.innerHTML = setTableContent();
}
document.getElementById('numberOfRefugees').addEventListener('keyup', function(){ updateData(); } );
document.getElementById('numberOfRefugees').addEventListener('onchange', function(){ updateData(); } );
tableElement.innerHTML = setTableContent();
</script>
</html>