Repository navigation
Expand file tree
/
Copy pathindex.html
More file actions
262 lines (223 loc) · 6.55 KB
/
Copy pathindex.html
File metadata and controls
262 lines (223 loc) · 6.55 KB
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
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
<!DOCTYPE html>
<meta charset="utf-8">
<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Open+Sans|Roboto"/>
<style>
html, body
{
padding: 10;
margin: 10;
height: 100%;
font-family: 'Open Sans', sans-serif;
color: #212121;
}
.lsoa {
fill: #ccc;
stroke: #fff;
}
.centroid{
fill: #ccc;
stroke: #777;
stroke-width: .5px;
}
.mapTitle{
font-size: 20px;
}
.subtitle{
font-size: 15px;
}
.source{
font-size: 10px;
}
.label{
font-size: 13px;
}
#histograms{
float: left;
width: 46%;
padding-top: 50px;
}
#map{
float: left;
width: 550px
}
#histograms::after{
display: block;
clear: both;
}
</style>
<body>
<h2>Index of Multiple Deprivation (IMD) 2015 </h2>
<p>The Index of Multiple Deprivation provides a summary measure of relative deprivation at Lower Super Output Area (LSOA) using a total of 37 indicators. The IMD include seven different domains of deprivation providing a rich insight of relative deprivation in small areas.</p>
<p>There are 138 LSOA within Trafford with a population of around 1500, move the mouse over the charts to explore the distribution of LSOAs according to the decile they are classified. </p>
<div id="map"></div>
<div id="histograms"></div>
<script src="https://d3js.org/d3.v4.min.js"></script>
<script>
var width = 960,
height = 600;
var colors=['#8b0000','#ac4a2f','#c97d5d','#e1b08f','#f6e4c4','#e9e1d8','#bca7c6','#8e6fb3','#5b3a9f','#00008b']
var imdDomains={Index:"Index of Multiple Deprivation (IMD)", Income:"Income deprivation", Employment:"Employment deprivation", Health:"Health deprivation and disability", Education:"Education, skills and training deprivation", Barriers:"Barriers to housing and services", Living:"Living environment deprivation", Crime:"Crime"};
var chosenProjection = d3.geoMercator()
.center([-2.35533605967,53.4190090526])
.scale(width*140)
.translate([300, 300])
var path = d3.geoPath()
.projection(chosenProjection);
var map = d3.select("#map").append("svg")
.attr("width", width/1.7)
.attr("height", height)
.attr("id", "map")
map.append("text")
.attr("class", "mapTitle")
.attr("y", "30")
.attr("x", "5")
.text("")
//load imd data
d3.csv("IMD_trafford.csv",function(imd){
//load geojson
d3.json("https://www.trafforddatalab.io/boundaries/trafford/trafford_lsoa.geojson", function(error, geoData) {
//render file
map.append("path")
.attr("class", "lsoa")
.attr("d", path(geoData));
map.append("text")
.attr("class", "source")
.attr("y", "580")
.attr("x", "5")
.text("Source: Index of Multiple Deprivation, ONS")
var centroids = geoData.features.map(function (feature){
var data={};
data.centroid=path.centroid(feature);
data.area_code=feature.properties.lsoa11cd;
for (var i = 0; i < imd.length;i++){
if (imd[i].lsoa11cd==data.area_code){
var classString="";
for(var key in imd[i]){
if(imd[i].hasOwnProperty(key)){
classString+=" " +key+imd[i][key];
}
}
data.classes=classString;
data.imd=imd[i];
break;
}
}
return data
})
//add centroids
map.selectAll(".centroid").data(centroids)
.enter().append("circle")
.attr("r", 5)
.attr("cx", function (d){ return d.centroid[0]; })
.attr("cy", function (d){ return d.centroid[1]; })
.attr("class", function (d){ return "centroid"+d.classes; })
});
})
//load fequency data
d3.csv("imd_freq.csv",function(freq){
var imdf=[];
for (var i=0;i<8;i++){
var imdd=[];
var domain={};
for (var j=1;j<11;j++){
imdd.push({name:freq["columns"][j],value:freq[i][j]})
}
imdf.push(imdd);
}
var margin = {
top: 15,
right: 25,
bottom: 15,
left: 25
};
var hx = d3.scaleLinear()
.range([0, width/12])
.domain([0, d3.max(imdf[4], function (d) {
return +d.value;
})]);
var hy = d3.scaleBand()
.rangeRound([height/3, 0])
.padding(0.1)
.domain(imdf[0].map(function (d) {
return d.name;
}));
var yAxis = d3.axisLeft(hy)
.tickSize(0)
//loop to create histograms
for (var i=0;i<imdf.length;i++){
var histo = d3.select("#histograms").append("svg")
.attr("width", width/12 + margin.left + margin.right)
.attr("height", height/3 + margin.top + margin.bottom)
.attr("id", freq[i].index_domain)
.on ("mouseover", colorlsoas)
.on ("mouseout", greylsoas)
.append("g")
.attr("transform", "translate(" + margin.left + "," + margin.top + ")")
var gy = histo.append("g")
.attr("class", "y axis")
.call(yAxis)
var bars = histo.selectAll(".bar")
.data(imdf[i])
.enter()
.append("g")
//append rects
bars.append("rect")
.attr("class", "bar")
.attr("id", function (d) {
return freq[i].index_domain+d.name})
.attr("y", function (d) {
return hy(d.name);
})
.attr("height", hy.bandwidth())
.attr("x", 0)
.attr("width", function (d) {
return hx(d.value);
})
.attr("fill",function (d) {return colors[d.name-1]})
.on ("mouseover", showlsoas)
.on ("mouseout", hidelsoas)
//add a value label to the right of each bar
bars.append("text")
.attr("class", "label")
.attr("y", function (d) {
return hy(d.name) + hy.bandwidth() / 2 + 4;
})
//x position is 3 pixels to the right of the bar
.attr("x", function (d) {
return hx(d.value) + 3;
})
.text(function (d) {
return d.value;
});
var subtitle = histo.append("g")
.append("text")
.attr("class", "subtitle")
.attr("y", "0")
.style("text-anchor","start")
.text(freq[i].index_domain)
}
})
function showlsoas(d,i){
var key = this.id;
map.selectAll("."+key)
.style("stroke", "yellow")
.style("stroke-width", "3px");
}
function hidelsoas(d,i){
var key = this.id;
map.selectAll("."+key)
.style("stroke", "#ccc")
.style("stroke-width", "0.5px");
}
function colorlsoas(d,i){
var key = this.id;
map.selectAll(".centroid")
.style("fill", function (d) {return colors[d.imd[key]-1]});
map.selectAll(".mapTitle")
.text(imdDomains[key])
}
function greylsoas(d,i){
var key = this.id;
}
</script>
</body>