-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
652 lines (459 loc) · 17.3 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
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
<html>
<head>
<title>The Airport Survey</title>
<meta property="og:locale" content="en_US" />
<meta property="og:url" content="http://cbcb.umd.edu/~lmendelo/airport/"/>
<meta property="og:title" content="Washington Post Airport Survey DataViz"/>
<meta property="og:description"
content="Visualization of the Washington Post's airport survey results. Check out all of the crazy responses!" />
<meta property="og:image" content="http://cbcb.umd.edu/~lmendelo/airport/assets/website_preview.png"/>
<meta property="og:type" content="article"/>
<!-- <meta property="article:author" content="[lee.mendelowitz,joseph.n.paulson]"/> -->
<meta name="twitter:card" content="summary"/>
<meta name="twitter:site" content="@lmendy7"/>
<meta name="twitter:title" content="Washington Post Airport Survey DataViz"/>
<meta name="twitter:image" content="http://cbcb.umd.edu/~lmendelo/airport/assets/website_preview.png">
<meta name="twitter:url" content="http://cbcb.umd.edu/~lmendelo/airport/"/>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/css/bootstrap.min.css">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/css/bootstrap-theme.min.css">
<link rel="stylesheet" href="assets/nv.d3.css">
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.3.15/angular.min.js"></script>
<!-- <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/js/bootstrap.min.js"></script> -->
<script src="assets/angular-table.min.js"></script>
<script src="assets/d3.min.js"></script>
<script src="assets/nv.d3.min.js"></script>
<script src="assets/angularjs-nvd3-directives.js"></script>
<style>
.nvtooltip {
position: absolute;
background-color: rgba(255,255,255,0.5);
padding: 2px;
border: 1px solid rgba(0,0,0,.2);
z-index: 10000;
font-family: Arial;
font-size: 13px;
text-align: left;
pointer-events: none;
white-space: nowrap;
-webkit-touch-callout: none;
-webkit-user-select: none;
-khtml-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
user-select: none;
}
</style>
<script type="text/javascript">
// ref: http://stackoverflow.com/a/1293163/2343
// This will parse a delimited string into an array of
// arrays. The default delimiter is the comma, but this
// can be overriden in the second argument.
function CSVToArray( strData, strDelimiter ){
// Check to see if the delimiter is defined. If not,
// then default to comma.
strDelimiter = (strDelimiter || ",");
// Create a regular expression to parse the CSV values.
var objPattern = new RegExp(
(
// Delimiters.
"(\\" + strDelimiter + "|\\r?\\n|\\r|^)" +
// Quoted fields.
"(?:\"([^\"]*(?:\"\"[^\"]*)*)\"|" +
// Standard fields.
"([^\"\\" + strDelimiter + "\\r\\n]*))"
),
"gi"
);
// Create an array to hold our data. Give the array
// a default empty first row.
var arrData = [[]];
// Create an array to hold our individual pattern
// matching groups.
var arrMatches = null;
// Keep looping over the regular expression matches
// until we can no longer find a match.
while (arrMatches = objPattern.exec( strData )){
// Get the delimiter that was found.
var strMatchedDelimiter = arrMatches[ 1 ];
// Check to see if the given delimiter has a length
// (is not the start of string) and if it matches
// field delimiter. If id does not, then we know
// that this delimiter is a row delimiter.
if (
strMatchedDelimiter.length &&
strMatchedDelimiter !== strDelimiter
){
// Since we have reached a new row of data,
// add an empty row to our data array.
arrData.push( [] );
}
var strMatchedValue;
// Now that we have our delimiter out of the way,
// let's check to see which kind of value we
// captured (quoted or unquoted).
if (arrMatches[ 2 ]){
// We found a quoted value. When we capture
// this value, unescape any double quotes.
strMatchedValue = arrMatches[ 2 ].replace(
new RegExp( "\"\"", "g" ),
"\""
);
} else {
// We found a non-quoted value.
strMatchedValue = arrMatches[ 3 ];
}
// Now that we have our value string, let's add
// it to the data array.
arrData[ arrData.length - 1 ].push( strMatchedValue );
}
// Return the parsed data.
return( arrData );
}
</script>
<script>
var app = angular.module('myApp', [
"angular-table", 'nvd3ChartDirectives'
]);
app.factory('DataManager', function($rootScope, $http, $q, $window, Entry) {
var data = [];
var api = {};
var get_data_deferred;
api.get_data = function() {
if (get_data_deferred) {
return get_data_deferred.promise;
}
get_data_deferred = $q.defer();
if(data && data.length > 0) {
deferred.resolve(data);
}
var url = "data/response.for.site.csv";
$http.get(url).success(function(d, status, headers, config) {
data = CSVToArray(d).map(function(e) { return new Entry(e); });
data = data.slice(1);
$rootScope.haveData = true;
get_data_deferred.resolve(data);
// console.log("got data: ", data);
}).error(function() {
console.log("Error getting data");
$window.alert("Error getting data!");
get_data_deferred = undefined;
$rootScope.have_data = false;
});
return get_data_deferred.promise;
};
return api;
});
app.factory('Entry', function() {
var Entry = function(d) {
this.answer = d[0];
this.birth_year = d[1];
this.gender = d[2];
this.party = d[3];
this.reason = d[4];
}
return Entry;
});
app.controller("RandomResponseCtrl", function($scope, DataManager, $filter, $timeout) {
$scope.full_responses = [];
$scope.curResponse = {};
$scope.curInd = 0;
DataManager.get_data().then( function(data) {
$scope.full_responses = data.filter(function(e) { return e.reason && e.reason.length && e.reason.length > 1; });
$scope.shuffleResponses();
$scope.curResponse = $scope.full_responses && $scope.full_responses[$scope.curInd];
});
$scope.shuffleResponses = function() {
function shuffle(o){ //v1.0
for(var j, x, i = o.length; i; j = Math.floor(Math.random() * i), x = o[--i], o[i] = o[j], o[j] = x);
return o;
};
$scope.full_responses = shuffle($scope.full_responses);
};
$scope.next = function() {
if(!$scope.full_responses) {
return;
}
$scope.curInd += 1;
if ($scope.curInd > $scope.full_responses.length) {
$scope.curInd = 0;
}
$scope.curResponse = $scope.full_responses && $scope.full_responses[$scope.curInd];
};
$scope.prev = function() {
if(!$scope.full_responses) {
return;
}
$scope.curInd -= 1;
if ($scope.curInd < 0) {
$scope.curInd = $scope.full_responses.length > 0 ? $scope.full_responses.length - 1 : 0;
}
$scope.curResponse = $scope.full_responses && $scope.full_responses[$scope.curInd];
};
});
app.controller("SearchCtrl", function($scope, DataManager, $filter, $timeout, $location) {
$scope.matches = [];
$scope.query = "";
var cur_timeout = undefined;
$scope.counts = [];
// Defaults:
$scope.searchReason = true;
$scope.searchAnswer = true;
// Parse the url
var urlSearch = $location.search();
if (urlSearch.hasOwnProperty('searchAnswer')) {
$scope.searchAnswer = urlSearch.searchAnswer == 1;
}
if (urlSearch.hasOwnProperty('searchReason')) {
$scope.searchReason = urlSearch.searchReason == 1;
}
if (urlSearch.hasOwnProperty('query')) {
$scope.query = urlSearch.query;
}
var updateMatches = function() {
// Restart
$timeout.cancel(cur_timeout);
cur_timeout = $timeout(function() {
// Build the search criteria
var criteria = {};
if($scope.searchAnswer) {
criteria['answer'] = $scope.query;
}
if($scope.searchReason) {
criteria['reason'] = $scope.query;
}
var re = new RegExp($scope.query, "i");
var filterFunction = function(entry, index) {
var ret = false;
ret = ret || ($scope.searchAnswer && re.test(entry.answer));
ret = ret || ($scope.searchReason && re.test(entry.reason));
return ret;
}
var mm = $filter('filter')($scope.data, filterFunction) || [];
// console.log("Have matches!", mm);
countAnswers(mm);
$scope.matches = mm;
$location.path('/').search({query: $scope.query, searchAnswer: $scope.searchAnswer ? 1 : 0, searchReason: $scope.searchReason ? 1 : 0})
}, 300);
};
var countAnswers = function(matches) {
var counts = {};
var a, i;
if(!matches) {
$scope.total = 0;
$scope.counts = [];
return;
}
for(i = 0; i < matches.length; i++) {
a = matches[i].answer;
if(counts.hasOwnProperty(a)) {
counts[a] += 1;
} else {
counts[a] = 1;
}
}
var counts_array = [];
angular.forEach(counts, function(value, key) {
counts_array.push({key: key, value: value});
});
// DEBUG
// counts_array = counts_array.slice(0, 10);
$scope.counts = counts_array;
// Loop over the counts to produce total
$scope.total = 0;
for(var i = 0; i < $scope.counts.length; i++) {
$scope.total += $scope.counts[i].value;
}
// console.log("Counts: ", $scope.counts, $scope.total);
return counts_array;
}
DataManager.get_data().then(updateMatches);
$scope.$watch("query", updateMatches);
$scope.$watch("searchReason", updateMatches);
$scope.$watch("searchAnswer", updateMatches);
$scope.tableConfig = {
itemsPerPage: 10,
fillLastPage: false,
maxPages: 5
};
$scope.xFunction = function () {
return function(d) {
return d.key;
};
};
$scope.yFunction = function() {
return function(d) {
return d.value;
};
};
$scope.toolTipContentFunction = function(){
return function(key, x, y, e, graph) {
var count = y.value;
return '<div style="padding: 2px; background-color: rgba(255, 255, 255, 0.8);">' +
'<h4>' + key + '</h4>' +
'<p>Count: ' + $filter("number")(count, 0) +
' (' + $filter('number')(count/$scope.total*100, 1) + '%) </p>' +
'</div>';
};
};
});
app.run(function($rootScope, DataManager) {
$rootScope.matches = [];
$rootScope.haveData = false;
DataManager.get_data().then(function(data) {
$rootScope.data = data;
$rootScope.haveData = true;
});
});
</script>
</head>
<body ng-app="myApp">
<div class="container">
<div class="row">
<div class="col-xs-12">
<h1>Washington Post Airport Survey</h1>
<p>
The results of the Washington Post's <a href="http://www.washingtonpost.com/express/wp/2015/03/31/national-reagan-dca-17-years-later-locals-still-cant-agree-on-the-name-of-the-airport-in-question/?wprss=rss_traffic" target="_blank"> Airport Survey</a> are out!
</p>
<p>The survey asked respondents to explain how they refer to "the airport in Northern Virginia that's not Dulles".
Respondents could choose from a list of "DCA", "National", "Reagan", "Reagan National",
or provide their own answer.
</p>
<p>
Respondents also provided their birth year, gender, party affiliation, and
a reason for why they call the airport the way they do.
<p>Have fun!</p>
<p class="text-danger">WARNING: This site contains unfiltered survery responses and contains
vulgar and potentially hateful content. Use at your own risk.</p>
</p>
<a href="https://twitter.com/share" class="twitter-share-button" data-url="goo.gl/OXR9Ly" data-text="goo.gl/OXR9Ly #DataViz by @lmendy7 @dorageh. CC @postlocal">Tweet</a>
</div>
</div>
<div ng-hide="haveData">
<div class="col-xs-12">
Loading Data...
<div class="progress">
<div class="progress-bar progress-bar-striped active"
role="progressbar" aria-valuenow="45" aria-valuemin="0" aria-valuemax="100"
style="width: 45%">
</div>
</div>
</div>
</div>
<div ng-show="haveData">
<div class="row" ng-controller="SearchCtrl">
<div class="col-xs-12">
<h2>Search</h2>
<form class="form-inline">
<div class="form-group">
<label class="sr-only" for="searchQuery">Query</label>
<input type="text" class="form-control" id="searchQuery" ng-model="query" placeholder="Search terms">
</div>
<div class="checkbox">
<label>
<input type="checkbox" ng-model="searchAnswer"> Airport Name
</label>
</div>
<div class="checkbox">
<label>
<input type="checkbox" ng-model="searchReason"> Reason
</label>
</div>
</form>
<p>Have {{ matches.length | number }} matches.</p>
</div>
<div class="col-md-4" style="max-height: 400px; overflow: auto;">
<nvd3-pie-chart
data="counts"
id="exampleId"
width="300"
height="300"
x="xFunction()"
y="yFunction()"
showLabels="true"
tooltips="true"
tooltipcontent="toolTipContentFunction()">
<svg></svg>
</nvd3-pie-chart>
</div>
<div class="col-md-8">
<at-pagination at-list="matches" at-config="tableConfig"></at-pagination>
<table at-table at-list="matches" at-paginated at-config="tableConfig" class="table table-bordered">
<thead>
</thead>
<tbody>
<tr>
<td at-implicit at-attribute="answer" at-title="AirportName"></td>
<td at-implicit at-attribute="gender" at-title="Gender"></td>
<td at-implicit at-attribute="birth_year" at-title="BirthYear"></td>
<td at-implicit at-attribute="party" at-title="Party"></td>
<td at-implicit at-attribute="reason" at-title="Reason"></td>
</tr>
</tbody>
</table>
</div>
</div>
<div ng-controller="RandomResponseCtrl">
<div class="col-xs-12">
<h2>Random Answer Generator</h2>
</div>
<div class="col-md-3">
<button class="btn btn-md btn-primary" ng-click="prev()"><span class="glyphicon glyphicon-backward"></span> Back</button>
<button class="btn btn-md btn-success" ng-click="next()">Forward <span class="glyphicon glyphicon-forward"></span></button>
</div>
<div class="col-md-9">
<table class="table table-bordered table-condensed">
<tbody>
<tr>
<th>Answer</th>
<td>{{ curResponse.answer}}</td>
</tr>
<tr>
<th>BirthYear</th>
<td>{{ curResponse.birth_year}}</td>
</tr>
<tr>
<th>Gender</th>
<td>{{ curResponse.gender}}</td>
</tr>
<tr>
<th>Party</th>
<td>{{ curResponse.party}}</td>
</tr>
<tr>
<th>Reason</th>
<td>{{ curResponse.reason}}</td>
</tr>
</tbody>
</table>
</div>
</div>
</div> <!-- have data -->
<div class="col-xs-12">
<h2>Authors</h2>
<ul>
<li>Lee M. Mendelowitz
<br><a href="mailto:[email protected]" target="_blank">[email protected]</a>
<br><a href="https://twitter.com/lmendy7" class="twitter-follow-button" data-show-count="false">Follow @lmendy7</a>
</li>
<li>Joseph Paulson
<br><a href="mailto:[email protected]" target="_blank">[email protected]</a>
<br><a href="https://twitter.com/dorageh" class="twitter-follow-button" data-show-count="false">Follow @dorageh</a>
</li>
</ul>
<h2>GitHub</h2>
<iframe src="https://ghbtns.com/github-btn.html?user=LeeMendelowitz&repo=AirportViz&type=star&count=true&size=large" frameborder="0" scrolling="0" width="160px" height="30px"></iframe>
</div>
</div>
<!-- Google Analytics -->
<script>
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','//www.google-analytics.com/analytics.js','ga');
ga('create', 'UA-61462133-1', 'auto');
ga('send', 'pageview');
</script>
<!-- Twitter -->
<script>!function(d,s,id){var js,fjs=d.getElementsByTagName(s)[0],p=/^http:/.test(d.location)?'http':'https';if(!d.getElementById(id)){js=d.createElement(s);js.id=id;js.src=p+'://platform.twitter.com/widgets.js';fjs.parentNode.insertBefore(js,fjs);}}(document, 'script', 'twitter-wjs');</script>
</body>
</html>