-
Notifications
You must be signed in to change notification settings - Fork 3
/
london-borough-population-now.html
93 lines (81 loc) · 2.55 KB
/
london-borough-population-now.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
<!DOCTYPE html>
<html>
<head>
<style>
body{
font-family: sans-serif;
}
p{
max-width:600px;
}
.subtitle{
font-style:italic;
color:#666;
}
.borough-label{
fill: #111;
}
.ls-background{
fill:#DDD;
}
</style>
<script src="https://d3js.org/d3.v5.min.js"></script>
<!-- <script src="../dist/index.js"></script> -->
<script src="https://unpkg.com/@aftertheflood/londonsquared@0.2.1/dist/index.js"></script>
</head>
<body>
<h1>London population by borough</h1>
<p class="subtitle">GLA Population Estimate 2015 (thousands)</p>
<p>This example illustrates how you might use the After the Flood <a href="https://github.com/aftertheflood/londonsquared">London Squared</a> module for D3 to visualise a single variable accross all London boroughs.</p>
<div class="vizualisation-container"></div>
</body>
<script>
window.onload = ()=>{
const width = 600;
const height = 525;
const svg = d3.select('.vizualisation-container')
.append('svg')
.attr('width', width)
.attr('height', height);
d3.csv('data/london-borough-profiles.csv')
.then((data)=>{
const LS = atf.londonSquared({gridGapProportion:0.05})
.data(data, d=>d.Code) //the second argument is an accessor for the local authority code associated with the data row. by default this is d=>d.code
.width(width)
.height(height);
svg.call(LS); // draw the cartogram shapes
const circleScale = d3.scalePow()
.domain([0, d3.max(data, d => Number(d['GLA Population Estimate 2015']))])
.range([0, LS.blockSize()/2])
console.log(circleScale.domain(), circleScale.range());
LS.masked()
.call(function(parent){
parent.append('circle')
.attr('r', d => {
console.log(d);
return circleScale(d.data['GLA Population Estimate 2015'])
})
.attr('cx', LS.centroid()[0])
.attr('cy', LS.centroid()[1])
.attr('fill', '#f00');
});
LS.foreground()
.call(function(parent){
parent.append('text')
.attr('class', 'borough-label')
.attr('x', 5)
.attr('y', 15)
.text(d => d.LSAbbreviation);
parent.append('text')
.attr('class', 'borough-label')
.attr('x', 5)
.attr('y', LS.blockSize()-5)
.text(d => `${d.data['GLA Population Estimate 2015']/1000}k`);
})
})
.catch(err=>{
console.log(err);
})
}
</script>
</html>