-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.html
executable file
·286 lines (208 loc) · 8.54 KB
/
index.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
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
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
<!DOCTYPE html> <!--[if lt IE 7 ]> <html lang="en" class="ie ie6"> <![endif]--> <!--[if IE 7 ]> <html lang="en" class="ie ie7"> <![endif]--> <!--[if IE 8 ]> <html lang="en" class="ie ie8"> <![endif]--> <!--[if IE 9 ]> <html lang="en" class="ie ie9"> <![endif]--> <!--[if (gt IE 9)|!(IE)]><!--> <html lang="en"> <!--<![endif]--> <head>
<title>Baseball Data visualizatrion by Daigo Fujiwara</title>
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="viewport" content="width=device-width, initial-scale=1, minimum-scale=1, maximum-scale=1">
<link href="//cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/2.3.2/css/bootstrap.min.css" rel="stylesheet" media="screen">
<link href="//cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/2.3.2/css/bootstrap-responsive.min.css" rel="stylesheet" media="screen">
<style>
/* full width graphic */
.section-nav {display: none;}
div.article {width: 100%;margin: 0;}
.aside {display: none;}
.interactive-body {float: left; width: 100%;}
#gfx-loading {font-family:"BentonSans", BentonSans, sans-serif; text-align:center; width: 100%; height: 100px; }
#gfx-loading p {margin:10px; font-weight:bold; color:#999;}
#gfx-loading img {margin:20px auto;}
#charts { overflow:hidden; margin-bottom:100px;}
.year {width:200px; height:170px; float:left; margin: 0 3px 10px 0; background:#ffffff; border:#fff 1px solid;}
.hover {background:#e5e5e5; border:#fba500 1px solid;}
#gfx-wrap { position:relative; font-family:"BentonSans", BentonSans, sans-serif;}
#gfx-wrap br, #gfx-loading br {display:block;}
#gfx-wrap h1 {font-size: 130%;margin: 1em 0 .5em;}
#gfx-tooltip { padding: 5px; width: auto; min-width:78px; max-width:220px; background-color:#fff; border: 2px #ccc solid; position: absolute; top: 50px; z-index:1000; font-size:14px; text-align:left; -webkit-border-radius: 3px; -moz-border-radius: 3px; border-radius: 3px;}
#gfx-tooltip .tip, #gfx-tooltip .tip-inner { position: absolute; width:0; height:0; border-top-width: 0; background: none; }
#gfx-tooltip .tip { border-left: 5px solid transparent; border-right: 5px solid transparent; border-bottom: 7px solid #ccc; top: -7px; right: auto; left: 50%; margin-left: -5px; }
#gfx-tooltip .tip-inner { border-left: 4px solid transparent; border-right: 4px solid transparent; border-bottom: 7px solid #fff; bottom: auto; top: 2px; left: -4px; }
.quiet { color: gray; font-size: 80%;}
.gfx-under {position:absolute; top:0;left:0; }
.figcaption {margin:4em 0 3em; clear:both;}
.aside {clear:both;}
@media only screen and (min-width: 480px) {
/* responsive */
}
#gfx-landscape {display:none; width:240px; margin:0 auto;font-family:"BentonSans", BentonSans, sans-serif; font-size:10px;}
#gfx-landscape-turn {width:30px; height:20px;}
@media only screen and (max-device-width: 800px) and (orientation:portrait) {
#gfx-landscape {display:block;}
}
</style>
<body class="type-home">
<div class="container">
<div id="gfx-wrap">
<h1>Visualizing the win-loss records of the Boston Red Sox</h1>
<p><strong>Just how bad was The Boston Red Sox's 2012, 2014 and 2015 season?</strong> The Red Sox have had only 10 losing seasons since 1976, 3 of them is in the last 4 years. The above and below .500 for each of the last 40 years: </p>
<p class="quiet">[October 2015] Added records through 2015</p>
<div id="gfx-loading" style="height:800px">
<p> <img src="ajax-loader.gif" alt="Loading" /><br/>Loading...</p>
</div>
<div id="charts">
</div>
<div id="gfx-tooltip" style="display: none; ">
<div class="tip">
<div class="tip-inner"></div>
</div>
<h5><span id="tip-title"></span></h5>
<span id="tip-subtitle"></span>
</div>
<!-- remove this if you don't need landscape/portrait warning
<div id="gfx-landscape"><img id="gfx-landscape-turn" src="http://c.o0bg.com/rw//Boston/2011-2020/WebGraphics/Sports/BostonGlobe.com/2012/04/greenmonster/img/turn.png" width="31" height="20" alt="" align="left" /> For a better viewing experience,<br/>turn the device into landscape mode</div> -->
</div>
<div class="figcaption">
<p class="source">SOURCES: MLB; Boston Red Sox; <a href="http://www.baseball-reference.com/teams/BOS/">Baseball-References.com</a></p>
<P class="credit" style="float:right"><a href="https://twitter.com/daigofuji">Daigo Fujiwara</a> (Originally created for the Boston Globe)</P>
</div>
<!-- PUT GRAPHIC ABOVE HERE : ONLY CONTENT ABOVE HERE SHOULD GO INTO THE JPT -->
<!-- ######################################################### -->
<!-- ######################################################### -->
<!-- ######################################################### -->
<script src="//cdnjs.cloudflare.com/ajax/libs/jquery/1.10.1/jquery.min.js"></script>
<script type="text/javascript" src="sox-data.js"></script>
<script type="text/javascript">
//console.log(soxdata[0].data); //this returns array with 162 objects
$(window).load(function() {
//code
//Create renderTo contnt area inside #charts like: <div id="y2011" class="year won"></div>
var html = "";
for (var yr in soxdata) {
html = html + '<div id="'
+ soxdata[yr].name
+ '" class="year" data-title="'
+ soxdata[yr].title
+ '" data-subtitle="'
+ soxdata[yr].subtitle
+ '"></div>';
}
$("#charts").append(html);
//load scripts after jquery
//http://c.o0bg.com/rw/Boston/2011-2020/WebGraphics/Metro/BostonGlobe.com/library/js/highcharts.js
$.getScript('highcharts.js', function() {
var chart;
$(document).ready(function() {
//Setting the global default
Highcharts.setOptions({
chart: {
type: 'area',
marginRight: 2,
marginBottom: 5
},
colors: ['#173368'],
title: {
style: {
color: '#000000',
fontWeight: 'bold',
fontSize:'13px'
},
align: 'left',
floating: true,
x: 35,
y: 15
},
subtitle: {
align: 'left',
floating: true
},
xAxis: {
categories: []
},
yAxis: {
plotLines: [{
value: 0,
width: 1,
color: '#cccccc'
}],
title: {
text: '',
margin: 0
},
plotLines: [{
value: 0,
width: 1,
color: '#cccccc'
}],
min: -20,
max: 40
},
tooltip: {
borderWidth: 0,
formatter: function() {
return '<b>'+ this.point.name +'</b><br/>'+
this.point.result;
}
},
plotOptions: {
series: {
step: true,
marker: {
enabled: false
}
}
},
legend: {
enabled: false
},
credits: {
enabled: false
}
}); // end setting global default for all charts
// Render all the charts!
for (var yr in soxdata) {
var options = {
chart: {
renderTo: soxdata[yr].name,
},
title: {
text: soxdata[yr].year //soxdata[yr].title
},
subtitle: {
text: '' //soxdata[yr].subtitle
},
series: [{
name: soxdata[yr].name,
data: soxdata[yr].data
}]
};
if (soxdata[yr].won < 1 ) { //losing year
options.series[0].color = '#aa0016';
}
var chart = new Highcharts.Chart(options);
}
});
});
// showing tooltips
$(".year").hover( function () {
$("#tip-subtitle").text($(this).attr("data-subtitle"));
$("#tip-title").text($(this).attr("data-title"));
var leftposition = $(this).offset().left - $(".year").offset().left;
var thisw = $(this).width()/2;
var tipw = $("#gfx-tooltip").width()/2;
var tipx = leftposition + thisw - tipw -4; //
$("#gfx-tooltip").css("left", tipx + "px");
var tipy = $(this).offset().top - $("#charts").offset().top + $(this).height() + 90; //
$("#gfx-tooltip").css("top", tipy + "px");
$("#gfx-tooltip").fadeIn("fast");
//debug
//console.log("hover.");
//var dify = tipy-$(this).offset().top;
//var difx = tipx-$(this).offset().left;
//console.log("Tip Y is "+ tipy +" and this top is " + $(this).offset().top + ". This height?: " + $(this).height());
//console.log("Tip X is "+ tipx +" and this left is " + $(this).offset().left + ". Difference: " + difx );
$(this).addClass("hover")
}, function (){
$("#gfx-tooltip").hide();
$(this).removeClass("hover")
});
//When ready remove loading animation.
$('#gfx-loading').slideUp();
});
</script>
</body> </html>