-
Notifications
You must be signed in to change notification settings - Fork 3
/
index.html
2280 lines (1975 loc) · 133 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
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Weighted US News 2012 World University Rankings</title>
<style type= "text/css">
body {
font: Verdana, 'sans-serif' !important;
font-size: 14px !important;
font-weight:normal ;
}
.x.axis path { display: none; }
rect:hover{ fill:pink ; }
td, th { padding: 1px 4px; }
</style>
<div align="center">
<h2> Interactive US News/QS 2012 World University Rankings </h2>
<h3> Conor L. Myhrvold </h3>
<h3> CS299r, Fall 2013, Hanspeter Pfister Lab, Harvard SEAS & IACS </h3>
<h4> <i>Special thanks to Alexander Lex and Pavlos Protopapas</i> </h4>
</div>
<p>
<!-- for padding style: http://www.plus2net.com/html_tutorial/html_blank_space.php -->
<span style="padding-left:185px">
<!-- Twitter follow button start -->
<a href="http://twitter.com/conormyhrvold" class="twitter-follow-button">Follow @conormyhrvold</a>
<script>!function(d,s,id){
var js,fjs=d.getElementsByTagName(s)[0];
if(!d.getElementById(id)){js=d.createElement(s);
js.id=id;
js.src="//platform.twitter.com/widgets.js";
fjs.parentNode.insertBefore(js,fjs);}}(document,"script","twitter-wjs");
</script>
<!-- Twitter follow button end -->
</span>
</p>
<p>
<form name = "form_weight1" id = "form_weight1" >
<!-- http://webtutsdepot.com/2010/04/24/html-5-slider-input-tutorial/ ,
http://stackoverflow.com/questions/20781635/displaying-values-from-multiple-javascript-slider-values/20789860?noredirect=1#20789860 -->
<span style="padding-left:185px">
<text><b> Academic Reputation Score </b></text>
</span>
<span style="padding-left:8px">
<input id="weight1" input type="range" name="weight1" min="0" max="100" value="40" step="1" onchange="showValue(this); newWeights();" />
<span id="range">40</span>
</span>
<script type="text/javascript">
<!-- JavaScript bin that modified code: http://jsbin.com/ISekuSiN/5/edit -->
function get_nextsibling(n) {
x=n.nextSibling;
while (x.nodeType!=1) {
x=x.nextSibling; }
return x; }
function showValue(self) {
get_nextsibling(self).innerHTML=self.value; }
</script>
</form>
<form name = "form_weight2" id = "form_weight2" >
<span style="padding-left:185px">
<text><b> Employer Reputation Score </b></text>
</span>
<span style="padding-left:10px">
<input id="weight2" input type="range" name="weight2" min="0" max="100" value="10" step="1" onchange="showValue(this); newWeights();" />
<span id="range">10</span>
</span>
</form>
<form name = "form_weight3" id = "form_weight3" >
<span style="padding-left:185px">
<text><b> Faculty-Student Ratio Score </b></text>
</span>
<span style="padding-left:5px">
<input id="weight3" input type="range" name="weight3" min="0" max="100" value="20" step="1" onchange="showValue(this); newWeights();" />
<span id="range">20</span>
<span>
</form>
<form name = "form_weight4" id = "form_weight4" >
<span style="padding-left:185px">
<text><b> International Faculty Score </b></text>
</span>
<span style="padding-left:9px">
<input id="weight4" input type="range" name="weight4" min="0" max="100" value="5" step="1" onchange="showValue(this); newWeights();" />
<span id="range">5</span>
</span>
</form>
<form name = "form_weight5" id = "form_weight5" >
<span style="padding-left:185px">
<text><b> International Student Score </b></text>
</span>
<span style="padding-left:7px">
<input id="weight5" input type="range" name="weight5" min="0" max="100" value="5" step="1" onchange="showValue(this); newWeights();" />
<span id="range">5</span>
</span>
</form>
<form name = "form_weight6" id = "form_weight6" >
<span style="padding-left:185px">
<text><b> Faculty Citation Score </b></text>
</span>
<span style="padding-left:39px">
<input id="weight6" input type="range" name="weight6" min="0" max="100" value="20" step="1" onchange="showValue(this); newWeights();" />
<span id="range">20</span>
<!--<text>/ %</text> -->
</span>
</form>
</p>
<!-- Refresh button -- see below for source -->
<script type="text/javascript">
<!-- This script and many more are available free online at -->
<!-- The JavaScript Source!! http://www.javascriptsource.com -->
<!-- Original: Happy Smart -->
<!-- Web Site: http://happysmart.net -->
document.write('<form><input type=button value="Refresh (or hit F5)" style="position: absolute; left: 190px;" onClick="history.go()"></form>') <!-- Goes to default weighted score view by refreshing page -->
// End -->
</script>
<br>/</br>
<script type="text/javascript" src="d3.v3.js"></script>
<div id="option">
<input name="updateButton"
type="button"
value="US News/QS Rankings"
style="position: absolute; left: 190px;"
onclick="originalWeightedScore()" />
</div>
<div id="option">
<input name="sortButton"
type="button"
value="Sort"
style="position: absolute; left: 340px;"
onclick="sort_orig()" />
</div>
<div id="option2">
<input name="scaleButton"
type="button"
value="Unscale Scores"
style="position: absolute; left: 870px;"
onclick="unscale_scenario()" />
</div>
<div id="option3">
<input name="separateButton"
type="button"
value="Separate Scores"
style="position: absolute; left: 980px;"
onclick="separateScores()" />
</div>
<div id="option4">
<input name="stackButton"
type="button"
value="Stack Scores"
style="position: absolute; left: 1095px;"
onclick="stackChoose()" />
</div>
<br></br>
<p><center>
<div id="chart"></div>
</p>
</head>
<body>
<p><center>
<script type="text/javascript">
// ----------------------------------- Declare variables --------------------------------------
//Globally defined variables
var barHeight = 20 ; // height of one bar
var uniLabel = 550 ; // space reserved for bar labels of universities
var finalScoreNumberWidth = 50 ; // space reserved for value labels (right)
var barLabelPadding = 5 ; // padding between bar and bar labels (left)
var gridLabelHeight = 30 ; // space reserved for gridline labels
var topMargin = 5 ; // space from top where chart starts
var totalWidth = 500 ;
var maxFinalScoreBarWidth = totalWidth/2 ; // width of the bar with the max value
var otherBarsNumber = 6 ;
var maxOtherBarWidth = totalWidth - maxFinalScoreBarWidth ;
var ranklist = d3.range(400) ; // list of numbers from 1 to 400 to display on chart (had a more complicated Javascript loop before...)
var init_score_display_offset = 3; // score display offset for academic reputation score to not overlap
var global_display_offset = 4 ; //offset in between rects to ensure that none overlap
var xoffset = -80 ;
//negative number shifts to left. moves graph to the left so that there's more space for spreading out score components.
var weightfactor1 ; // declare weight factors
var weightfactor2 ;
var weightfactor3 ;
var weightfactor4 ;
var weightfactor5 ;
var weightfactor6 ;
//Function-dependent variables. See http://stackoverflow.com/questions/10608964/how-to-share-scope-between-functions-in-d3-js . It's suggested method.
var weight1 ;
var weight2 ;
var weight3 ;
var weight4 ;
var weight5 ;
var weight6 ;
var orig_weight1 ;
var orig_weight2 ;
var orig_weight3 ;
var orig_weight4 ;
var orig_weight5 ;
var orig_weight6 ;
var dataset ;
var barLabel ;
var barLabel2 ;
var barLabel3 ;
var overallScore ;
var academicReputationScore ;
var employerReputationScore ;
var facultyStudentRatioScore ;
var internationalFacultyScore ;
var internationalStudentScore ;
var citationsPerFacultyScore ;
var orig_academicReputationScore ;
var orig_employerReputationScore ;
var orig_facultyStudentRatioScore ;
var orig_internationalFacultyScore ;
var orig_internationalStudentScore ;
var orig_citationsPerFacultyScore ;
var weightedScore ;
var sortedData ;
var yScale ;
var x ;
var y ;
var svg_width ;
var svg_height ;
var yText ;
var chart ;
var labelsContainer ;
var weightedScoreContainer ;
var rankContainer ;
var x2 ;
var academicRepScoreContainer ;
var x3 ;
var employerRepScoreContainer ;
var x4 ;
var facStuRatioScoreContainer ;
var x5 ;
var intFacScoreContainer ;
var x6 ;
var intStuScoreContainer ;
var x7 ;
var citationScoreContainer ;
//standardize x attributes for spacing the score component bars ( spaced vs not spaced, fixed width vs weighted width)
var x_attr2 ;
var x_attr3 ;
var x_attr4 ;
var x_attr5 ;
var x_attr6 ;
var x_attr7 ;
//for separate scores function & other functions
var addWidth ;
var unscale_button_count ;
var separate_button_count ;
var addBarSpace ;
var original_scores_button ; // 0 if it's weighted -- 1 if it's orignal -- 2 if it's new weighted
//new weights
var weight_factor_sum ;
var new_weight1 ;
var new_weight2 ;
var new_weight3 ;
var new_weight4 ;
var new_weight5 ;
var new_weight6 ;
var new_academicReputationScore ;
var new_employerReputationScore ;
var new_facultyStudentRatioScore ;
var new_internationalFacultyScore ;
var new_internationalStudentScore ;
var new_citationsPerFacultyScore ;
var new_weightedScore ;
var base_offset ; //declare variable for a baseline offset that I'll use and define differently for below functions
var stack_score_button = 0 ;
//this is just for the New Weights. If you have more than 1 slider set to > 0, but some zero, when you try to add sliders AFTER you've stacked the new
//one won't show. So in that case, you have to refresh.
//Original weights used by QS Rankings 2012
function startWeights() {
weight1 = 0.4 ; // AcademicReputationScore
weight2 = 0.1; // EmployerReputationScore
weight3 = 0.2 ; // FacultyStudentRatioScore
weight4 = 0.05 ; //InternationalFacultyScore
weight5 = 0.05 ; //InternationalStudentsScore
weight6 = 0.2 ; //CitationsperFacultyScore
}
function origWeights() {
orig_weight1 = 0.4 ; // AcademicReputationScore
orig_weight2 = 0.1 ; // EmployerReputationScore
orig_weight3 = 0.2 ; // FacultyStudentRatioScore
orig_weight4 = 0.05 ; //InternationalFacultyScore
orig_weight5 = 0.05 ; //InternationalStudentsScore
orig_weight6 = 0.2 ; //CitationsperFacultyScore
}
// ----------------------------------- Now start functions to generate charts --------------------------------------
function makeChart() {
dataset = d3.csv.parse(d3.select('#csv').text());
// Rank,School,Country
barLabel = function(d) { return d['School']+' '+','+' '+d['Country']; } ;
barLabel2 = function(d) { return d['Country']; } ;
barLabel3 = function(d) { return d['Rank']; } ;
// OverallScore,AcademicReputationScore,EmployerReputationScore,FacultyStudentRatioScore,InternationalFacultyScore,InternationalStudentsScore,CitationsperFacultyScore
overallScore = function(d) { return parseFloat(d['OverallScore']); } ; //this remains unchanged since it's the original
academicReputationScore = function(d) { return parseFloat(weight1*d['AcademicReputationScore']); } ; //now make function that multiply by weights...use to build rects
employerReputationScore = function(d) { return parseFloat(weight2*d['EmployerReputationScore']); } ;
facultyStudentRatioScore = function(d) { return parseFloat(weight3*d['FacultyStudentRatioScore']); } ;
internationalFacultyScore = function(d) { return parseFloat(weight4*d['InternationalFacultyScore']); } ;
internationalStudentScore = function(d) { return parseFloat(weight5*d['InternationalStudentsScore']); } ;
citationsPerFacultyScore = function(d) { return parseFloat(weight6*d['CitationsperFacultyScore']); } ;
weightedScore = function(d) { return parseFloat(weight1*d['AcademicReputationScore'])+parseFloat(weight2*d['EmployerReputationScore'])
+parseFloat(weight3*d['FacultyStudentRatioScore'])+parseFloat(weight4*d['InternationalFacultyScore'])
+parseFloat(weight5*d['InternationalStudentsScore']+parseFloat(weight6*d['CitationsperFacultyScore'])); } ;
sortedData = dataset.sort(function(a, b) {return d3.descending(weightedScore(a), weightedScore(b));});
//Scales
yScale = d3.scale.ordinal().domain(d3.range(0, sortedData.length))
.rangeBands([0, sortedData.length * barHeight]);
x = d3.scale.linear().domain([0, d3.max(sortedData, weightedScore)])
.range([0, maxFinalScoreBarWidth]);
y = function(d, i) { return yScale(i); };
yText = function(d, i) { return y(d, i) + yScale.rangeBand() / 2; }; // the /2 centers text to middle of bar height (which is middle of bar)
//SVG Container Element
svg_width = totalWidth + uniLabel + finalScoreNumberWidth ;
svg_height = gridLabelHeight + topMargin + sortedData.length * barHeight ;
chart = d3.select('#chart').append("svg")
.attr('width', svg_width) //set to accommodate additional bars I'll build
.attr('height', svg_height);
// University Names
labelsContainer = chart.append('g')
.attr("class", "university-labels-container") //create labels so can be updated
.attr('transform', 'translate(' + (uniLabel - barLabelPadding) + ',' + (gridLabelHeight + topMargin) + ')')
.selectAll('text')
.data(sortedData)
.enter()
.append('text')
.attr('x', xoffset)
.attr('y', yText)
.attr('stroke', 'none')
.attr('fill', 'black')
.attr("dy", ".35em") // vertical-align: middle
.attr('text-anchor', 'end')
.text(barLabel);
// Overall Score Bars
weightedScoreContainer = chart.append('g')
.attr('transform', 'translate(' + uniLabel + ',' + (gridLabelHeight + topMargin) + ')');
weightedScoreContainer.selectAll("rect")
.data(sortedData)
.enter()
.append("rect")
.attr('x', xoffset)
.attr('y', y)
.attr('height', yScale.rangeBand())
.attr('width', function(d) { return x(weightedScore(d)); })
.attr('stroke', 'black')
.attr('fill', '#4985D6') //blue http://www.hitmill.com/html/pastels.html
.on("click", function(d) { console.log(d) ;})
.append("title")
.text(function(d){ return "Overall Weighted Score: " + d3.round(weightedScore(d), 1); }) ;
// Bar Value Labels
weightedScoreContainer.selectAll("text")
.data(sortedData)
.enter()
.append("text")
.attr("x", function(d) { return x(weightedScore(d))+xoffset; })
.attr("y", yText)
.attr("dx", -25) // padding for bar value labels
.attr("dy", ".3em") // vertical-align: middle
.attr("text-anchor", "right") // text-align: right
.attr("fill", "white")
.style("font-weight", "bold")
.text(function(d) { return d3.round(weightedScore(d), 0); });
//static rankings to appear on left hand side (will always stay there)
rankContainer = chart.append('g')
.attr('transform', 'translate(' + uniLabel + ',' + (gridLabelHeight + topMargin) + ')');
rankContainer.selectAll("rect")
.data(sortedData)
.enter()
.append("rect")
.attr('x', -550)
.attr('y', y)
.attr('height', yScale.rangeBand())
.attr('width', function(d) { return 30; })
.attr('stroke', 'black')
.attr('fill', 'white')
.append("title")
.text("Overall Rank") ;
rankContainer.selectAll("text")
.data(ranklist)
.enter()
.append("text")
.attr("x", function(d) { return 15;})
.attr("y", function(d, i) { return y(d, i) + yScale.rangeBand() /4 ; })
.attr("dx", -550) // padding for bar value labels
.attr("dy", ".6em") // vertical-align
.attr("text-anchor", "middle") // text-align
.attr("fill", "black")
.text(function(d) { return ranklist[d]+1 ; }) ;
x2 = d3.scale.linear().domain([0, d3.max(sortedData, academicReputationScore)])
.range([0, parseInt(weight1*maxOtherBarWidth)]);
x_attr2 = maxFinalScoreBarWidth ;
// Score Components Bars
academicRepScoreContainer = chart.append('g')
.attr('transform', 'translate(' + uniLabel + ',' + (gridLabelHeight + topMargin) + ')');
academicRepScoreContainer.selectAll("rect")
.data(sortedData)
.enter()
.append("rect")
.attr('x', x_attr2+xoffset + init_score_display_offset)
.attr('y', y)
.attr('height', yScale.rangeBand())
.attr('width', function(d) { return x2(academicReputationScore(d)); })
.attr('stroke', 'black')
.attr('fill', '#FF8A8A') //red http://www.hitmill.com/html/pastels.html
.on("click", function(d) { console.log(d) ;})
.append("title")
.text(function(d){ return "Academic Reputation Score: " + d3.round(academicReputationScore(d), 1); }) ;
x3 = d3.scale.linear().domain([0, d3.max(sortedData, employerReputationScore)])
.range([0, parseInt(weight2*maxOtherBarWidth)]);
x_attr3 = maxFinalScoreBarWidth+weight1*maxOtherBarWidth ;
employerRepScoreContainer = chart.append('g')
.attr('transform', 'translate(' + uniLabel + ',' + (gridLabelHeight + topMargin) + ')');
employerRepScoreContainer.selectAll("rect")
.data(sortedData)
.enter()
.append("rect")
.attr('x', x_attr3+xoffset + global_display_offset)
.attr('y', y)
.attr('height', yScale.rangeBand())
.attr('width', function(d) { return x3(employerReputationScore(d)); })
.attr('stroke', 'black')
.attr('fill', '#72FE95') //green http://www.hitmill.com/html/pastels.html
.on("click", function(d) { console.log(d) ;})
.append("title")
.text(function(d){ return "Employer Reputation Score: " + d3.round(employerReputationScore(d), 1); }) ;
x4 = d3.scale.linear()
.domain([0, d3.max(sortedData, facultyStudentRatioScore)])
.range([0, parseInt(weight3*maxOtherBarWidth)]);
x_attr4 = maxFinalScoreBarWidth+(weight1+weight2)*maxOtherBarWidth ;
facStuRatioScoreContainer = chart.append('g')
.attr('transform', 'translate(' + uniLabel + ',' + (gridLabelHeight + topMargin) + ')');
facStuRatioScoreContainer.selectAll("rect")
.data(sortedData)
.enter()
.append("rect")
.attr('x', x_attr4+xoffset + global_display_offset)
.attr('y', y)
.attr('height', yScale.rangeBand())
.attr('width', function(d) { return x4(facultyStudentRatioScore(d)); })
.attr('stroke', 'black')
.attr('fill', '#E77AFE') //purple http://www.hitmill.com/html/pastels.html
.on("click", function(d) { console.log(d) ;})
.append("title")
.text(function(d){ return "Faculty-Student Ratio Score: " + d3.round(facultyStudentRatioScore(d), 1); }) ;
x5 = d3.scale.linear()
.domain([0, d3.max(sortedData, internationalFacultyScore)])
.range([0, parseInt(weight4*maxOtherBarWidth)]);
x_attr5 = maxFinalScoreBarWidth+(weight1+weight2+weight3)*maxOtherBarWidth ;
intFacScoreContainer = chart.append('g')
.attr('transform', 'translate(' + uniLabel + ',' + (gridLabelHeight + topMargin) + ')');
intFacScoreContainer.selectAll("rect")
.data(sortedData)
.enter()
.append("rect")
.attr('x', x_attr5+xoffset + global_display_offset)
.attr('y', y)
.attr('height', yScale.rangeBand())
.attr('width', function(d) { return x5(internationalFacultyScore(d)); })
.attr('stroke', 'black')
.attr('fill', '#FFA04A') //orange http://www.hitmill.com/html/pastels2.html
.on("click", function(d) { console.log(d) ;})
.append("title")
.text(function(d){ return "International Faculty Score: " + d3.round(internationalFacultyScore(d), 1); }) ;
x6 = d3.scale.linear()
.domain([0, d3.max(sortedData, internationalStudentScore)])
.range([0, parseInt(weight5*maxOtherBarWidth)]);
x_attr6 = maxFinalScoreBarWidth+(weight1+weight2+weight3+weight4)*maxOtherBarWidth ;
intStuScoreContainer = chart.append('g')
.attr('transform', 'translate(' + uniLabel + ',' + (gridLabelHeight + topMargin) + ')');
intStuScoreContainer.selectAll("rect")
.data(sortedData)
.enter()
.append("rect")
.attr('x', x_attr6+xoffset + global_display_offset)
.attr('y', y)
.attr('height', yScale.rangeBand())
.attr('width', function(d) { return x6(internationalStudentScore(d)); })
.attr('stroke', 'black')
.attr('fill', '#D19C67') //brown http://www.hitmill.com/html/pastels2.html
.on("click", function(d) { console.log(d) ;})
.append("title")
.text(function(d){ return "International Student Score: " + d3.round(internationalStudentScore(d), 1); }) ;
x7 = d3.scale.linear()
.domain([0, d3.max(sortedData, citationsPerFacultyScore)])
.range([0, parseInt(weight6*maxOtherBarWidth)]);
x_attr7 = parseFloat(maxFinalScoreBarWidth+(weight1+weight2+weight3+weight4+weight5)*maxOtherBarWidth) ;
citationScoreContainer = chart.append('g')
.attr('transform', 'translate(' + uniLabel + ',' + (gridLabelHeight + topMargin) + ')');
citationScoreContainer.selectAll("rect")
.data(sortedData)
.enter()
.append("rect")
.attr('x', x_attr7+xoffset + global_display_offset)
.attr('y', y)
.attr('height', yScale.rangeBand())
.attr('width', function(d) { return x7(citationsPerFacultyScore(d)); })
.attr('stroke', 'black')
.attr('fill', '#FFF06A') //yellow http://www.hitmill.com/html/pastels2.html
.on("click", function(d) { console.log(d) ;})
.append("title")
.text(function(d){ return "Faculty Citation Score: " + d3.round(citationsPerFacultyScore(d), 1); }) ;
original_scores_button = 0;
}
// ----------------------------------- Next function --------------------------------------
function originalWeightedScore() {
if(unscale_button_count==0){
original_scores_button = 1;
origWeights() ;
orig_academicReputationScore = function(d) { return parseFloat(orig_weight1*d['AcademicReputationScore']); } ;
//now make function that multiply by weights...use to build rects
orig_employerReputationScore = function(d) { return parseFloat(orig_weight2*d['EmployerReputationScore']); } ;
orig_facultyStudentRatioScore = function(d) { return parseFloat(orig_weight3*d['FacultyStudentRatioScore']); } ;
orig_internationalFacultyScore = function(d) { return parseFloat(orig_weight4*d['InternationalFacultyScore']); } ;
orig_internationalStudentScore = function(d) { return parseFloat(orig_weight5*d['InternationalStudentsScore']); } ;
orig_citationsPerFacultyScore = function(d) { return parseFloat(orig_weight6*d['CitationsperFacultyScore']); } ;
//first update the overall scores
weightedScoreContainer.selectAll("rect")
.data(sortedData)
.transition()
.duration(1500)
.ease("linear")
.attr('y', y)
.attr('height', yScale.rangeBand())
.attr('width', function(d) { return x(overallScore(d)); })
.attr('stroke', 'black')
.attr('fill', '#4985D6') //blue http://www.hitmill.com/html/pastels.html
.select("title")
.text(function(d){ return "Original Overall Score: " + d3.round(overallScore(d), 1); }) ;
weightedScoreContainer.selectAll("text")
.data(sortedData)
.transition()
.duration(1500)
.ease("elastic")
.attr("x", function(d) { return x(overallScore(d))+xoffset; })
.attr("y", yText)
.attr("dx", -31) // padding for bar value labels
.attr("dy", ".3em") // vertical-align: middle
.attr("text-anchor", "right") // text-align: right
.attr("fill", "white")
.style("font-weight", "bold")
.text(function(d) { return d3.round(overallScore(d), 0); });
x_attr2 = maxFinalScoreBarWidth ;
//now update the component weights and scores
academicRepScoreContainer.selectAll("rect")
.data(sortedData)
.transition()
.duration(1500)
.ease("linear")
.attr('x', x_attr2 + xoffset + init_score_display_offset)
.attr('y', y)
.attr('height', yScale.rangeBand())
.attr('width', function(d) { return x2(orig_academicReputationScore(d)); })
.attr('stroke', 'black')
.attr('fill', '#FF8A8A') //red http://www.hitmill.com/html/pastels.html
.select("title")
.text(function(d){ return "Original Academic Reputation Score: " + d3.round(orig_academicReputationScore(d), 1); }) ;
x_attr3 = maxFinalScoreBarWidth+orig_weight1*maxOtherBarWidth ;
employerRepScoreContainer.selectAll("rect")
.data(sortedData)
.transition()
.duration(1500)
.ease("linear")
.attr('x', x_attr3 + xoffset + global_display_offset)
.attr('y', y)
.attr('height', yScale.rangeBand())
.attr('width', function(d) { return x3(orig_employerReputationScore(d)); })
.attr('stroke', 'black')
.attr('fill', '#72FE95') //green http://www.hitmill.com/html/pastels.html
.select("title")
.text(function(d){ return "Original Employer Reputation Score: " + d3.round(orig_employerReputationScore(d), 1); }) ;
x_attr4 = maxFinalScoreBarWidth+(orig_weight1+orig_weight2)*maxOtherBarWidth ;
facStuRatioScoreContainer.selectAll("rect")
.data(sortedData)
.transition()
.duration(1500)
.ease("linear")
.attr('x', x_attr4 + xoffset + global_display_offset)
.attr('y', y)
.attr('height', yScale.rangeBand())
.attr('width', function(d) { return x4(orig_facultyStudentRatioScore(d)); })
.attr('stroke', 'black')
.attr('fill', '#E77AFE') //purple http://www.hitmill.com/html/pastels.html
.select("title")
.text(function(d){ return "Original Faculty-Student Ratio Score: " + d3.round(orig_facultyStudentRatioScore(d), 1); }) ;
x_attr5 = maxFinalScoreBarWidth+(orig_weight1+orig_weight2+orig_weight3)*maxOtherBarWidth ;
intFacScoreContainer.selectAll("rect")
.data(sortedData)
.transition()
.duration(1500)
.ease("linear")
.attr('x', x_attr5 + xoffset + global_display_offset)
.attr('y', y)
.attr('height', yScale.rangeBand())
.attr('width', function(d) { return x5(orig_internationalFacultyScore(d)); })
.attr('stroke', 'black')
.attr('fill', '#FFA04A') //orange http://www.hitmill.com/html/pastels2.html
.select("title")
.text(function(d){ return "Original International Faculty Score: " + d3.round(orig_internationalFacultyScore(d), 1); }) ;
x_attr6 = maxFinalScoreBarWidth+(orig_weight1+orig_weight2+orig_weight3+orig_weight4)*maxOtherBarWidth ;
intStuScoreContainer.selectAll("rect")
.data(sortedData)
.transition()
.duration(1500)
.ease("linear")
.attr('x', x_attr6 + xoffset + global_display_offset)
.attr('y', y)
.attr('height', yScale.rangeBand())
.attr('width', function(d) { return x6(orig_internationalStudentScore(d)); })
.attr('stroke', 'black')
.attr('fill', '#D19C67') //brown http://www.hitmill.com/html/pastels2.html
.select("title")
.text(function(d){ return "Original International Student Score: " + d3.round(orig_internationalStudentScore(d), 1); }) ;
x_attr7 = parseFloat(maxFinalScoreBarWidth+(orig_weight1+orig_weight2+orig_weight3+orig_weight4+orig_weight5)*maxOtherBarWidth) ;
citationScoreContainer.selectAll("rect")
.data(sortedData)
.transition()
.duration(1500)
.ease("linear")
.attr('x', x_attr7 + xoffset + global_display_offset)
.attr('y', y)
.attr('height', yScale.rangeBand())
.attr('width', function(d) { return x7(orig_citationsPerFacultyScore(d)); })
.attr('stroke', 'black')
.attr('fill', '#FFF06A') //yellow http://www.hitmill.com/html/pastels2.html
.select("title")
.text(function(d){ return "Original Faculty Citation Score: " + d3.round(orig_citationsPerFacultyScore(d), 1); }) ;
separate_button_count = 1;
// added since this function stacks the scores together; otherwise when you hit 'separate score' afterwards it'll stack beyond what it's supposed to...
}
else if(unscale_button_count==1){
alert("Original score transition is not available once weighted data is unscaled. :-o Hit Refresh to reset (then select Original), or choose Separate or stack options.") ;
}
}
// ----------------------------------- Next function --------------------------------------
function sort_orig() {
if(unscale_button_count==0){
//reassign variables to the original rankings criteria
dataset = d3.csv.parse(d3.select('#csv').text());
sortedData = dataset.sort(function(a, b) {return d3.descending(overallScore(a), overallScore(b));});
// scales
yScale = d3.scale.ordinal().domain(d3.range(0, sortedData.length))
.rangeBands([0, sortedData.length * barHeight]);
x = d3.scale.linear().domain([0, d3.max(sortedData, overallScore)])
.range([0, maxFinalScoreBarWidth]);
y = function(d, i) { return yScale(i); };
yText = function(d, i) { return y(d, i) + yScale.rangeBand() / 2; };
// Rank,School,Country
barLabel = function(d) { return d['School']+' '+','+' '+d['Country']; } ;
// update University Names
labelsContainer = chart.select("g.university-labels-container").selectAll("text")
.data(sortedData)
.transition()
.duration(1500)
.attr('x', xoffset)
.attr('y', yText)
.attr('stroke', 'none')
.attr('fill', 'black')
.attr("dy", ".35em")
.attr('text-anchor', 'end')
.text(barLabel) ;
originalWeightedScore() ;
}
else if(unscale_button_count==1){
alert("Original score transition is not available once weighted data is unscaled. :-o Hit Refresh to reset (then select Original), or choose Separate or stack options.") ;
}
}
// ----------------------------------- Next function --------------------------------------
unscale_button_count = 0; //initialize, but set to 1 permanently as soon as it's run
function unscale_data() {
if(unscale_button_count==0){
if(original_scores_button==2){
maxOtherBarWidth = (totalWidth - maxFinalScoreBarWidth)/ otherBarsNumber ;
//update x attribute for component scores to make them all the maximum same length irrespective of weighting differences
var x2_unscale = d3.scale.linear().domain([0, d3.max(sortedData, new_academicReputationScore)])
.range([0, maxOtherBarWidth]); //go from factoring weights here, to setting all linear scale axes ranges to simply 0 to maxOtherBarWidth
// Score Components Bars
x_attr2 = maxFinalScoreBarWidth ;
academicRepScoreContainer.selectAll("rect")
.data(sortedData)
.transition()
.duration(1500)
.ease("linear")
.attr('x', x_attr2+xoffset + init_score_display_offset)
.attr('y', y)
.attr('height', yScale.rangeBand())
.attr('width', function(d) { return x2_unscale(new_academicReputationScore(d)); }) ;
var x3_unscale = d3.scale.linear().domain([0, d3.max(sortedData, new_employerReputationScore)])
.range([0, maxOtherBarWidth]);
x_attr3 = maxFinalScoreBarWidth+maxOtherBarWidth ;
employerRepScoreContainer.selectAll("rect")
.data(sortedData)
.transition()
.duration(1500)
.ease("linear")
.attr('x', x_attr3+xoffset + global_display_offset)
.attr('y', y)
.attr('height', yScale.rangeBand())
.attr('width', function(d) { return x3_unscale(new_employerReputationScore(d)); }) ;
var x4_unscale = d3.scale.linear().domain([0, d3.max(sortedData, new_facultyStudentRatioScore)])
.range([0, maxOtherBarWidth]);
x_attr4 = maxFinalScoreBarWidth+2*maxOtherBarWidth ;
facStuRatioScoreContainer.selectAll("rect")
.data(sortedData)
.transition()
.duration(1500)
.ease("linear")
.attr('x', x_attr4+xoffset + global_display_offset)
.attr('y', y)
.attr('height', yScale.rangeBand())
.attr('width', function(d) { return x4_unscale(new_facultyStudentRatioScore(d)); }) ;
x5_unscale = d3.scale.linear().domain([0, d3.max(sortedData, new_internationalFacultyScore)])
.range([0, maxOtherBarWidth]);
x_attr5 = maxFinalScoreBarWidth+3*maxOtherBarWidth ;
intFacScoreContainer.selectAll("rect")
.data(sortedData)
.transition()
.duration(1500)
.ease("linear")
.attr('x', x_attr5+xoffset + global_display_offset)
.attr('y', y)
.attr('height', yScale.rangeBand())
.attr('width', function(d) { return x5_unscale(new_internationalFacultyScore(d)); }) ;
x6_unscale = d3.scale.linear().domain([0, d3.max(sortedData, new_internationalStudentScore)])
.range([0, maxOtherBarWidth]);
x_attr6 = maxFinalScoreBarWidth+4*maxOtherBarWidth ;
intStuScoreContainer.selectAll("rect")
.data(sortedData)
.transition()
.duration(1500)
.ease("linear")
.attr('x', x_attr6+xoffset)
.attr('y', y)
.attr('height', yScale.rangeBand())
.attr('width', function(d) { return x6_unscale(new_internationalStudentScore(d)); }) ;
x7_unscale = d3.scale.linear().domain([0, d3.max(sortedData, new_citationsPerFacultyScore)])
.range([0, maxOtherBarWidth]);
x_attr7 = maxFinalScoreBarWidth+5*maxOtherBarWidth ;
citationScoreContainer.selectAll("rect")
.data(sortedData)
.transition()
.duration(1500)
.ease("linear")
.attr('x', x_attr7+xoffset + global_display_offset)
.attr('y', y)
.attr('height', yScale.rangeBand())
.attr('width', function(d) { return x7_unscale(new_citationsPerFacultyScore(d)); }) ;
unscale_button_count = 1;
}
else{
maxOtherBarWidth = (totalWidth - maxFinalScoreBarWidth)/ otherBarsNumber ;
//update x attribute for component scores to make them all the maximum same length irrespective of weighting differences
var x2_unscale = d3.scale.linear().domain([0, d3.max(sortedData, academicReputationScore)])
.range([0, maxOtherBarWidth]); //go from factoring weights here, to setting all linear scale axes ranges to simply 0 to maxOtherBarWidth
// Score Components Bars
x_attr2 = maxFinalScoreBarWidth ;
academicRepScoreContainer.selectAll("rect")
.data(sortedData)
.transition()
.duration(1500)
.ease("linear")
.attr('x', x_attr2+xoffset + init_score_display_offset)
.attr('y', y)
.attr('height', yScale.rangeBand())
.attr('width', function(d) { return x2_unscale(academicReputationScore(d)); }) ;
var x3_unscale = d3.scale.linear().domain([0, d3.max(sortedData, employerReputationScore)])
.range([0, maxOtherBarWidth]);
x_attr3 = maxFinalScoreBarWidth+maxOtherBarWidth ;
employerRepScoreContainer.selectAll("rect")
.data(sortedData)
.transition()
.duration(1500)
.ease("linear")
.attr('x', x_attr3+xoffset + global_display_offset)
.attr('y', y)
.attr('height', yScale.rangeBand())
.attr('width', function(d) { return x3_unscale(employerReputationScore(d)); }) ;
var x4_unscale = d3.scale.linear().domain([0, d3.max(sortedData, facultyStudentRatioScore)])
.range([0, maxOtherBarWidth]);
x_attr4 = maxFinalScoreBarWidth+2*maxOtherBarWidth ;
facStuRatioScoreContainer.selectAll("rect")
.data(sortedData)
.transition()
.duration(1500)
.ease("linear")
.attr('x', x_attr4+xoffset + global_display_offset)
.attr('y', y)
.attr('height', yScale.rangeBand())
.attr('width', function(d) { return x4_unscale(facultyStudentRatioScore(d)); }) ;
x5_unscale = d3.scale.linear().domain([0, d3.max(sortedData, internationalFacultyScore)])
.range([0, maxOtherBarWidth]);
x_attr5 = maxFinalScoreBarWidth+3*maxOtherBarWidth ;
intFacScoreContainer.selectAll("rect")
.data(sortedData)
.transition()
.duration(1500)
.ease("linear")
.attr('x', x_attr5+xoffset + global_display_offset)
.attr('y', y)
.attr('height', yScale.rangeBand())
.attr('width', function(d) { return x5_unscale(internationalFacultyScore(d)); }) ;
x6_unscale = d3.scale.linear().domain([0, d3.max(sortedData, internationalStudentScore)])
.range([0, maxOtherBarWidth]);
x_attr6 = maxFinalScoreBarWidth+4*maxOtherBarWidth ;
intStuScoreContainer.selectAll("rect")
.data(sortedData)
.transition()
.duration(1500)
.ease("linear")
.attr('x', x_attr6+xoffset + global_display_offset)
.attr('y', y)
.attr('height', yScale.rangeBand())
.attr('width', function(d) { return x6_unscale(internationalStudentScore(d)); }) ;
x7_unscale = d3.scale.linear().domain([0, d3.max(sortedData, citationsPerFacultyScore)])
.range([0, maxOtherBarWidth]);
x_attr7 = maxFinalScoreBarWidth+5*maxOtherBarWidth ;
citationScoreContainer.selectAll("rect")
.data(sortedData)
.transition()
.duration(1500)
.ease("linear")
.attr('x', x_attr7+xoffset + global_display_offset)
.attr('y', y)
.attr('height', yScale.rangeBand())
.attr('width', function(d) { return x7_unscale(citationsPerFacultyScore(d)); }) ;
unscale_button_count = 1;
}
}
}
//this is the function that you call for the button, to avoid garbled interaction where you try to unscale, separated score components (which doesn't work)
function unscale_scenario(){
if(separate_button_count==1){
unscale_data() ;
}
else if(separate_button_count==0){
separateScores() ;
unscale_data() ; }
}
// ----------------------------------- Next function --------------------------------------