forked from jalapic/jalapic.github.io
-
Notifications
You must be signed in to change notification settings - Fork 0
/
soccerpitch.html
174 lines (131 loc) · 5.85 KB
/
soccerpitch.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
<!DOCTYPE html>
<html>
<head>
<title>A title </title>
<meta charset="utf-8" />
<script src="http://d3js.org/d3.v3.js"></script>
<h1> A d3.js soccer pitch </h1>
<style>
h1{
font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif;
font-size: 22px;
font-style: bold;
}
p{
font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif;
font-size: 16px;
}
</style>
</head>
<body>
<script type="text/javascript">
var holder = d3.select("body") // select the 'body' element
.append("svg") // append an SVG element to the body
.attr("width", 1200)
.attr("height", 600);
// draw a rectangle - pitch
holder.append("rect") // attach a rectangle
.attr("x", 0) // position the left of the rectangle
.attr("y", 0) // position the top of the rectangle
.attr("height", 500) // set the height
.attr("width", 1000) // set the width
.style("stroke-width", 5) // set the stroke width
.style("stroke", "#001400") // set the line colour
.style("fill", "#80B280"); // set the fill colour
// draw a rectangle - halves
holder.append("rect") // attach a rectangle
.attr("x", 0) // position the left of the rectangle
.attr("y", 0) // position the top of the rectangle
.attr("height", 500) // set the height
.attr("width", 500) // set the width
.style("stroke-width", 5) // set the stroke width
.style("stroke", "#001400") // set the line colour
.style("fill", "#80B280"); // set the fill colour
// draw a circle - center circle
holder.append("circle") // attach a circle
.attr("cx", 500) // position the x-centre
.attr("cy", 250) // position the y-centre
.attr("r", 50) // set the radius
.style("stroke-width", 5) // set the stroke width
.style("stroke", "#001400") // set the line colour
.style("fill", "none"); // set the fill colour
// draw a rectangle - penalty area 1
holder.append("rect") // attach a rectangle
.attr("x", 0) // position the left of the rectangle
.attr("y", 105) // position the top of the rectangle
.attr("height", 290) // set the height
.attr("width", 170) // set the width
.style("stroke-width", 5) // set the stroke width
.style("stroke", "#001400") // set the line colour
.style("fill", "#80B280"); // set the fill colour
// draw a rectangle - penalty area 2
holder.append("rect") // attach a rectangle
.attr("x", 830) // position the left of the rectangle
.attr("y", 105) // position the top of the rectangle
.attr("height", 290) // set the height
.attr("width", 170) // set the width
.style("stroke-width", 5) // set the stroke width
.style("stroke", "#001400") // set the line colour
.style("fill", "#80B280"); // set the fill colour
// draw a rectangle - six yard box 1
holder.append("rect") // attach a rectangle
.attr("x", 0) // position the left of the rectangle
.attr("y", 184) // position the top of the rectangle
.attr("height", 132) // set the height
.attr("width", 60) // set the width
.style("stroke-width", 5) // set the stroke width
.style("stroke", "#001400") // set the line colour
.style("fill", "#80B280"); // set the fill colour
// draw a rectangle - six yard box 2
holder.append("rect") // attach a rectangle
.attr("x", 940) // position the left of the rectangle
.attr("y", 184) // position the top of the rectangle
.attr("height", 132) // set the height
.attr("width", 60) // set the width
.style("stroke-width", 5) // set the stroke width
.style("stroke", "#001400") // set the line colour
.style("fill", "#80B280"); // set the fill colour
// draw a circle - penalty spot 1
holder.append("circle") // attach a circle
.attr("cx", 120) // position the x-centre
.attr("cy", 250) // position the y-centre
.attr("r", 5) // set the radius
.style("fill", "#001400"); // set the fill colour
// draw a circle - penalty spot 2
holder.append("circle") // attach a circle
.attr("cx", 880) // position the x-centre
.attr("cy", 250) // position the y-centre
.attr("r", 5) // set the radius
.style("fill", "#001400"); // set the fill colour
// draw a circle - center spot
holder.append("circle") // attach a circle
.attr("cx", 500) // position the x-centre
.attr("cy", 250) // position the y-centre
.attr("r", 5) // set the radius
.style("fill", "#001400"); // set the fill colour
// penalty box semi-circle 1
var vis = d3.select("body").append("svg")
var pi = Math.PI;
var arc = d3.svg.arc()
.innerRadius(70)
.outerRadius(75)
.startAngle(0.75) //radians
.endAngle(2.4) //just radians
var arc2 = d3.svg.arc()
.innerRadius(70)
.outerRadius(75)
.startAngle(-0.75) //radians
.endAngle(-2.4) //just radians
holder.append("path")
.attr("d", arc)
.attr("fill", "#001400")
.attr("transform", "translate(120,250)");
holder.append("path")
.attr("d", arc2)
.attr("fill", "#001400")
.attr("transform", "translate(880,250)");
</script>
<p>A simple <a href="http://d3js.org/">d3.js</a> visualization of a soccer pitch. The coordinates are based on the OPTA coordinate scale. The field length is 1000px and height is 500px. Therefore to plot to a 100x100 coordinate plot, the data points will need to be scaled as appropriate. </p>
<p> Code and data are <a href="https://github.com/jalapic/jalapic.github.io">available here </a>. Please get in touch via twitter - <a href="https://twitter.com/jalapic">@jalapic</a> </p>
</body>
</html>