-
Notifications
You must be signed in to change notification settings - Fork 1
/
nyc_charts.js
866 lines (810 loc) · 21.4 KB
/
nyc_charts.js
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
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
function pushData(dobj, things) {
dobj.push({'geography': things[0],
'industry': things[1],
'education': things[2],
'EmpS': parseFloat(things[3]),
'HirAS': parseFloat(things[4]),
'HirNS': parseFloat(things[5]),
'EarnS': parseFloat(things[6]),
'EarnHirAS': parseFloat(things[7]),
'EarnHirNS': parseFloat(things[8]),
'yyyyqq': things[9],
'yyyyqq2': things[10]});
}
function pushOccData(dobj, things) {
dobj.push({'education': things[0],
'industry': things[1],
'occupation': things[2],
'pct': parseFloat(things[3]),
'earn': parseFloat(things[4]),
'sample': parseFloat(things[5])});
};
$(function () {
var nycdata = [];
var nycoccdata = [];
var xcat = []; /* Used by all QWI charts */
/* Vars used for education charts */
var emp_alled = [];
var emp_lths = [];
var emp_hs = [];
var emp_scaa = [];
var emp_ba = [];
var emp_na = [];
var empearn_alled = [];
var empearn_lths = [];
var empearn_hs = [];
var empearn_scaa = [];
var empearn_ba = [];
var empearn_na = [];
var hire_alled = [];
var hire_lths = [];
var hire_hs = [];
var hire_scaa = [];
var hire_ba = [];
var hire_na = [];
var earnhire_alled = [];
var earnhire_lths = [];
var earnhire_hs = [];
var earnhire_scaa = [];
var earnhire_ba = [];
var earnhire_na = [];
var subset = [];
var occsubset = [];
var sub_alled = [];
var sub_lths = [];
var sub_hs = [];
var sub_scaa = [];
var sub_ba = [];
var sub_na = [];
var str_cty = "";
var str_ind = "";
var parentmap = [{id: 'All education categories', name: 'All education categories', color: Highcharts.getOptions().colors[0]},
{id: "Bachelor's or advanced degree", name: "Bachelor's or advanced degree", color: Highcharts.getOptions().colors[4]},
{id: 'Less than high school', name: 'Less than high school', color: Highcharts.getOptions().colors[1]},
{id: 'High school or equivalent, no college', name: 'High school or equivalent, no college', color: Highcharts.getOptions().colors[2]},
{id: 'Some college or Associate degree', name: 'Some college or Associate degree', color: Highcharts.getOptions().colors[3]}];
var outmap = [];
var outotal = [];
var totals = [];
/* Helper function to create data series for charts */
function filldata (subdata,outemp, outearn, outhire, outhirearn) {
$.each(subdata, function(items, item) {
outemp.push(item.EmpS);
outearn.push(item.EarnS);
outhire.push(item.HirAS);
outhirearn.push(item.EarnHirAS);
});
};
/* Functions used for education charts */
function clearArrays() {
xcat = [];
emp_alled = [];
emp_lths = [];
emp_hs = [];
emp_scaa = [];
emp_ba = [];
emp_na = [];
empearn_alled = [];
empearn_lths = [];
empearn_hs = [];
empearn_scaa = [];
empearn_ba = [];
empearn_na = [];
hire_alled = [];
hire_lths = [];
hire_hs = [];
hire_scaa = [];
hire_ba = [];
hire_na = [];
earnhire_alled = [];
earnhire_lths = [];
earnhire_hs = [];
earnhire_scaa = [];
earnhire_ba = [];
earnhire_na = [];
subset = [];
sub_alled = [];
sub_lths = [];
sub_hs = [];
sub_scaa = [];
sub_ba = [];
sub_na = [];
occsubset = [];
outmap = [];
outotal = [];
totals = [];
}
function subsetdata() {
subset = $.grep(nycdata, function (n,i) {
return (n.geography == str_cty && n.industry == str_ind);
});
sub_alled = $.grep(subset, function (n,i){
return (n.education == 'All education categories');
});
sub_lths = $.grep(subset, function (n,i){
return (n.education == 'Less than high school');
});
sub_hs = $.grep(subset, function (n,i){
return (n.education == 'High school or equivalent, no college');
});
sub_scaa = $.grep(subset, function (n,i){
return (n.education == 'Some college or Associate degree');
});
sub_ba = $.grep(subset, function (n,i){
return (n.education == "Bachelor's or advanced degree");
});
sub_na = $.grep(subset, function (n,i){
return (n.education == "Not available");
});
occsubset = $.grep(nycoccdata, function (n,i) {
return (n.industry == str_ind);
});
$.each(occsubset, function(items, item) {
if (item.occupation == "All occupations") {
outotal.push({occupation: item.occupation, education: item.education, pct: item.pct, earnings: item.earn});
}
else {
outmap.push({name: item.occupation, parent: item.education, value: item.pct, earnings: item.earn});
}
});
outmap = parentmap.concat(outmap);
};
function createSeries() {
filldata(sub_alled, emp_alled, empearn_alled, hire_alled, earnhire_alled);
filldata(sub_lths, emp_lths, empearn_lths, hire_lths, earnhire_lths);
filldata(sub_hs, emp_hs, empearn_hs, hire_hs, earnhire_hs);
filldata(sub_scaa, emp_scaa, empearn_scaa, hire_scaa, earnhire_scaa);
filldata(sub_ba, emp_ba, empearn_ba, hire_ba, earnhire_ba);
filldata(sub_na, emp_na, empearn_na, hire_na, earnhire_na);
totals = outmap.reduce(function (acc, obj) {
if (!acc[obj.parent]) {
acc[obj.parent] = {
value: 0,
education: obj.parent
};
totals.push(acc[obj.parent]);
}
if (isNaN(acc[obj.parent].value) == false) {
acc[obj.parent].value += obj.value;
}
return acc;
}, {});
}
function drawCharts(){
$('#div_empnum').highcharts({
title: {
text: "Employment (Stable)"
},
subtitle: {
text: str_cty + ": " + str_ind
},
xAxis: {
categories: xcat
},
yAxis: {
title: {
text: ''
},
plotLines: [{
value: 0,
width: 1,
color: '#808080'
}]
},
credits: {
enabled: false
},
series: [{
name: 'All education categories',
data: emp_alled
},
{
name: 'Less than high school',
data: emp_lths
},
{
name: 'High school or equivalent, no college',
data: emp_hs
},
{
name: 'Some college or Associate degree',
data: emp_scaa
},
{
name: "Bachelor's or advanced degree",
data: emp_ba
},
{
name: 'Not available (24 years or younger)',
data: emp_na
}]
});
$('#div_empearn').highcharts({
title: {
text: "Employment earnings (Stable)"
},
subtitle: {
text: str_cty + ": " + str_ind
},
xAxis: {
categories: xcat
},
yAxis: {
title: {
text: ''
},
plotLines: [{
value: 0,
width: 1,
color: '#808080'
}]
},
credits: {
enabled: false
},
series: [{
name: 'All education categories',
data: empearn_alled
},
{
name: 'Less than high school',
data: empearn_lths
},
{
name: 'High school or equivalent, no college',
data: empearn_hs
},
{
name: 'Some college or Associate degree',
data: empearn_scaa
},
{
name: "Bachelor's or advanced degree",
data: empearn_ba
},
{
name: 'Not available (24 years or younger)',
data: empearn_na
}]
});
$('#div_hirenum').highcharts({
title: {
text: "Hires (Stable)"
},
subtitle: {
text: str_cty + ": " + str_ind
},
xAxis: {
categories: xcat
},
yAxis: {
title: {
text: ''
},
plotLines: [{
value: 0,
width: 1,
color: '#808080'
}]
},
credits: {
enabled: false
},
series: [{
name: 'All education categories',
data: hire_alled
},
{
name: 'Less than high school',
data: hire_lths
},
{
name: 'High school or equivalent, no college',
data: hire_hs
},
{
name: 'Some college or Associate degree',
data: hire_scaa
},
{
name: "Bachelor's or advanced degree",
data: hire_ba
},
{
name: 'Not available (24 years or younger)',
data: hire_na
}]
});
$('#div_hirearn').highcharts({
title: {
text: "Hires earnings (Stable)"
},
subtitle: {
text: str_cty + ": " + str_ind
},
xAxis: {
categories: xcat
},
yAxis: {
title: {
text: ''
},
plotLines: [{
value: 0,
width: 1,
color: '#808080'
}]
},
credits: {
enabled: false
},
series: [{
name: 'All education categories',
data: earnhire_alled
},
{
name: 'Less than high school',
data: earnhire_lths
},
{
name: 'High school or equivalent, no college',
data: earnhire_hs
},
{
name: 'Some college or Associate degree',
data: earnhire_scaa
},
{
name: "Bachelor's or advanced degree",
data: earnhire_ba
},
{
name: 'Not available (24 years or younger)',
data: earnhire_na
}]
});
};
function drawOccs() {
$('#div_occmap').highcharts({
series: [{
type: "treemap",
layoutAlgorithm: 'sliceAndDice',
alternateStartingDirection: true,
levels: [{
level: 1,
layoutAlgorithm: 'sliceAndDice',
dataLabels: {
enabled: true,
align: 'left',
verticalAlign: 'top',
style: {
fontSize: '15px',
fontWeight: 'bold'
}
}
}],
data: outmap
}],
credits: {
enabled: false
},
tooltip: {
formatter: function() {
if (this.point.name == "All education categories" || this.point.name == "Bachelor's or advanced degree" ||
this.point.name == "Less than high school" || this.point.name == "High school or equivalent, no college" ||
this.point.name == "Some college or Associate degree") {
var ed = this.point.name;
var tearn = $.grep(outotal, function (n,i) {
return (n.education == ed);
});
return '<b>'+ this.point.name +'</b>: ' + Highcharts.numberFormat(totals[this.point.name].value * 100, 1) + '%, <br> Annual earnings: $' +
Highcharts.numberFormat(tearn[0].earnings, 0, ".", " ") + '<br><em>Percents do not sum to 100 due to sample size exclusions.</em>';
}
else return '<b>'+ this.point.name +'</b>: '+ Highcharts.numberFormat(this.point.value * 100,1) + '%, <br> Annual earnings: $' +
Highcharts.numberFormat(this.point.earnings, 0, ".", " ");
}
},
title: {
text: 'Occupations (All New York City)'
},
subtitle: {
text: str_ind
},
});
}
/* Vars for county charts */
var emp_all = [];
var emp_bronx = [];
var emp_kings = [];
var emp_manhattan = [];
var emp_queens = [];
var emp_richmond = [];
var empearn_all = [];
var empearn_bronx = [];
var empearn_kings = [];
var empearn_manhattan = [];
var empearn_queens = [];
var empearn_richmond = [];
var hire_all = [];
var hire_bronx = [];
var hire_kings = [];
var hire_manhattan = [];
var hire_queens = [];
var hire_richmond = [];
var earnhire_all = [];
var earnhire_bronx = [];
var earnhire_kings = [];
var earnhire_manhattan = [];
var earnhire_queens = [];
var earnhire_richmond = [];
var subset_cty = [];
var sub_all = [];
var sub_bronx = [];
var sub_kings = [];
var sub_manhattan = [];
var sub_queens = [];
var sub_richmond = [];
var str_ed = "";
var str_ind2 = "";
/* Functions used for county charts */
function clearArrays2() {
xcat = [];
emp_bronx = [];
emp_kings = [];
emp_manhattan = [];
emp_queens = [];
emp_richmond = [];
emp_all = [];
empearn_bronx = [];
empearn_kings = [];
empearn_manhattan = [];
empearn_queens = [];
empearn_richmond = [];
empearn_all = [];
hire_bronx = [];
hire_kings = [];
hire_manhattan = [];
hire_queens = [];
hire_richmond = [];
hire_all = [];
earnhire_bronx = [];
earnhire_kings = [];
earnhire_manhattan = [];
earnhire_queens = [];
earnhire_richmond = [];
earnhire_all = [];
subset_cty = [];
sub_bronx = [];
sub_kings = [];
sub_manhattan = [];
sub_queens = [];
sub_richmond = [];
sub_all = [];
}
function subsetdata2() {
subset_cty = $.grep(nycdata, function (n,i) {
return (n.education == str_ed && n.industry == str_ind2);
});
sub_all = $.grep(subset_cty, function (n,i){
return (n.geography == 'All counties/boroughs');
});
sub_bronx = $.grep(subset_cty, function (n,i){
return (n.geography == 'Bronx/The Bronx');
});
sub_kings = $.grep(subset_cty, function (n,i){
return (n.geography == 'Kings/Brooklyn');
});
sub_manhattan = $.grep(subset_cty, function (n,i){
return (n.geography == 'New York/Manhattan');
});
sub_queens = $.grep(subset_cty, function (n,i){
return (n.geography == 'Queens/Queens');
});
sub_richmond = $.grep(subset_cty, function (n,i){
return (n.geography == "Richmond/State Island");
});
};
function createSeries2() {
filldata(sub_bronx, emp_bronx, empearn_bronx, hire_bronx, earnhire_bronx);
filldata(sub_kings, emp_kings, empearn_kings, hire_kings, earnhire_kings);
filldata(sub_manhattan, emp_manhattan, empearn_manhattan, hire_manhattan, earnhire_manhattan);
filldata(sub_queens, emp_queens, empearn_queens, hire_queens, earnhire_queens);
filldata(sub_richmond, emp_richmond, empearn_richmond, hire_richmond, earnhire_richmond);
filldata(sub_all, emp_all, empearn_all, hire_all, earnhire_all);
}
function drawCharts2(){
$('#div_empnum2').highcharts({
title: {
text: "Employment (Stable)"
},
subtitle: {
text: str_ed + ": " + str_ind2
},
xAxis: {
categories: xcat
},
yAxis: {
title: {
text: ''
},
plotLines: [{
value: 0,
width: 1,
color: '#808080'
}]
},
credits: {
enabled: false
},
series: [{
name: 'All counties/boroughs',
data: emp_all
},
{
name: 'Bronx/The Bronx',
data: emp_bronx
},
{
name: 'Kings/Brooklyn',
data: emp_kings
},
{
name: 'New York/Manhattan',
data: emp_manhattan
},
{
name: 'Queens/Queens',
data: emp_queens
},
{
name: "Richmond/Staten Island",
data: emp_richmond
}]
});
$('#div_empearn2').highcharts({
title: {
text: "Employment earnings (Stable)"
},
subtitle: {
text: str_ed + ": " + str_ind2
},
xAxis: {
categories: xcat
},
yAxis: {
title: {
text: ''
},
plotLines: [{
value: 0,
width: 1,
color: '#808080'
}]
},
credits: {
enabled: false
},
series: [{
name: 'All counties/boroughs',
data: empearn_all
},
{
name: 'Bronx/The Bronx',
data: empearn_bronx
},
{
name: 'Kings/Brooklyn',
data: empearn_kings
},
{
name: 'New York/Manhattan',
data: empearn_manhattan
},
{
name: 'Queens/Queens',
data: empearn_queens
},
{
name: "Richmond/Staten Island",
data: empearn_richmond
}]
});
$('#div_hirenum2').highcharts({
title: {
text: "Hires (Stable)"
},
subtitle: {
text: str_ed + ": " + str_ind2
},
xAxis: {
categories: xcat
},
yAxis: {
title: {
text: ''
},
plotLines: [{
value: 0,
width: 1,
color: '#808080'
}]
},
credits: {
enabled: false
},
series: [{
name: 'All counties/boroughs',
data: hire_all
},
{
name: 'Bronx/The Bronx',
data: hire_bronx
},
{
name: 'Kings/Brooklyn',
data: hire_kings
},
{
name: 'New York/Manhattan',
data: hire_manhattan
},
{
name: 'Queens/Queens',
data: hire_queens
},
{
name: "Richmond/Staten Island",
data: hire_richmond
}]
});
$('#div_hirearn2').highcharts({
title: {
text: "Hires earnings (Stable)"
},
subtitle: {
text: str_ed + ": " + str_ind2
},
xAxis: {
categories: xcat
},
yAxis: {
title: {
text: ''
},
plotLines: [{
value: 0,
width: 1,
color: '#808080'
}]
},
credits: {
enabled: false
},
series: [{
name: 'All counties/boroughs',
data: earnhire_all
},
{
name: 'Bronx/The Bronx',
data: earnhire_bronx
},
{
name: 'Kings/Brooklyn',
data: earnhire_kings
},
{
name: 'New York/Manhattan',
data: earnhire_manhattan
},
{
name: 'Queens/Queens',
data: earnhire_queens
},
{
name: "Richmond/Staten Island",
data: earnhire_richmond
}]
});
};
$.get('nyc_qwi.tsv', function (qwidata, status) {
$.get('nyc_acs.tsv', function (acsdata, status) {
var lines = qwidata.split('\n');
$.each(lines, function(lineNo, line) {
var items = line.split('\t');
if (lineNo > 0) {
pushData(nycdata, items);
}
});
var occlines = acsdata.split('\n');
$.each(occlines, function(lineNo, line) {
var items = line.split('\t');
if (lineNo > 0) {
pushOccData(nycoccdata, items);
}
});
$("#sel_cty").change(function() {
str_cty = "";
clearArrays();
$("#sel_cty option:selected" ).each(function() {
str_cty = $( this ).text();
});
console.log(str_cty);
subsetdata();
createSeries();
$.each(sub_alled, function(items, item) {
xcat.push(item.yyyyqq);
});
drawCharts();
});
$("#sel_ind").change(function() {
str_ind = "";
clearArrays();
$("#sel_ind option:selected" ).each(function() {
str_ind = $( this ).text();
});
console.log(str_ind);
subsetdata();
createSeries();
$.each(sub_alled, function(items, item) {
xcat.push(item.yyyyqq);
});
drawCharts();
drawOccs();
});
if (str_cty == "") {
str_cty = "All counties/boroughs";
};
if (str_ind == "") {
str_ind = "Accommodation and Food Services";
};
subsetdata();
createSeries();
$.each(sub_alled, function(items, item) {
xcat.push(item.yyyyqq);
});
drawCharts();
//console.log($("#div_empearn").height());
drawOccs();
$("#sel_ed").change(function() {
str_ed = "";
clearArrays2();
$("#sel_ed option:selected" ).each(function() {
str_ed = $( this ).text();
});
console.log(str_ed);
subsetdata2();
createSeries2();
$.each(sub_bronx, function(items, item) {
xcat.push(item.yyyyqq);
});
drawCharts2();
});
$("#sel_ind2").change(function() {
str_ind2 = "";
clearArrays2();
$("#sel_ind2 option:selected" ).each(function() {
str_ind2 = $( this ).text();
});
console.log(str_ind);
subsetdata2();
createSeries2();
$.each(sub_bronx, function(items, item) {
xcat.push(item.yyyyqq);
});
drawCharts2();
});
if (str_ed == "") {
str_ed = "All education categories";
};
if (str_ind2 == "") {
str_ind2 = "Accommodation and Food Services";
};
subsetdata2();
createSeries2();
$.each(sub_bronx, function(items, item) {
xcat.push(item.yyyyqq);
});
drawCharts2();
});
});
});