-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
executable file
·495 lines (449 loc) · 21.1 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
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
<!DOCTYPE html>
<html>
<head lang="en">
<meta charset="UTF-8">
<title>RIAA Music Sales</title>
<!-- Libraries -->
<script src="libs/d3/d3.min.js" charset="utf-8"></script>
<script src="libs/d3/d3.parcoords.js" charset="utf-8"></script>
<script src="libs/d3/queue.min.js" charset="utf-8"></script>
<script src="libs/jquery/jquery-2.1.1.min.js" charset="utf-8"></script>
<script src="libs/bootstrap/js/bootstrap.min.js" charset="utf-8"></script>
<script src="libs/dropdown-check-list/src/jquery-ui-1.11.2.min.js"
charset="utf-8"></script>
<script src="libs/dropdown-check-list/js/ui.dropdownchecklist-1.5-min.js"
charset="utf-8"></script>
<!-- Stylesheets -->
<link rel="stylesheet" type="text/css" href="css/d3.parcoords.css">
<link rel="stylesheet" type="text/css" href="css/stylesheet.css">
<link rel="stylesheet" type="text/css"
href="libs/bootstrap/css/bootstrap.min.css">
<link rel="stylesheet" type="text/css"
href="libs/dropdown-check-list/doc/smoothness-1.11.2/jquery-ui-1.11.2.custom.css">
<!-- Our JavaScript Files -->
<script src="js/dataset.js" type="text/javascript"></script>
<script src="js/metadata.js" type="text/javascript"></script>
<script src="js/milestoneVis.js" type="text/javascript"></script>
<script src="js/contextVis.js" type="text/javascript"></script>
<script src="js/focusVis.js" type="text/javascript"></script>
<script src="js/rankingVis.js" type="text/javascript"></script>
<script src="js/paraVis.js" type="text/javascript"></script>
<!-- Our Stylesheets -->
<link rel="stylesheet" type="text/css" href="css/myStyle.css">
</head>
<body>
<header>
<div class="inner">
<h1>RIAA Music Sales</h1>
<a href="https://github.com/jasonjyu/cs171-pr-riaamusicsales"
class="button"><small>View project on</small> GitHub</a>
</div>
</header>
<div class="container" style="position:absolute;width:270px">
<div class="text-center" id="milestoneVis" style="height:300px;">
<span class="chartTitle">milestone guide</span>
<br>
<p class="description">
Click the buttons to toggle through some music milestones.
</p>
<div id="milestoneControl"></div>
</div>
<hr>
<div id="controls">
<div class="text-center">
<span class="chartTitle">controls</span>
</div>
<div id="comparisonControl"></div>
<br>
<div id="formatControl"></div>
<br>
<div id="metricControl1"></div>
<div id="metricControl2"></div>
</div>
<hr>
<div id="key">
<b><i>KEY:</i></b>
<br>
<b>B</b> = billion, <b>M</b> = million, <b>k</b> = thousand
</div>
</div>
<div class="container" style="position:absolute;left:270px;width:1130px;">
<div class="row" id="overview">
<div class="col-xs-12 text-center" id="contextVis">
<span class="chartTitle">sales overview</span>
<p class="description">
Brush the chart to select a time interval to focus on,
then drag the selection.
Hover over a circle to select a music milestone,
click to deselect.
</p>
</div>
</div>
<div class="row" id="primaryView">
<div class="col-xs-7 text-center" id="focusVis1">
<span class="chartTitle">sales trends</span>
<br>
<p class="description">
Hover over a format to highlight.
Drag side slider to rescale.
Click button to toggle data view.
</p>
<div id="dataViewControl1"></div>
</div>
<div class="col-xs-5 text-center" id="rankingVis1">
<span class="chartTitle">sales rankings</span>
<br>
<p class="description">
Hover over a format bar to highlight.
</p>
</div>
</div>
<div class="row" id="secondaryView">
<div class="col-xs-7 text-center" id="focusVis2">
<span class="chartTitle">sales trends (comparison)</span>
<p class="description">
Hover over a format to highlight.
Drag side slider to rescale.
Click button to toggle data view.
</p>
<div id="dataViewControl2"></div>
</div>
<div class="col-xs-5 text-center" id="rankingVis2">
<span class="chartTitle">sales rankings (comparison)</span>
<br>
<p class="description">
Hover over a format bar to highlight.
</p>
</div>
</div>
<div class="row" id="paraView" style="position:relative;bottom:325px">
<div class="col-xs-12 text-center" style="height:40px;">
<span class="chartTitle">sales metric relationships</span>
<p class="description">
Brush or reorder the axes.
</p>
<div id="dataViewControl3"
style="position:relative;bottom:30px">
</div>
</div>
<div id="paraVis" class="col-xs-12 parcoords" style="height:280px;">
</div>
</div>
</div>
<footer>
<div style="position:absolute;top:930px;width:1400px;">
<div class="col-xs-12">
<hr>
<ul>
<li>Subscription price is average monthly fee for
subscription services.</li>
<li>Subscription volume is annual average number of
subscribers for subscription services.</li>
<li>Subscription includes streaming, tethered, and other
paid subscription services not operating under
statutory licenses.</li>
<li>Kiosk includes Singles and Albums</li>
<li>SoundExchange Distributions are estimated payments
in dollars to performers and copyright holders for
digital radio services under statutory licenses</li>
<li>On-Demand Streaming includes ad-supported audio and
music video services not operating under statutory
licenses</li>
<li>Synchronization Royalties include fees and royalties
from synchronization of sound recordings with other
media</li>
<li>Inflation adjustments based on US Bureau of Labor
Statistics annual CPI</li>
</ul>
<h3>About</h3>
<p>Team Members: Jason Yu, Kyle Franseen, Shadi Fadaee</p>
<p>
Screencast Overview Demo
<a href="https://www.youtube.com/watch?v=F2w1wCutaM4">
Video Link
</a>
</p>
<p>
Harvard University 2015 course website:
<a href="http://www.cs171.org/2015/index.html">
CS 171 - Visualization
</a>
</p>
<i>Data Sources:</i>
<ul>
<li>Recording Industry Association of America (RIAA):
<a href="https://riaa.com/keystatistics.php?content_selector=research-shipment-database-overview">
Shipment Database
</a>
</li>
<li>Pearson Education:
<a href="http://www.infoplease.com/ipea/A0151192.html">
Music Timeline
</a>
</li>
<li>Wikipedia:
<a href="http://en.wikipedia.org/wiki/Spotify">
Spotify
</a>
</li>
</ul>
<br>
<p>
This page was generated by
<a href="https://pages.github.com">GitHub Pages</a>
using the Architect theme by
<a href="https://twitter.com/jasonlong">Jason Long</a>.
</p>
</div>
</div>
</footer>
<script>
// this function is called after the HTML document is fully loaded
$(function() {
// keeps global knowledge of the data types in the dataset
var dataset;
// keeps metadata about the dataset
var metadata;
// keeps parallel data
var pardata;
var bindControlsComparison = function(controlElement,
controlTitle, shownElements, hiddenElements) {
controlElement.append("label")
.attr("class", "control")
.text(controlTitle + " ")
.append("input").attr({
type: "checkbox",
name: "comparison",
value: "enabled"
}).on("click", function() {
shownElements.transition().duration(500)
.style("opacity", this.checked ? 1 : 0)
.style("z-index", this.checked ? 1 : -1);
hiddenElements.transition().duration(500)
.style("opacity", this.checked ? 0 : 1)
.style("z-index", this.checked ? -1 : 1);
});
// set default display properties
shownElements.style("opacity", 0);
hiddenElements.style("opacity", 1);
};
var bindControlsFormat = function(controlElement, controlTitle,
defaultSelections, eventHandler, eventName) {
var form = controlElement
.classed("control", true)
.text(controlTitle);
form.append("br");
var dropdown = form.append("select")
.attr("class", "option")
.attr("name", "format")
.attr("multiple", "")
.style("height", "350px")
.style("width", getInnerWidth(controlElement) + "px" )
.on("change", function() {
$(eventHandler).trigger(eventName, [$(this).val()]);
});
// generate an array of unique formats nested by medium type
var media = d3.nest().key(function(d) {
return d.medium;
}).rollup(function(leaves) {
return Object.keys(d3.nest().key(function(e) {
return e.format;
}).map(leaves));
}).map(dataset.dollars.data);
// create a dropdown menu option for each format
dropdown.append("option")
.attr("value", "")
.attr("selected",
defaultSelections.indexOf("[ALL SELECTED]") < 0 ?
null : "")
.text("[ALL SELECTED]");
for (var medium in media) {
var optgroup = dropdown.append("optgroup")
.attr("label", medium);
media[medium].forEach(function(format) {
optgroup.append("option")
.attr("value", format)
.attr("selected", defaultSelections.indexOf(format) < 0
? null : "")
.style("color", metadata.colorMap[format])
// add text outline
.style("text-shadow", "-1px -1px black,"
+ "1px -1px black, -1px 1px black, 1px 1px black")
.text(format);
});
};
// transform dropdown menu into a dropdown checklist
$(dropdown).dropdownchecklist({
emptyText: "[NONE SELECTED]",
firstItemChecksAll: true,
icon: {
placement: 'right',
toClose: 'ui-icon-triangle-1-n',
toOpen: 'ui-icon-triangle-1-s'
},
maxDropHeight: 375,
width: getInnerWidth(controlElement),
onItemClick: function(checkbox, selector) {
var value = checkbox.val();
var selections = $(selector).val() ?
$(selector).val(): [];
var index = selections.indexOf(value);
// if value is not in current selections,
// then it was checked, otherwise it was unchecked
if (index < 0) {
if (value) {
// add checked value to current selections
selections.push(value);
}
else {
// clear current selections if value is empty
selections.length = 0;
}
}
else {
// remove unchecked value from current selections
selections.splice(index, 1);
}
$(eventHandler).trigger(eventName, [selections]);
}
});
// trigger default format selections
$(eventHandler).trigger(eventName, [defaultSelections]);
};
var bindControlsDataView = function(controlElement, controlText,
eventHandler, eventName) {
controlElement.append("button")
.attr("class", "btn-primary toggle")
.text(controlText + " ")
.on("click", function() {
$(eventHandler).trigger(eventName);
})
.append("span")
.attr("class", "glyphicon glyphicon-refresh");
};
var bindControlsMetric = function(controlElement, controlTitle,
defaultCheckedIndex, eventHandler, eventName) {
var form = controlElement
.classed("control", true)
.text(controlTitle);
form.append("br");
var dropdown = form.append("select")
.attr("class", "option")
.attr("name", "metric")
.on("change", function() {
$(eventHandler).trigger(eventName, dataset[this.value]);
});
// create a dropdown menu option for each metric
Object.keys(dataset).forEach(function(metric, i) {
dropdown.append("option")
.attr("value", metric)
.attr("selected", i === defaultCheckedIndex ? "" : null)
.text(dataset[metric].name);
});
// transform dropdown menu into a dropdown radio list
$(dropdown).dropdownchecklist({
icon: {
placement: 'right',
toClose: 'ui-icon-triangle-1-n',
toOpen: 'ui-icon-triangle-1-s'
},
width: getInnerWidth(controlElement),
onItemClick: function(checkbox) {
// if checkbox is checked, then fire event,
// otherwise keep checkbox checked
if (checkbox.prop("checked")) {
$(eventHandler).trigger(eventName,
dataset[checkbox.val()]);
}
else {
checkbox.prop("checked", true);
}
}
});
};
var bindControlsMilestone = function(controlElement,
controlHtmlText, controlFunction) {
controlElement.append("button")
.attr("class", "btn-primary")
.html(controlHtmlText)
.on("click", controlFunction);
};
// call this function after data is loaded,
// reformatted and bound to the variables
var initVis = function() {
var myEventHandler = new Object();
var milestoneVis = new MilestoneVis(d3.select("#milestoneVis"),
metadata.milestones, myEventHandler, "images/");
var contextVis = new ContextVis(d3.select("#contextVis"),
dataset.units, dataset.dollars, metadata.milestones,
myEventHandler);
var focusVis1 = new FocusVis(1, d3.select("#focusVis1"),
dataset.units, metadata.colorMap, myEventHandler);
var focusVis2 = new FocusVis(2, d3.select("#focusVis2"),
dataset.dollars, metadata.colorMap, myEventHandler);
var rankingVis1 = new RankingVis(1, d3.select("#rankingVis1"),
dataset.units, metadata.colorMap, myEventHandler);
var rankingVis2 = new RankingVis(2, d3.select("#rankingVis2"),
dataset.dollars, metadata.colorMap, myEventHandler);
var paraVis = new ParaVis(d3.select("#paraVis"),
pardata,metadata.colorMap, myEventHandler);
// bind sales metric controls
bindControlsMetric(d3.select("#metricControl1"),
"Sales Metric:", 0, myEventHandler, "dataChanged1");
bindControlsMetric(d3.select("#metricControl2"),
"Sales Metric (comparison):", 1, myEventHandler,
"dataChanged2");
// bind music format control
bindControlsFormat(d3.select("#formatControl"),
"Music Format Filter:", ["CD", "Cassette", "Vinyl",
"Music Video", "Download Single", "Paid Subscriptions"],
myEventHandler, "formatsChanged");
// bind comparison mode toggle control
bindControlsComparison(d3.select("#comparisonControl"),
"Comparison Mode:", d3.selectAll("#secondaryView, " +
"#metricControl2, .comparison"), d3.select("#paraView"));
// bind milestone controls
bindControlsMilestone(d3.select("#milestoneControl"), "«",
milestoneVis.decrementMilestone(milestoneVis));
bindControlsMilestone(d3.select("#milestoneControl"), "»",
milestoneVis.incrementMilestone(milestoneVis));
// bind data view toggle controls
bindControlsDataView(d3.select("#dataViewControl1"),
"Toggle Data View", myEventHandler, "dataViewChanged1");
bindControlsDataView(d3.select("#dataViewControl2"),
"Toggle Data View", myEventHandler, "dataViewChanged2");
bindControlsDataView(d3.select("#dataViewControl3"),
"Toggle Data Aggregation", myEventHandler, "Aggregate");
};
var startHere = function() {
// load data here and call parseData() afterwards
queue()
.defer(d3.csv, "data/RIAADATA_units.csv")
.defer(d3.csv, "data/RIAADATA_value.csv")
.defer(d3.csv, "data/RIAADATA_value_inflation_adjusted.csv")
.defer(d3.csv, "data/milestones.csv")
.defer(d3.csv, "data/paradata.csv")
.await(function(error, rows1, rows2, rows3, rows4, rows5) {
// process data if no error occurs
if (!error) {
dataset = new Dataset(rows1, rows2, rows3);
metadata = new Metadata(dataset.dollars.data,
rows4);
pardata = rows5;
initVis();
}
});
};
startHere();
});
/**
* Helper function that gets the width of a DOM element
* @param {object} element
*/
var getInnerWidth = function(element) {
var style = window.getComputedStyle(element.node(), null);
return parseInt(style.getPropertyValue('width'));
};
</script>
</body>
</html>