-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex2.html
1024 lines (819 loc) · 28.5 KB
/
index2.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
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
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<html>
<script src='https://d3js.org/d3.v5.min.js'></script>
<style>
table {
border-collapse: collapse;
}
.summary td, th {
border: 1px solid #dddddd;
padding: 4px;
}
</style>
<body onload='init()'>
<table border =1><tr>
<td>
<div id="chart" align=center></div>
<div id="chart2" align=center></div>
</td>
<td width=470 valign=top>
<table>
<tr height=300 ><td>
<div id='slideshow-text' class='top' ></div>
</td></tr>
<tr><td align="center">
<button id='btn_next' onClick="lastSlide()">Prev</button>
<button id="btn_toggle_slideshow" onClick='toggleSlideshow()'>Stop Narration</button>
<button id='btn_last' onClick="nextSlide()">Next</button>
</td></tr>
<tr><td> <div id="summary" align=center width=200></div> </td></tr>
<tr><td align="center">
<div id="filters" >
<table>
<tr valign="top"><td>
School type<br>
<input type="checkbox" id="type_all" onclick="toggleGraph()">All<br>
<input type="checkbox" id="type_public" checked onclick="toggleGraph()">Public<br>
<input type="checkbox" id="type_private" onclick="toggleGraph()">Private<br>
</td><td>
Cost of<br>
<input type="checkbox" id="cost_all" checked onclick="toggleGraph()">All Costs<br>
<input type="checkbox" id="cost_tuition" onclick="toggleGraph()">Tution and Fees Only<br>
</td></tr>
</table>
</div>
</td></tr>
</table>
<div id="summary" align=center width=200></div>
</td>
</tr></table>
<script>
const SLIDESHOW = 'slideshow';
const INTERACTIVE = 'interactive'
let mode = SLIDESHOW;
let MAIN_FIELD = 'PublicAllCosts';
const WAGE_FIELD = 'MinimumWage';
function toggleSlideshow() {
let filtered_data = filterData();
const butn_toggle = document.getElementById("btn_toggle_slideshow");
const btn_next = document.getElementById("btn_next");
const btn_last = document.getElementById("btn_last");
const filters = document.getElementById("filters");
if (mode == SLIDESHOW) {
mode = INTERACTIVE;
butn_toggle.innerHTML = "Restart Narration";
btn_next.disabled = true;
btn_last.disabled = true;
target_year = SLIDES[SLIDES.length-1].year;
//target_max_y = current_max_y;
_setInterval('year_interval',animateYear, 12);
filters.style.display = "unset";
}
else {
mode = SLIDESHOW;
butn_toggle.innerHTML = "Stop Narration";
slide_index=0;
updateSlide(12);
btn_next.disabled = true;
btn_last.disabled = true;
filters.style.display = "none";
// Reset checkboxes
document.getElementById("type_all").checked = false;
document.getElementById("type_public").checked = true;
document.getElementById("type_private").checked = false;
document.getElementById("cost_all").checked = true;
document.getElementById("cost_tuition").checked = false;
toggleGraph();
}
}
const intervals = {};
function _setInterval(name, action, speed) {
//console.log("Setting interval", name);
document.getElementById("btn_toggle_slideshow").disabled = true;
document.getElementById("btn_next").disabled = true;
document.getElementById("btn_last").disabled = true;
intervals[name] = setInterval(action, speed);
}
function _clearInterval(name) {
//console.log("clearing interval", intervals[name]);
clearInterval(intervals[name]);
delete intervals[name];
if (Object.keys(intervals).length == 0) {
document.getElementById("btn_toggle_slideshow").disabled = false;
if (mode == SLIDESHOW) {
document.getElementById("btn_next").disabled = false;
document.getElementById("btn_last").disabled = false;
}
}
}
const graph_colors = {
AllAllCosts: 'Yellow',
PrivateAllCosts: 'DarkOrange',
PublicAllCosts: 'RoyalBlue',
AllTuitionAndFees: 'Khaki',
PrivateTuitionAndFees: 'LightSalmon',
PublicTuitionAndFees: 'LightBlue'
};
const display_names = {
AllAllCosts: 'Public and Privates Colleges, All Costs',
PrivateAllCosts: 'CollegePrivate , All Costs',
PublicAllCosts: 'Public College, All Costs',
AllTuitionAndFees: 'Public and Privates Colleges, Tuition and Fees',
PrivateTuitionAndFees: 'Private College, Tuition and Fees',
PublicTuitionAndFees: 'Public College, Tuition and Fees'
};
const axis_names = {
AllAllCosts: 'All Colleges',
PrivateAllCosts: 'Private College',
PublicAllCosts: 'Public College',
AllTuitionAndFees: 'All Colleges',
PrivateTuitionAndFees: 'Private College',
PublicTuitionAndFees: 'Public College',
minimum_wage: 'Minimum Wage'
}
const axis_names_2 = {
AllAllCosts: 'All Costs',
PrivateAllCosts: 'All Costs',
PublicAllCosts: 'All Costs',
AllTuitionAndFees: 'Tuition and Fees',
PrivateTuitionAndFees: 'Tuition and Fees',
PublicTuitionAndFees: 'Tuition and Fees',
minimum_wage: ''
}
school_types = {
type_all: 'All',
type_private: 'Private',
type_public: 'Public'
};
cost_types = {
cost_all: 'AllCosts',
cost_tuition: 'TuitionAndFees'
};
function toggleGraph(updateVisuals = true) {
const btn_values = {};
Object.keys({...school_types, ...cost_types}).forEach((name) => {
btn_values[name] = document.getElementById(name).checked;
});
clearVisualElements();
cost_configs = [];
data_sets = [wage_config];
Object.keys(school_types).forEach((school_type) => {
Object.keys(cost_types).forEach((cost_type) => {
if (!btn_values[school_type] || !btn_values[cost_type]) {
return;
}
let fieldname = school_types[school_type] + cost_types[cost_type];
const config = {
...cost_defaults,
type: "cost",
name: fieldname,
field: fieldname,
school_type,
cost_type,
label: (val) => {return '$' + parseInt(val)},
color: graph_colors[fieldname],
display_name: display_names[fieldname],
axis: d3.axisLeft,
//tick_format: (a) => {return '$'+ parseInt(a)},
tick_format: (a) => {return '$'+ parseFloat(a).toFixed(2)}
}
cost_configs.push(config);
data_sets.push(config);
});
});
if(updateVisuals) {
setVisualElements();
drawChart(SLIDES[slide_index].year)
}
}
/********************
*
* Slideshow stuff
*
*******************/
let slide_index = 0;
const SLIDES = [
{
year: 1969,
text: "The idea of working your way through college is part of the mythos of the American dream. How realistic was working your way through college, and is it still possible?"
+ "<p>We will look at how the minimum wage has changed with respect to the cost of a public college education, specifically at how many hours of work it would take to pay for the costs."
+ "<p>We are looking at public college costs, as public college is more affordable for a working student, and a student is likely to have a job at or near minumum wage"
},
{
year: 1969,
text: "In 1969 you could pay for all of your college expenses working just under 15 hours a week at minimum wage. This workload is manageable for a full-time student"
},
{
year: 1979,
text: "Ten years later, minimum wage had kept pace with costs and you could still pay for public college a little over 15 hours of minimum wage work per week"
},
{
year: 1984,
text: "Five years later the cost of public college had increased around by around 50% and minimum wage had increased by around only 15%."
+ " As a result the number of hours needed to pay for college increased to over 20 hours for the first time. It has not gone below that number since."
+ "<p>This amount of work is probably manageable for a full-time student, but is more challenging than it used to be"
},
{
year: 1989,
text: "In 1989, the minimum wage had not been raised in 8 years while the cost of going to public college continued to increase."
+ "It would now require almost 29 hours of minimum wage work per week to cover, almost double the number of hours from a decade before."
+ "<p>The number of hours required to pay for college is now pushing close to 4 days of full time work a week. It is getting hard to imagine balancing that with a full course load"
},
{
year: 1997,
text: "Thanks to a series of minimum wage increases, 8 years later you could still pay for a public college education with a less than 29 hours of minimum wage work per week."
+ "Working your way through college hadn't gotten easier, but it hadn't gotten worse"
},
{
year: 2006,
text: "After a 9 year stretch with no minimum wage increases, 48 hours a week of minimum wage work is now required to pay for public college."
+ '<p>This is a full workweek, plus and extra day, and it would be challenging to be even a part time student while working so much'
},
{
year: 2009,
text: "A series of minimum wage increases pushes the hours per week at minimum wage needed to pay for college down to 40, the length of a standard work week. "
+ "<p>Thhis was the last time the minimum wage was raiased, and this number has not fallen since."
},
{
year: 2019,
text: "After 10 years of a frozen minimum wage, it now requires 56 hours of minimum wage work per week to pay for public college."
+ "This is 2 hours short of a full work day every day of the week."
+ "<p>While it was once possible to pay your way through school while working a minimum wage job, it is no longer a realistic option "
}
];
const annotations = [
{
year: 1984,
text: '20 hrs/wk',
type: 'hours',
height: 50
},
{
year: 1989,
text: '8 yrs no increase',
type: 'wage'
},
{
year: 1994,
text: '30 hrs/wk',
type: 'hours',
height: 80
},
{
year: 2004,
text: '40 hrs/wk',
type: 'hours',
height: 80
},
{
year: 2006,
text: '8 yrs no increasee',
type: 'wage'
},
{
year: 2009,
text: 'Most recent increase',
type: 'wage'
},
{
year: 2013,
text: '6 full days/wk',
type: 'hours',
height: 80
},
];
let year_interval;
let current_year = SLIDES[slide_index].year;
let target_year;
let y_axis_interval;
let target_max_y;
let current_max_y = 1;
let max_y_animate_direction = "";
let color_range;
function nextSlide() {
if (slide_index < SLIDES.length-1) {
slide_index++;
}
updateSlide();
}
function lastSlide() {
if (slide_index > 0) {
slide_index--;
}
updateSlide();
}
function updateSlide(speed=50) {
const slide = SLIDES[slide_index];
target_year = slide.year;
_setInterval("year_interval", animateYear, speed);
}
function animateYear() {
if(target_year > current_year) {
current_year++;
}
else if (target_year < current_year) {
current_year-- ;
}
else {
_clearInterval("year_interval");
}
clearVisualElements();
setVisualElements();
drawChart(current_year);
}
/********************
*
* Graph stuff
*
*******************/
const COST_AXIS_COLOR = 'steelblue';
const config_defaults = {
tick_format: x => x
};
const cost_defaults = {
...config_defaults,
line_color: COST_AXIS_COLOR
}
const formatDollar = (a) => {return '$'+ parseFloat(a).toFixed(2)};
const formatDollarWhole = (a) => {return '$'+ parseFloat(a).toFixed(0)};
const wage_config = {
...config_defaults,
type: "wage",
name: 'minimum_wage',
field: WAGE_FIELD,
label: formatDollar,
color: 'green',
axis: d3.axisRight,
tick_format: formatDollar,
};
let data_sets = [];
var y = {};
var focus = {};
var y_axes = {};
var line_graphs = {};
var x_grid_lines = {};
var line_labels = {};
var line;
var x;
var x_focus;
var x2;
var y2;
// Chart2 section
let y_axis2;
let graph2;
var summary = document.querySelector("#summary");
var slideshow_text = document.querySelector("#slideshow-text");
var filters = document.querySelector("#filters");
var margin = {top: 40, right: 90, bottom: 30, left: 60};
var width = 820 - margin.left - margin.right;
var height = 410 - margin.top - margin.bottom;
var height2 = 220 - margin.top - margin.bottom;
let path;
let svg;
let svg2;
let college_costs;
let display_college_costs;
const parseDate = d3.timeParse("%Y");
const formatTime = d3.timeFormat("%Y");
function clearVisualElements() {
data_sets.forEach((config) => {
x_grid_lines[config.name].remove();
line_graphs[config.name].remove();
focus[config.name].remove();
});
if ( y_axes["cost"]) { y_axes["cost"].remove(); }
if ( y_axes["wage"]) { y_axes["wage"].remove(); }
if (y_axis2) {y_axis2.remove(); }
if (graph2) {graph2.remove();}
y = {};
line_graphs = {};
focus = {};
x_grid_lines = {};
// We need to redraw axis labels, so remove them
svg.selectAll(".line-label").remove();
d3.selectAll(".annotation").remove();
d3.selectAll(".annotation-circle").remove();
}
async function init() {
college_costs = await d3.csv( "https://sheidkamp.github.io/data/college/college_costs.csv");
filters.style.display = "none";
initializeVisualElements();
toggleGraph(false);
setVisualElements();
updateSlide();
}
function mousemove() {
if (mode != INTERACTIVE) {
return;
}
// recover coordinate we need
var x0 = formatTime(
x.invert(d3.mouse(this)[0])
);
drawChart(x0);
}
function initializeVisualElements(){
svg = d3.select("#chart")
.append("svg")
.attr("width", width + margin.left + margin.right)
.attr("height", height + margin.top + margin.bottom)
.append("g")
.attr("transform",
"translate(" + margin.left + "," + margin.top + ")");
svg2 = d3.select("#chart2")
.append("svg")
.attr("width", width + margin.left + margin.right)
.attr("height", height2 + margin.top + margin.bottom)
.append("g")
.attr("transform",
"translate(" + margin.left + "," + margin.top + ")");
// Add X axis
x = d3.scaleTime()
.domain(d3.extent(college_costs, function(d) { return parseDate(d.Year); }))
.range([ 0, width ]);
x2 = d3.scaleBand()
.domain([...d3.map(college_costs, function(d){return d.Year;}).keys()])
.range([0, width])
.padding(0);
let x_axis = svg.append("g")
.attr("transform", "translate(0," + height + ")")
.call(d3.axisBottom(x)
.ticks(d3.timeYear.every(5))
);
svg2.append("g")
.attr("transform", "translate(0," + height2 + ")")
.call(d3.axisBottom(x2)
.tickValues(x2.domain().filter(function(d,i){ return !(d%5)}))
);
y2 = d3.scaleLinear()
.domain([0, 80])
.range([ height2, 0 ]);
// gridlines in y axis function
function make_y_gridlines(yy) {
return d3.axisLeft(yy)
.ticks(8)
}
svg2.append("g")
.call(make_y_gridlines(y2)
.tickSize(-width)
.tickFormat("")
)
.attr("style","color:lightgray");
// Add label/circle for year
x_focus = svg
.append('g')
.append('circle')
.style("fill", "#333")
.attr("stroke", "black")
.attr('r', 4)
.style("opacity", 0.5);
// Add guideline
line = svg
.append('g')
.append('line')
.style("stroke", "lightgray")
.style("stroke-width", 1);
//
color_range = d3.scaleLinear().domain([10,60]).range(['green','red']);
// X Axis labels:
svg.append("text")
.attr("transform",
"translate(" + (width/2) + " ," +
(height + margin.bottom ) + ")")
.style("text-anchor", "middle")
.text("Year");
svg2.append("text")
.attr("transform",
"translate(" + (width/2) + " ," +
(height2 + margin.bottom) + ")")
.style("text-anchor", "middle")
.text("Year");
// text label for the y axis
svg.append("text")
.attr("transform", "rotate(-90)")
.attr("y", 0 - margin.left)
.attr("x",0 - (2*height / 3))
.attr("dy", "1em")
.style("text-anchor", "middle")
.style("fill", "steelblue")
.text("Cost/year");
svg.append("text")
.attr("transform", "rotate(-90)")
.attr("y", 0 - margin.left)
.attr("x",0 - (height / 3))
.attr("dy", "1em")
.style("fill", wage_config.color)
.style("text-anchor", "middle")
.text("dollars/hr");
svg2.append("text")
.attr("transform", "rotate(-90)")
.attr("y", 0 - margin.left + 10)
.attr("x",0 - (height2 / 2))
.attr("dy", "1em")
.style("fill", "steelblue")
.style("text-anchor", "middle")
.text("hrs/week");
svg.append("text")
.attr("transform",
"translate(" + (width/2) + " ," +
(-20) + ")")
.style("text-anchor", "middle")
.text("Federal Minimum Wage and the Cost of College");
svg2.append("text")
.attr("transform",
"translate(" + (width/2) + " ," +
(-20) + ")")
.style("text-anchor", "middle")
.text("Hours per week at minimum wage to pay for all public college expenses");
// Graph titles
// Create a rect on top of the svg area: this rectangle recovers mouse position
svg
.append('rect')
.style("fill", "none")
.style("pointer-events", "all")
.attr('width', width)
.attr('height', height)
.on('mousemove', mousemove);
}
//
//
//
function setVisualElements() {
let filtered_data = filterData();
target_max_y = d3.max(filterData(), function(d) {
const cost_field_array = [];
cost_configs.forEach((config) => {
cost_field_array.push(config.field);
});
const values = [];
//console.log(d)
cost_field_array.forEach((val) => {
values.push(parseInt(d[val]));
})
values.push(1000*parseFloat(d[WAGE_FIELD]))
//console.log("Max out of", values)
return d3.max(values);
});
let ys = d3.scaleLinear()
.domain([0, 0.001 * target_max_y])
.range([ height, 0 ]);
y['wage'] = ys;
y_axes['wage'] = svg.append("g")
.call(
wage_config.axis(ys)
.tickFormat(wage_config.tick_format)
)
.attr("style","color:"+ wage_config.color + ";");
ys = d3.scaleLinear()
.domain([0, target_max_y])
.range([ height, 0 ]);
y_axes['cost'] = svg.append("g")
.call(
d3.axisLeft(ys)
.tickFormat(formatDollarWhole)
)
.attr("style","color:"+ COST_AXIS_COLOR+ ";");
y['cost'] = ys;
// draw the line graphs
data_sets.forEach((config) => {
ys = y[config.type];
x_grid_lines[config.name] =
svg.append('g')
.append('line')
.style("stroke", config.line_color || config.color)
.style("stroke-width", 1)
.style("opacity", 0.3);
let last_x, last_y;
line_graphs[config.name] = svg
.append("g")
.append("path")
.datum(filtered_data)
.attr("fill", "none")
.attr("stroke", config.color)
.attr("stroke-width", 1.5)
.attr("d", d3.line()
.x(function(d) { last_x = x(parseDate(d.Year)); return last_x })
.y(function(d) { last_y = ys(d[config.field]); return last_y; })
);
last_x = d3.max([last_x,30]);
svg.append("text")
.attr("class", "line-label")
.attr("transform", "translate(" + (last_x + 5) + "," + last_y + ")")
.attr("dy", ".15em")
.attr("text-anchor", "start")
.style("fill", config.color)
.style("font-size","10px")
.text(axis_names[config.name]);
svg.append("text")
.attr("class", "line-label")
.attr("transform", "translate(" + (last_x + 5) + "," + (last_y + 10) + ")")
.attr("dy", ".15em")
.attr("text-anchor", "start")
.style("fill", config.color)
.style("font-size","10px")
.text(axis_names_2[config.name]);
var f = svg
.append('g')
.append('circle')
.style("fill", "#333")
.attr("stroke", "black")
.attr('r', 4)
.style("opacity", 0.5);
focus[config.name] = f;
});
// Little chart
y_axis2 = svg2.append("g")
.call(
d3.axisLeft(y2)
)
.attr("style","color:"+ COST_AXIS_COLOR+ ";");
svg.selectAll(".tick")
.each(function (d) {
if ( d === 0 ) {
this.remove();
}
});
console.log("Done")
}
var bisect = d3.bisector(function(d) { return d.Year; }).left;
function drawChartYear(year) {
let x0 = x(parseDate(year));
drawChart(x0)
}
function generateSummary(selectedData) {
const table_data = [];
const table_start = "<table class='summary' width=100%><tr><th colspan=7>Year: " + selectedData.Year + "</th></tr>";
const table_end = "</table>";
let table_rows = '';
const display_names = {
type_all: 'All',
type_private: 'Private',
type_public: 'Public',
cost_all: 'All',
cost_tuition: 'Tuition'
};
const rows = [
{name: 'College Type', value: (d,c)=> display_names[c.school_type]},
{name: 'Cost Type', value: (d,c)=>display_names[c.cost_type]},
{name: 'Cost', value: (d, c) => {return formatDollarWhole(d[c.field]) }},
{name: 'Minimum Wage', value: (d, c) => {return formatDollar(d[wage_config.field]) + "/hr" }},
{name: 'Hours Per Week', value: (d, c) => {return (d[c.field] / d[wage_config.field]/52.0).toFixed(1) }},
];
rows.forEach((row) => {
table_rows += "<tr><td>"+ row.name + "</td>";
cost_configs.forEach((config) => {
table_rows += "<td bgcolor='" + config.color + "'>" + row.value(selectedData, config) + "</td>"
});
table_rows += "</tr>";
});
let slide_text = '';
if (mode == SLIDESHOW) {
//slide_text = SLIDES[slide_index].text + '<br>'
slideshow_text.innerHTML = SLIDES[slide_index].text;
}
console.log("setting summary html")
summary.innerHTML = slide_text + table_start + table_rows + table_end;
}
function drawChart(x0) {
var i = bisect(college_costs, x0, 1);
selectedData = college_costs[i];
generateSummary(selectedData)
// horizontal guidelines and circles at graph interscetions
data_sets.forEach((config) => {
focus[config.name]
.attr("cx", x(parseDate(selectedData.Year)))
.attr("cy", y[config.type](selectedData[config.field]))
.attr("stroke", 'black');
// Horizontal grid markers:
x_grid_lines[config.name]
.attr("x1", 0)
.attr("y1", y[config.type](selectedData[config.field]))
.attr("x2", x(parseDate(selectedData.Year)))
.attr("y2", y[config.type](selectedData[config.field]));
});
x_focus
.attr("cx", x(parseDate(selectedData.Year)))
.attr("cy", height)
.attr("stroke", 'black');
line.attr("x1", x(parseDate(selectedData.Year)))
.attr("y1", 0)
.attr("x2", x(parseDate(selectedData.Year)))
.attr("y2", height);
const filtered_data = filterData();
svg2.selectAll("rect").remove();
graph2 = svg2.append("g")
.selectAll("rect")
.data(filtered_data)
.join("rect")
.attr("x", (d, i) => {return x2(d.Year)})
.attr("y", (d,i) => { return y2( (1.0*d[MAIN_FIELD]) / (52.0*d[WAGE_FIELD]))})
.attr("height", (d,i) => { return height2-y2( (1.0*d[MAIN_FIELD]) / (52.0*d[WAGE_FIELD])) })
.attr("width", (d) => {return x2.bandwidth();} )
.attr("fill", (d) => {
if (mode == SLIDESHOW) {
if ( d.Year == filtered_data[filtered_data.length - 1].Year) {
return "orange";
}
}
else { // mode == INTERACTIVE
if ( d.Year == selectedData.Year) {
return "orange";
}
}
return color_range((1.0*d[MAIN_FIELD]) / (52.0*d[WAGE_FIELD]));
})
svg2
.append('rect')
.style("fill", "none")
.style("pointer-events", "all")
.attr('width', width)
.attr('height', height2)
.on('mousemove', mousemove);
display_annotations();
console.log("ok")
}
function display_annotations() {
if (mode != SLIDESHOW) {
return;
}
const notes = {
wage: [],
hours: []
}
annotations.forEach((note) => {
if( note.year <= current_year ) {
console.log("Annotate", note.text);
notes[note.type].push(note);
}
});
// Chart 1
svg.append("g")
.selectAll(".annotation")
.data(notes.wage)
.join("text")
.attr("class", "annotation")
.attr("y", (d) => {
const i = bisect(college_costs, d.year, 1);
return y.wage(college_costs[i][WAGE_FIELD]) + 15;
})
.attr("x", (d, i) => {return x(parseDate(d.year))})
.style("fill", "#030") //wage_config.color)
.style("bgcolor", "blue")
.style("text-anchor", "center")
.text(d => d.text)
.style("font-size","12px") ;
svg.append("g")
.selectAll(".annotation-circle")
.data(notes.wage)
.join("circle")
.attr("class", "annotation-circle")
.attr("cy", (d) => {
const i = bisect(college_costs, d.year, 1);
return y.wage(college_costs[i][WAGE_FIELD]);
})
.attr("cx", (d, i) => {return x(parseDate(d.year))})
.attr("r", 4)
.style("fill", "#030") //wage_config.color)
.style("opacity","0.5")
//return color_range((1.0*d[MAIN_FIELD]) / (52.0*d[WAGE_FIELD]));
// Chart 2
svg2.append("g")
.selectAll(".annotation")
.data(notes.hours)
.join("text")
.attr("class", "annotation")
.attr("y", (d) => {return 20})
.attr("x", (d, i) => {return x2(d.year) + x2.bandwidth()/2 - 30})
.style("fill", (d) => {
const i = bisect(college_costs, d.year, 1);
return color_range((1.0*college_costs[i][MAIN_FIELD]) / (52.0*college_costs[i][WAGE_FIELD]));
})
.style("text-anchor", "center")
.text(d => d.text)
//.style("font-size","14px") ;
svg2.append("g")
.selectAll(".annotation-circle")
.data(notes.hours)
.join("line")
.attr("class", "annotation-circle")
.attr("y1", (d) => {return 23})
.attr("x1", (d, i) => {return x2(d.year) + x2.bandwidth()/2})
.attr("y2", (d) => {
const i = bisect(college_costs, d.year, 1);