-
Notifications
You must be signed in to change notification settings - Fork 6
/
de_bruyne_touches.html
89 lines (81 loc) · 2.28 KB
/
de_bruyne_touches.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
<!doctype html>
<html>
<head>
<title>D3 soccer</title>
<style type="text/css">
svg {
margin: 50px;
}
</style>
<link rel="stylesheet" href="./dist/d3-soccer.css" />
</head>
<body>
<div id="chart" class="d3-soccer light-theme"></div>
<script src="https://cdn.jsdelivr.net/npm/d3@7"></script>
<script type="text/javascript" src="./dist/d3-soccer.js"></script>
<script type="text/javascript">
var pitch_height = 500;
var header_height = 120;
d3.json(
"https://raw.githubusercontent.com/statsbomb/open-data/master/data/events/8650.json",
).then((data) => {
var filtData = data.filter(
(d) =>
d.hasOwnProperty("location") &&
d.hasOwnProperty("player") &&
d.type.id === 42 &&
d.player.id === 3089,
);
var hed = d3
.header()
.hed("Kevin De Bruyne")
.subhed("Ball touches")
.img("img/debruyne.png");
var pitch = d3.pitch().height(pitch_height).rotate(false);
var heatmap = d3.heatmap(pitch).interpolate(true);
var x = d3.scaleLinear().domain([0, 120]).range([0, 105]);
var y = d3.scaleLinear().domain([0, 80]).range([0, 68]);
var rectbin = d3
.rectbin()
.x((d) => x(d.location[0]))
.y((d) => y(d.location[1]))
.dx(105 / 10)
.dy(68 / 10);
var rectbinData = rectbin(filtData);
var svg = d3
.select("#chart")
.append("svg")
.attr("width", pitch.width() + 40)
.attr("height", pitch_height + header_height + 60);
svg
.append("g")
.attr("transform", `translate(20,${header_height + 20})`)
.datum(rectbinData)
.call(heatmap);
svg
.select("#above")
.append("g")
.selectAll("dot")
.data(filtData)
.enter()
.append("circle")
.attr("cx", (d) => x(d.location[0]))
.attr("cy", (d) => y(d.location[1]))
.attr("r", 0.5)
.attr("fill", "crimson")
.attr("stroke", "#white")
.attr("stroke-width", 0.1);
svg.append("g").attr("transform", "translate(30,30)").call(hed);
svg
.append("text")
.attr("x", pitch.width())
.attr("y", header_height + pitch_height + 40)
.attr("text-anchor", "end")
.style("fill", "grey")
.style("font-style", "italic")
.style("font-size", "11px")
.text("Data provided by StatsBomb");
});
</script>
</body>
</html>