-
Notifications
You must be signed in to change notification settings - Fork 0
/
worldcuponamap.html
98 lines (84 loc) · 3.04 KB
/
worldcuponamap.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
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<script src="d3.min.js"></script>
<style>
</style>
<script type="text/javascript">
function draw(geo_data) {
"use strict";
var margin = 75,
width = 1400 - margin,
height = 600 - margin;
var svg = d3.select("body")
.append("svg")
.attr("width", width + margin)
.attr("height", height + margin)
.append('g')
.attr('class', 'map');
var projection = d3.geo.mercator()
.scale(140)
.translate([width / 2, height / 1.25]);
var path = d3.geo.path().projection(projection);
var map = svg.selectAll('path')
.data(geo_data.features)
.enter()
.append('path')
.attr('d', path)
.style('fill', 'lightBlue')
.style('stroke', 'black')
.style('stroke-width', 0.25);
function plot_points (data) {
var nested = d3.nest()
.key (function (d) {
return d["date"].getUTCFullYear();
})
.rollup (function(leaves){
var total = d3.sum(leaves, function (d){
return d["attendance"];
});
var coords = leaves.map(function (d){
return projection ([+d.long, +d.lat]);
});
var center_x = d3.mean(coords, function(d){
return d[0];
});
var center_y = d3.mean(coords, function(d){
return d[1];
});
return {
"attendance" : total,
"x": center_x,
"y" : center_y
};
})
.entries(data);
svg.append("g")
.attr("class", "bubble")
.selectAll("circle")
.data(nested)
.enter()
.append("circle")
.attr("cx", function (d) {return d.values["x"];})
.attr("cy", function (d) {return d.values["y"];})
.attr("r", 5);
};
var format = d3.time.format("%d-%m-%Y (%H:%M h)");
d3.tsv("world_cup_geo.tsv", function (d) {
d["attendance"] = +d["attendance"];
d["date"] = format.parse(d["date"]);
return d;
}, plot_points);
};
</script>
</head>
<body>
<script>
/*
Use D3 to load the GeoJSON file
*/
d3.json("world_countries.json", draw);
</script>
</body>
</html>