-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
751 lines (668 loc) · 33.2 KB
/
index.html
File metadata and controls
751 lines (668 loc) · 33.2 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
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="author" content="Whitney King">
<title>P6: Data Visualization - Whitney King</title>
<script src="http://d3js.org/d3.v4.min.js"></script> <!--Import d3.js-->
<script src="http://dimplejs.org/dist/dimple.v2.3.0.min.js"></script> <!--Import dimple.js-->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script> <!--Import jQuery-->
<script src="http://colorbrewer2.org/export/colorbrewer.js"></script> <!--Import D3 ColorBrewer-->
<script src="https://d3js.org/d3-array.v1.min.js"></script> <!--Import D3 Array-->
<script type="text/javascript" src="js/d3-tip.js"></script> <!--Import D3 Tip - https://github.com/VACLab/d3-tip/blob/master/d3-tip.js-->
<script type="text/javascript" src="js/wk_script.js"></script> <!--Import JavaScript file-->
<link href="https://fonts.googleapis.com/css?family=Maven+Pro|Open+Sans|Open+Sans+Condensed:300|Patrick+Hand+SC|Roboto+Condensed|Roboto+Slab" rel="stylesheet">
<link rel="stylesheet" type="text/css" href="css/style.css" /> <!--Import CSS file-->
<script type="text/javascript">
// Chart setup
// D3 Chart: Draw function
var formatYear = d3.timeFormat("%Y");
function draw(data) {
"use strict";
// Sizing and Position Variables
var margin = 75,
width = 1000 - margin,
height = 600 - margin;
var radius = 3,
multiplier = 2;
var colorsConsole = {'Atari' : '#03AA77',
'Microsoft' : '#14A704',
'Nintendo' : '#92A405',
'PC' : '#A13706',
'Sega' : '#9E074D',
'Sony' : '#75089B'}
// Create list of companies
var companies = [];
for (var c in colorsConsole) {
if (c.key in companies) {
continue;
}
else {
companies.push(c);
}
};
// Add random jitter to scatterplot
var epsilon = 15,
jitter = Math.random() * (2 * epsilon) - epsilon;
// Create dictionary of data
function select_game(data) {
return data.map(function (d) {
return {
'Rank' : d.Rank,
'Name' : d.Name,
'Platform' : d.Platform,
'Year' : +d.Year,
'Genre' : d.Genre,
'Publisher' : d.Publisher,
'NA_Sales' : d.NA_Sales,
'EU_Sales' : d.EU_Sales,
'JP_Sales' : d.JP_Sales,
'Other_Sales' : d.Other_Sales,
'Global_Sales' : d.Global_Sales,
'Franchise' : d.Franchise,
'Console_Company' : d.Console_Company
}
})
};
// Save scrubbed data
var dataDict = select_game(data);
// Average and sort yearly global sales by platform
var nestCompany = d3.nest()
.key(function(d) {
return d.Console_Company;
})
.sortKeys(d3.ascending).key(function(d) {
return d.Year;
})
.sortKeys(d3.ascending).rollup(function (d) {
return d3.mean(d, function(e) {
return e.Global_Sales;
});
})
.entries(dataDict);
function update(company) {
var selected_company = nestCompany.filter(function(d) {
return +d.key === company;
});
};
d3.select('body') // Add page title
.append('h2')
.text('VGChartz: Top 5,000 Best Selling Video Games Globally');
d3.select('body') // Add description of data visualization
.append('p')
.text('This chart uses global units sales data provided by VGChartz to visualize \'the console wars\' '
+ 'by displaying video games global units sales by year. The datapoints are colored by console company, '
+ 'and mean lines are shown for each company.')
d3.select('body') // Add factoids about insights that can be expected from the data visualization
.append('ul')
.append('li')
.text('Y-Axis is shown in logarithmic scale due to the extremely wide range in values for number of units shipped')
.append('li')
.text('X-Axis only shows games from 1980 - 2016, which were years with complete data')
.append('li')
.text('Legend is displayed as buttons that toggle display of datapoints and mean for each series')
.append('li')
.text('Hovering over a single datapoint will show a tooltip with detailed information about the game')
var tip = d3.tip()
.attr('class', 'd3-tip')
.offset([-10, 0])
.html(function(d) { // Add table to tooltip with detailed information about each data point
return "<table class='tooltip'><tr><td>Game:</td><td class='tipName tipInfo'>" + d.Name + "</td></tr>" +
"<tr><td>Franchise:</td><td class='tipFranchise tipInfo'>" + d.Franchise + "</td></tr>" +
"<tr><td>Publisher:</td><td class='tipPublisher tipInfo'>" + d.Publisher + "</td></tr>" +
"<tr><td>Platform:</td><td class='tipPlatform tipInfo'>" + d.Platform + "</td></tr>" +
"<tr><td>Console Company:</td><td class='tipCompany tipInfo'>" + d.Console_Company + "</td></tr>" +
"<tr><td>Genre:</td><td class='tipGenre tipInfo'>" + d.Genre + "</td></tr>" +
"<tr><td>Year:</td><td class='tipYear tipInfo'>" + d.Year + "</td></tr></br>" +
"<tr><td>Global Sales:</td><td class='tipGlobalSales tipInfo'>" + d.Global_Sales + "</td></tr>" +
"<tr><td>NA Sales:</td><td class='tipNASales tipInfo'>" + d.NA_Sales + "</td></tr>" +
"<tr><td>EU Sales:</td><td class='tipEUSales tipInfo'>" + d.EU_Sales + "</td></tr>" +
"<tr><td>JP Sales:</td><td class='tipJPSales tipInfo'>" + d.JP_Sales + "</td></tr>" +
"<tr><td>Other Sales:</td><td class='tipOtherSales tipInfo'>" + d.Other_Sales + "</td></tr></table>";
});
var svg = d3.select('body') // Frame chart area
.append('svg')
.attr('width', width + margin + 200)
.attr('height', height + margin + 100)
.append('g')
.attr('class', 'chart');
svg.call(tip);
svg.append('text') // Add chart title
.text('Console Company (Units Shipped) by Year')
.attr('class', 'chart-title')
.attr('x', (width / 3) - 20)
.attr('y', 40);
svg.append("rect") // Add color to chart background
.attr('class', 'chart-background')
.attr("width", width - margin)
.attr("height", height - (margin - 25))
.attr('left', margin)
.attr("fill", "whitesmoke")
.attr("transform", "translate(" + margin + "," + (margin - 25) + ")");
// Create X-Axis (Time)
var time_extent = d3.extent(data, function (d) {
return d.Year;
});
var time_scale = d3.scaleTime()
.range([margin, width])
.domain(time_extent);
var time_axis = d3.axisBottom()
.scale(time_scale)
.ticks(20)
.tickFormat(function(d) {
return +d; // Convert tick labels to years
});
// Create Y-Axis (Measure)
var count_extent = d3.extent(data, function (d) {
return d.Global_Sales;
});
var count_scale = d3.scaleLog() // Create log10 y-scale
.base(Math.E)
.range([height, 50])
.domain(count_extent);
var count_axis = d3.axisLeft()
.scale(count_scale)
.ticks(10, d3.format('d'));
// Draw X-Axis
d3.select('svg')
.append('g')
.attr('class', 'xaxis')
.attr('transform', 'translate(0,' + height + ')')
.call(time_axis);
//Draw X-Axis Label
d3.select('svg')
.append("text")
.attr("x", (width / 2) + (margin / 2))
.attr("y", height + (margin / 1.5))
.attr('class', 'xlabel')
.style("text-anchor", "middle")
.text("Year");
//Draw Y-Axis
d3.select('svg')
.append('g')
.attr('class', 'yaxis')
.attr('transform', 'translate('+ margin + ',0)')
.call(count_axis);
//Draw Y-Axis Label
d3.select('svg')
.append("text")
.attr("transform", "rotate(-90)")
.attr("x", 0 - (height / 2) - (margin / 3))
.attr("y", margin / 3.5)
.attr("dy", "1em")
.attr('class', 'ylabel')
.style("text-anchor", "middle")
.text("Global Units Shipped (millions)");
/****************************************************************************/
//BASE OF MARTINI GLASS - shows average sales per platform for each given year
/****************************************************************************/
// Draw mean lines
d3.select('svg')
.selectAll('path')
.data(nestCompany, function(d, i) { return d + i; }) // Add index so path is created for each plaform
.enter()
.append('path')
.attr('class', function(d) {
return 'line company-' + d.key;
})
.attr('id', function(d) {
return 'line-company-' + d.key;
});
// Position and style mean lines for each platform
var lineFunction = d3.line()
.curve(d3.curveBasis)
.x(function(d) {
return time_scale(d.key);
})
.y(function(d) {
return count_scale(d.value);
});
d3.selectAll('.line')
.attr('d', function(d) {
return lineFunction(d.values);
})
.style('stroke', function(d) { // Fill each circle with a color depending on Platform name
for (var c in colorsConsole) {
var match = false;
if (d.key == c) {
match = true;
return colorsConsole[c];
}
if (match) { break; }
}
})
.style('opacity', .7);
/****************************************************************************/
//MOUTH OF MARTINI GLASS - individual data points with tooltip on hover
/****************************************************************************/
// Draw data points
d3.select('svg')
.selectAll('circle')
.data(data)
.enter()
.append('circle')
.attr('class', function(d) {
return 'datapoint'
+ ' company-' + d.Console_Company
+ ' rank-' + d.Rank;
})
.on('mouseover', function(d) {
if (this.style.opacity == (.15 || 1)) {
d3.select(this)
.style('opacity', 1)
.attr('r', 8);
return tip.show(d);
};
})
.on('mouseout', function(d) {
if (this.style.opacity == 0) {
}
else {
d3.select(this)
.style('opacity', .15)
.attr('r', 3);
};
return tip.hide(d);
});
// Position and style datapoints
d3.selectAll('.datapoint')
.style('stroke', 0)
.style('opacity', .15)
.attr('cx', function (d) {
return time_scale(d.Year) + d.Jitter;
})
.attr('cy', function (d) {
return count_scale(d.Global_Sales)
})
.attr('r', radius)
.attr('fill', function(d) { // Fill each circle with a color depending on Platform name
for (var color in colorsConsole) {
var match = false;
if (d.Console_Company == color) {
match = true;
return colorsConsole[color];
}
if (match) { break; }
}
});
/****************************************************************************/
//STEM OF MARTINI GLASS - animation with mouse movement to show average units shipped per platform
//each year. The average will move with the line as the user moves their mouse.
/****************************************************************************/
// Show platform sales for each mean line when hovering on chart
//Reference: https://bl.ocks.org/larsenmtl/e3b8b7c2ca4787f77d78f58d41c3da91
var mouseElement = svg.append('g')
.attr('class', 'mouse-over-effects');
mouseElement.append('path') // Create vertical line to follow the mouse
.attr('class', 'mouse-line')
.attr('height', height - margin)
.style('stroke', 'darkgrey')
.attr("transform", "translate(" + margin + "," + (margin - 25) + ")")
.style('stroke-width', '1px')
.style('opacity', '0');
var lines = document.getElementsByClassName('line');
var mousePerLine = mouseElement.selectAll('.mouse-per-line')
.data(nestCompany, function(d, i) { return d + i; })
.enter()
.append('g')
.attr('class', 'mouse-per-line');
mousePerLine.append("circle")
.attr("r", 7)
.style('stroke', function(d) { // Fill each circle with a color depending on Platform name
for (var c in colorsConsole) {
var match = false;
if (d.key == c) {
match = true;
return colorsConsole[c];
}
if (match) { break; }
}
})
.style("fill", "none")
.style("stroke-width", "3px")
.style("opacity", "0")
.attr('z-index', 9999999)
.attr("transform", "translate(" + margin + ",0)");
mousePerLine.append('text')
.attr("transform", "rotate(-45) translate(65, 57)") ;
mouseElement.append('svg:rect') // append a rect to catch mouse movements on canvas
.attr("width", width - margin)
.attr("transform", "translate(" + margin + "," + (margin - 25) + ")")
.attr("height", height - 50)
.attr('fill', 'none')
.attr('pointer-events', 'all')
.on('mouseout', function() { // on mouse out hide line, circles and text
d3.select(".mouse-line")
.style("opacity", "0");
d3.selectAll(".mouse-per-line circle")
.style("opacity", "0");
d3.selectAll(".mouse-per-line text")
.style("opacity", "0");
})
.on('mouseover', function() { // on mouse in show line, circles and text
d3.select(".mouse-line")
.style("opacity", "1");
d3.selectAll(".mouse-per-line circle")
.style("opacity", "1");
d3.selectAll(".mouse-per-line text")
.style("opacity", "1");
})
.on('mousemove', function() { // mouse moving over canvas
var mouse = d3.mouse(this);
d3.select(".mouse-line")
.attr("d", function() {
var d = "M" + mouse[0] + "," + (height - 50);
d += " " + mouse[0] + "," + 0;
return d;
});
d3.selectAll(".mouse-per-line circle") // position circle over mean line for each series
.attr('class', function (d) {
d.key + '-circle company-' + d.key
})
.style("opacity", function (d) {
var xYear = +time_scale.invert(mouse[0]) + 3;
if ((xYear >= d.values[0].key && xYear < d.values[d.values.length - 1].key)) {
if (document.getElementById('line-company-' + d.key).style.opacity == .7) {
return "1";
}
else {
return "0";
};
}
else {
return "0";
};
});
d3.selectAll(".mouse-per-line text") // position label over mean line for each series
.style("opacity", function (d) {
var xYear = +time_scale.invert(mouse[0]) + 3;
if ((xYear >= d.values[0].key && xYear < d.values[d.values.length - 1].key)) {
if (document.getElementById('line-company-' + d.key).style.opacity == .7) {
return "1";
}
else {
return "0";
};
}
else {
return "0";
};
});
d3.selectAll(".mouse-per-line") // Check for mouse position, and move circle to match x of mouse, and y of series
.attr("transform", function(d, i) {
var xYear = +time_scale.invert(mouse[0]) + 3,
bisect = d3.bisector(function(d) { return d.Year; }).right,
idx = bisect(d.values, xYear);
var beginning = 0,
end = lines[i].getTotalLength(),
target = null;
while (true){
target = Math.floor((beginning + end) / 2);
var pos = lines[i].getPointAtLength(target);
if ((target === end || target === beginning) && (pos.x - margin) !== mouse[0]) {
break;
}
if ((pos.x - margin) > mouse[0]) end = target;
else if ((pos.x - margin) < mouse[0]) beginning = target;
else break; //position found
}
var yCount = count_scale.invert(pos.y).toFixed(2);
d3.select(this).select('text')
.attr('class', d.key + '-text company-' + d.key)
.style('z-index', 9999999)
.style('position', 'absolute')
.text(d.key + ": " + yCount + "m");
return "translate(" + mouse[0] + "," + pos.y +")";
});
});
// Draw legend
var legend = svg.append("g")
.attr("class", "legend")
.attr("transform", "translate(" + (width + 50) + "," + 70 + ")")
.selectAll("g")
.data(companies)
.enter()
.append("g")
.attr('class', function(d) { // Add background for legend buttons
return 'legend-button button-' + d;
});
// Add button background to legend
legend.append('rect')
.attr('class', function(d) {
return 'button-' + d;
})
.attr("y", function(d, i) {
return i * 40;
})
.attr("x", -15)
.style('height', '30px')
.style('width', '115px')
.attr('rx', '10')
.attr('ry', '10')
.attr('fill', function(d) { // Fill each circle with a color depending on Platform name
for (var color in colorsConsole) {
var match = false;
if (d == color) {
match = true;
return colorsConsole[color];
}
if (match) { break; }
}
})
.style("stroke", function(d) { // Fill each circle with a color depending on Platform name
for (var color in colorsConsole) {
var match = false;
if (d == color) {
match = true;
return colorsConsole[color];
}
if (match) { break; }
}
})
.style('fill-opacity', .1)
.style('stroke-width', '2px')
.on('click', function(d) { // Toggle series visiblity when users selects company on legend
var companyName = 'line-company-' + d;
var switchLineOpacity;
var switchDatapointOpacity;
var buttonText;
var buttonStroke;
var buttonColor;
var circleOpacity;
// Style legend based on if button is enabled or not
if (document.getElementById(companyName).style.opacity == .7) {
switchLineOpacity = 0;
switchDatapointOpacity = 0;
buttonText = 'darkgray';
buttonStroke = 'darkgray';
buttonColor = 'whitesmoke';
circleOpacity = .5;
}
else {
switchLineOpacity = .7;
switchDatapointOpacity = .15;
buttonText = 'black';
circleOpacity = 1;
for (var color in colorsConsole) {
var match = false;
if (d == color) {
match = true;
buttonStroke = colorsConsole[color];
buttonColor = colorsConsole[color];
}
if (match) { break; }
};
};
// Change page style based on button click
d3.select('#' + companyName)
.style("opacity", switchLineOpacity);
d3.selectAll('.button-' + d)
.style('stroke', buttonStroke)
.style('fill', buttonColor);
var dataOpacity = d3.selectAll('.datapoint.company-' + d);
dataOpacity.style('opacity', switchDatapointOpacity);
d3.selectAll('.legend-circle-' + d)
.style('opacity', circleOpacity);
d3.selectAll('.button-text-' + d)
.attr('fill', buttonText);
});
// Add colored icons to legend
legend.append("circle")
.attr("cy", function(d, i) {
return i * 40 + 15;
})
.attr("r", 8)
.attr('class', function(d) {
return 'legendCircle legend-circle-' + d;
})
.attr("fill", function(d) { // Fill each circle with a color depending on Platform name
for (var color in colorsConsole) {
var match = false;
if (d == color) {
match = true;
return colorsConsole[color];
}
if (match) { break; }
}
})
.on('click', function(d) { // Toggle series visiblity when users selects company on legend
var companyName = 'line-company-' + d;
var switchLineOpacity;
var switchDatapointOpacity;
var buttonText;
var buttonStroke;
var buttonColor;
var circleOpacity;
// Style legend based on if button is enabled or not
if (document.getElementById(companyName).style.opacity == .7) {
switchLineOpacity = 0;
switchDatapointOpacity = 0;
buttonText = 'darkgray';
buttonStroke = 'darkgray';
buttonColor = 'whitesmoke';
circleOpacity = .5;
}
else { // Fill each circle with a color depending on Platform name
switchLineOpacity = .7;
switchDatapointOpacity = .15;
buttonText = 'black';
circleOpacity = 1;
for (var color in colorsConsole) {
var match = false;
if (d == color) {
match = true;
buttonStroke = colorsConsole[color];
buttonColor = colorsConsole[color];
}
if (match) { break; }
};
};
d3.select('#' + companyName)
.style("opacity", switchLineOpacity);
d3.selectAll('.button-' + d)
.style('stroke', buttonStroke)
.style('fill', buttonColor);
var dataOpacity = d3.selectAll('.datapoint.company-' + d);
dataOpacity.style('opacity', switchDatapointOpacity);
d3.selectAll('.legend-circle-' + d)
.style('opacity', circleOpacity);
d3.selectAll('.button-text-' + d)
.attr('fill', buttonText);
});
// Add text labels to legend
legend.append("text")
.attr('class', function(d) {
return 'legendLabel button-text-' + d;
})
.attr("y", function(d, i) {
return i * 40 + 19;
})
.attr("x", radius * 6)
.text(function(d) {
return d;
})
.on('click', function(d) { // Toggle series visiblity when users selects company on legend
var companyName = 'line-company-' + d;
var switchLineOpacity;
var switchDatapointOpacity;
var buttonText;
var buttonStroke;
var buttonColor;
var circleOpacity;
// Style legend based on if button is enabled or not
if (document.getElementById(companyName).style.opacity == .7) {
switchLineOpacity = 0;
switchDatapointOpacity = 0;
buttonText = 'darkgray';
buttonStroke = 'darkgray';
buttonColor = 'whitesmoke';
circleOpacity = .5;
}
else { // Fill each circle with a color depending on Platform name
switchLineOpacity = .7;
switchDatapointOpacity = .15;
buttonText = 'black';
circleOpacity = 1;
for (var color in colorsConsole) {
var match = false;
if (d == color) {
match = true;
buttonStroke = colorsConsole[color];
buttonColor = colorsConsole[color];
}
if (match) { break; }
};
};
d3.select('#' + companyName)
.style("opacity", switchLineOpacity);
d3.selectAll('.button-' + d)
.style('stroke', buttonStroke)
.style('fill', buttonColor);
var dataOpacity = d3.selectAll('.datapoint.company-' + d);
dataOpacity.style('opacity', switchDatapointOpacity);
d3.selectAll('.legend-circle-' + d)
.style('opacity', circleOpacity);
d3.selectAll('.button-text-' + d)
.attr('fill', buttonText);
});
//Show one mean line at a time
var interval = 1200;
var companyIndex = 0;
var companyInterval = setInterval(function() {
update(companies[companyIndex]); //Add one line every n milliseconds
companyIndex++;
if (companyIndex >= companies.length) {
clearInterval(companyInterval);
};
}, interval);
};
</script>
</head>
<body>
<script type="text/javascript">
/*
Use D3 to load the CSV file
and pass the contents of it to the draw function
*/
d3.csv("data/vgsales_clean.csv", function (d) {
var epsilon = 15,
jitter = Math.random() * (2 * epsilon) - epsilon; // Add random jitter to scatterplot
d.Rank = +d.Rank;
d.Year = +d.Year; // Convert Year to DateTime
if (!isNaN(d.NA_Sales)) { d.NA_Sales = parseFloat(d.NA_Sales); } // Convert decimals to float values
if (!isNaN(d.EU_Sales)) { d.EU_Sales = parseFloat(d.EU_Sales); }
if (!isNaN(d.JP_Sales)) { d.JP_Sales = parseFloat(d.JP_Sales); }
if (!isNaN(d.Other_Sales)) { d.Other_Sales = parseFloat(d.Other_Sales); }
if (!isNaN(d.Global_Sales)) { d.Global_Sales = parseFloat(d.Global_Sales); }
d.Jitter = parseFloat(jitter.toFixed(4)); //Add x-axis jitter value for datapoint
if ((d.Year == '1980') && (d.Jitter < 0)) {
d.Jitter = 0;
}
if ((d.Year == '2016') && (d.Jitter > 0)) {
d.Jitter = 0;
}
return d;
}, draw);
</script>
</body>
</html>