-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFootballBasic.html
More file actions
executable file
·271 lines (222 loc) · 7.08 KB
/
Copy pathFootballBasic.html
File metadata and controls
executable file
·271 lines (222 loc) · 7.08 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
263
264
265
266
267
268
269
270
271
<!DOCTYPE html>
<html>
<head>
<title>Football Landscape</title>
<style>
body {
font: 10px sans-serif;
}
.axis path,
.axis line {
fill: none;
stroke: #000;
shape-rendering: crispEdges;
width:1px;
}
.area {
fill: steelblue;
}
.line{
fill: none;
stroke: blue;
width:2px;
}
</style>
<script src="http://d3js.org/d3.v3.min.js"></script>
<script>
function update(values, area_function, line_function, location, ySetup) {
d3.selectAll(".area")
.data([values])
.transition()
.duration(1500)
.attr("d", area_function);
d3.selectAll(".line")
.data([values])
.transition()
.duration(1500)
.attr("d", line_function);
d3.selectAll(".x-axis")
.transition()
.duration(1500)
.attr("transform", "translate(0," + location + ")");
d3.selectAll(".y-axis")
.transition()
.duration(1500)
.call(ySetup)
}
</script>
</head>
<body>
<header>
<h1>NFC East Small Multiples</h1>
<ul>
<li><a href="#redskins">Washington Redskins</a></li>
</ul>
</header>
<section id="charts">
<a id="toggle" href="#toggle">Toggle</a>
</section>
<select id="year">
<option selected="selected" value="0">2002</option>
<option value="1">2003</option>
<option value="2">2004</option>
<option value="3">2005</option>
<option value="4">2006</option>
<option value="5">2007</option>
<option value="6">2008</option>
<option value="7">2009</option>
<option value="8">2010</option>
<option value="9">2011</option>
</select>
<section id="explination">
<p>
Using Small Multiples to survey the landscape of the NFL over the last 10 years.
</p>
</section>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
<script>window.jQuery || document.write('<script src="js/vendor/jquery-1.8.3.min.js"><\/script>')</script>
<script src="js/plugins.js"></script>
<script src="js/main.js"></script>
<script>
"use strict";
var d = [
[1,1,1,2,2,2,3,4,4,4,5,5,5,5,6,7],
[1,2,2,3,3,3,3,3,4,4,4,4,5,5,5,5],
[1,1,1,1,1,2,2,3,3,3,3,4,4,5,5,6],
[1,2,3,3,3,4,4,5,5,5,5,6,7,8,9,10],
[0,0,1,2,2,2,2,3,3,3,4,4,4,5,5,5],
[1,2,2,3,3,4,4,5,5,5,5,5,6,7,8,9],
[0,1,2,3,4,4,5,6,6,6,7,7,7,7,8,8],
[0,1,1,2,2,2,2,2,3,3,3,3,4,4,4,4],
[1,1,1,2,3,3,4,4,4,5,5,5,5,5,6,6],
[1,2,2,3,3,3,3,3,3,3,4,4,4,5,5,5]
];
var d_over = [];
var tmp = [];
//d.forEach(GamesOver500);
for(var i=0; i < d.length; i++){
d[i].forEach(GamesOver500)
d_over.push(tmp);
tmp = []
}
function GamesOver500(element, index, array) {
tmp.push(element - (index+1)/2);
}
var margin = 25,
width = 500,
height = 300;
var value =0;
var x_extent = [1,16];
var x_scale = d3.scale.linear()
.range([margin, width-margin])
.domain(x_extent);
var y_extent = [0, 16],
y_over_extent = [-16,16];
var y_scale = d3.scale.linear()
.range([height-margin, margin])
.domain(y_extent);
var y_over_scale = d3.scale.linear()
.range([height-margin, margin])
.domain(y_over_extent);
var area = d3.svg.area()
.interpolate('cardinal')
.x(function(d,i) {
return x_scale(i+1); })
.y0(height)
.y1(function(d) {
return y_scale(d); });
var area_over = d3.svg.area()
.interpolate('cardinal')
.x(function(d,i) {
return x_scale(i+1); })
.y0(function(d) {
return (d >= 0) ? height/2 : y_over_scale(d); })
.y1(function(d) {
return (d <= 0) ? height/2 : y_over_scale(d); });
var line = d3.svg.line()
.x(function(d,i) {
return x_scale(i+1); })
.y(function(d) {
return y_scale(d); });
var line_over = d3.svg.line()
.x(function(d,i) {
return x_scale(i+1); })
.y(function(d) {
return y_over_scale(d); });
var xAxis = d3.svg.axis()
.scale(x_scale)
.orient("bottom");
var yAxis = d3.svg.axis()
.scale(y_scale)
.orient("left"),
y_over_Axis = d3.svg.axis()
.scale(y_over_scale)
.orient("left");
var svg = d3.select("#charts").append("svg")
.attr("width", width + margin + margin)
.attr("height", height + margin + margin)
.append("g")
.attr("transform", "translate(" + margin + "," + margin + ")");
svg.append("path")
.data([d_over[value]])
.attr("class", "area")
.attr("d", area_over);
// svg.append("path")
// .data([d[value]])
// .attr("class", "line")
// .attr("d", line);
// svg.append("path")
// .data([d_over[value]])
// .attr("class", "line")
// .attr("d", line_over);
// svg.append("g")
// .attr("class", "x-axis")
// .attr("transform", "translate(0," + height + ")")
// .call(xAxis);
svg.append("g")
.attr("class", "x-axis")
.attr("transform", "translate(0," + height/2 + ")")
.call(xAxis);
// svg.append("g")
// .attr("class", "y-axis")
// .attr("transform", "translate(" + margin + "," + margin + ")")
// .call(yAxis)
// .append("text")
// .attr("transform", "rotate(-90)")
// .attr("y", 6)
// .attr("dy", ".71em")
// .style("text-anchor", "end")
// .text("Wins");
svg.append("g")
.attr("class", "y-axis")
.attr("transform", "translate(" + margin + "," + margin + ")")
.call(y_over_Axis)
.append("text")
.attr("transform", "rotate(-90)")
.attr("y", 6)
.attr("dy", ".71em")
.style("text-anchor", "end")
.text("Wins");
var toggle = 1;
//d3.csv('was10.csv', draw);
//Query Stuff to be pulled into main
$(document).ready(function(){
$('#year').bind('change', function(){
value = $('#year option:selected').val();
updateLogic();
});
$('#toggle').click(function(){
toggle = (toggle == 1) ? 0 : 1;
updateLogic();
});
});
function updateLogic(){
if(toggle == 1){
update(d_over[value], area_over, line_over, height/2, y_over_Axis);
}else{
update(d[value], area, line, height, yAxis);
}
}
</script>
</body>
</html>