-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex4.html
918 lines (691 loc) · 23.7 KB
/
index4.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
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<style>
body {
font: 10px sans-serif;
}
#copy {
width:240px;
display:inline-block;
vertical-align:top;
}
#charts {
display:inline-block;
}
.chart {
display:inline;
}
.spacer {
height:15px;
}
.styled-select select {
background: transparent;
width: 240px;
padding: 5px;
font-size: 16px;
line-height: 1;
border: 0;
border-radius: 0;
height: 28px;
-webkit-appearance: none;
-moz-appearance:none;
}
.styled-select {
width: 240px;
height: 28px;
overflow: hidden;
padding-left:28px;
border: 1px solid #ccc;
}
#subject-select {
background: url(svg/education36.svg) no-repeat left/28px 28px;
}
#attitude-select {
background: url(svg/student53.svg) no-repeat left/28px 28px;
}
#school-select {
background: url(svg/school50.svg) no-repeat left/28px 28px;
}
.axis path,
.axis line {
fill: none;
stroke: #000;
shape-rendering: crispEdges;
}
.dot {
stroke: #000;
}
</style>
</head>
<body>
<span id = "title">
<h1>PISA 2012 - The relationship of student attitudes to results</h1>
</span>
<div id = "copy">
<p>
In the PISA 2012 survey, 15 year old students accross the world were assessed for their abilities in mathmatics, science and reading.
</p>
<p>
The students were also asked to answer a questionaire investigating, among other things, their attitude towards school.
</p>
<p>
There was also a school questionaire filled out by the senior administrator in each school.
</p>
<p>
This graphic is looking only at schools in the United Kingdom and the relationship between the students attitude and their grade in each of the three subjects.
</p>
<p>
Students were asked how much they agree or dissagree with a number of statements. In this case, the statement was 'School has been a waste of time.'
</p>
<p>
The first chart shows the percentage of students that gave each answer (along the y axis) along with their average score in one of the skills (in this case, Maths).
</p>
<p>
As we might expect, the students who strongly agreed that school had been a waste of time had the lowest scores. Of course correlation does not equal causation and it is possible that the students who strongly agreed, were in fact correct in believing that school had not been a good use of their time.
</p>
<p>
The third to sixth charts show the same data looking at the schools from the 0 to 25th percentile (in this case, of the schools average Maths scores), the 25th to 50th, the 50th to 75th and 75th to 100th percentile.
</p>
<p>
The second chart shows the average scores for each percentile bin. It can also show the schools divided by answers to the school questionaire regarding the resources available to the school.
</p>
<p>
You can adjust the parameters of the charts below.
</p>
Subject for average score comparison:
<div class = "styled-select" id = "subject-select">
<select id = "subject">
<option value="maths">Student Maths score</option>
<option value="read">Student Reading score</option>
<option value="scie">Student Science score</option>
</select>
</div>
Attitude statement that students agree or disagree with:
<div class = "styled-select" id = "attitude-select">
<select id = "attitude">
</select>
</div>
Subject of school percentiles or availabilty of resources at school:
<div class = "styled-select" id = "school-select">
<select id = "school">
</select>
</div>
</div>
<div id = "charts">
<div class = "spacer">
</div>
<div>
</div>
<div id = "chartone" class = "chart">
</div>
<div id = "charttwo" class = "chart"> </div>
<div class = "spacer">
</div>
<span id = "chartthree"> </span>
<span id = "chartfour"> </span>
<div class = "spacer"><p></p></div>
<span id = "chartfive"> </span>
<span id = "chartsix"> </span>
<div class = "spacer"></div>
</div>
<div id = "links">
LINKS <br>
Pisa 2012 Results: <a href="http://www.oecd.org/pisa/keyfindings/pisa-2012-results.htm">http://www.oecd.org/pisa/keyfindings/pisa-2012-results.htm</a><br>
Student Questionaire: <a href="https://nces.ed.gov/surveys/pisa/pdf/MS12_StQ_FormB_ENG_USA_final.pdf">https://nces.ed.gov/surveys/pisa/pdf/MS12_StQ_FormB_ENG_USA_final.pdf</a>
<br>
School Questionaire: <a href="https://nces.ed.gov/surveys/pisa/pdf/MS12_ScQ_USA_final.pdf">https://nces.ed.gov/surveys/pisa/pdf/MS12_ScQ_USA_final.pdf
</a>
<br>
Icons: <a href="http://www.freepik.com">designed by freepik</a>
</div>
<script src="d3.v3.min.js"></script>
<script>
var divs_arr = ["#chartone","#charttwo","#chartthree","#chartfour","#chartfive","#chartsix"]
var attitudes_arr = [
["ST86Q01","Students get along well with most teachers","Q39"],
["ST86Q02","Most teachers are interested in students well-being","Q39"],
["ST86Q03","Most of my teachers really listed to what I have to say.","Q39"],
["ST86Q04","If I need extra help, I will receive it from my teachers.","Q39"],
["ST86Q05","Most of my teachers treat me fairly.","Q39"],
["ST87Q01","I feel like an outsider (or left out of things) at school.","Q40"],
["ST87Q02","I make friends easily at school","Q40"],
["ST87Q03","I feel like I belong at school.","Q40"],
["ST87Q04","I feel awkward and out of place in my school.","Q40"],
["ST87Q05","Other students seem to like me","Q40"],
["ST87Q06","I feel lonely at school.","Q40"],
["ST87Q07","I feel happy at school.","Q40"],
["ST87Q08","Things are ideal in my school.","Q40"],
["ST87Q09","I am satisfied with my school.","Q40"],
["ST88Q01","School has done little to prepare me for adult life when I leave school.","Q41"],
["ST88Q02","School has been a waste of time.","Q41"],
["ST88Q03","School has helped give me confidence to make decisions.","Q41"],
["ST88Q04","School has taught me things which could be useful in a job.","Q41"],
["ST89Q02","Trying had at school will help me get a good job.","Q42"],
["ST89Q03","Trying hard at school will help me get into a good college.","Q42"],
["ST89Q04","I enjoy receiving good grades.","Q42"],
["ST89Q05","Trying hard at school is important.","Q42"],
["ST91Q01","If I put in enough effort I can succeed in school.","Q43"],
["ST91Q02","It is completely my choice whether or not I do well at school.","Q43"],
["ST91Q03","Family demands or other problems prevent me from putting a lot of time into my school work.","Q43"],
["ST91Q04","If I had different teachers I would try harder at school.","Q43"],
["ST91Q05","If I wanted to I could do well in school.","Q43"],
["ST91Q06","I do badly in school whether or not I study for my exams.","Q43"]
]
var main_titles = [
"Students Attitudes",
"School Variable",
"Students Attitude by school variable",
"Students Attitude by school variable",
"Students Attitude by school variable",
"Students Attitude by school variable",
]
var attitudes_domain = ["Strongly Agree","Agree","Disagree","Strongly Disagree"]
var school_arr = [
["schoolmath","0-25,25-50,50-75,75-100 Percentiles (Maths)"],
["schoolread","0-25,25-50,50-75,75-100 Percentiles (Reading)"],
["schoolscie","0-25,25-50,50-75,75-100 Percentiles (Science)"],
["SC14Q01","a) A lack of qualified science teachers"],
["SC14Q02","b) A lack of qualified mathematics teachers"],
["SC14Q03","c) A lack of qualified English teachers"],
["SC14Q04","d) A lack of qualified teachers of other subjects"],
["SC14Q05","e) Shortage or inadequacy of science laboratory equipment"],
["SC14Q06","f) Shortage or inadequacy of instructional materials (e.g., textbooks)"],
["SC14Q07","g) Shortage or inadequacy of computers for instruction"],
["SC14Q08","h) Lack or inadequacy of Internet connectivity"],
["SC14Q09","i) Shortage or inadequacy of computer software for instruction"],
["SC14Q010","j) Shortage or inadequacy of library materials"]
]
var school_domain = ["Not at all","Very Little","To some extent","A lot"]
var percentile_domain = ["0 to 25th Percentile","25th to 50th Percentile","50th to 75th Percentile","75th to 100th Percentile"]
// var margin = {top: 40, right: 20, bottom: 30, left: 40},
// width = 340 - margin.left - margin.right,
// height = 310 - margin.top - margin.bottom,
// swidth = 260 - margin.left - margin.right,
// sheight = 180 - margin.top - margin.bottom;
var color = d3.scale.category10();
var schoolcolor = d3.scale.ordinal().range(['#9467bd','#8c564b', '#e377c2','#bcbd22'])
// var x = d3.scale.linear()
// .range([0, width]);
// var y = d3.scale.linear()
// .range([height,0]);
// set inintial parameters
var subject_var = "maths"
var attitude_var = "ST88Q02"
var ukschools;
var chartdata;
function getAttitudeString () {
for (i = 0; i<=attitudes_arr.length; i++) {
if (attitudes_arr[i][0]==attitude_var) {
return attitudes_arr[i][1]
}
}
}
function getSchoolString () {
for (i = 0; i<=school_arr.length; i++) {
if (school_arr[i][0]==school_var) {
return school_arr[i][1]
}
}
}
d3.csv("uk_studentsThree.csv",function(error, data) {
if (error) throw error;
ukschools = data;
drawChart();
});
var school_var = "schoolmath"
var svgs = [];
var xAxiss = [];
var yAxiss = [];
var legends = [];
var attitude_el = document.getElementById("attitude");
for (i = 0; i < attitudes_arr.length;i++) {
var option = document.createElement("option");
option.setAttribute("value", attitudes_arr[i][0]);
option.text = attitudes_arr[i][1];
attitude_el.appendChild(option);
}
var school_el = document.getElementById("school");
for (i = 0; i < school_arr.length;i++) {
var option = document.createElement("option");
option.setAttribute("value", school_arr[i][0]);
option.text = school_arr[i][1];
school_el.appendChild(option);
}
d3.select('#attitude')
.property( "value", attitude_var )
.on('change', function() {
var newData = d3.select(this).property('value');
attitude_var = newData;
updateChart();
});
d3.select('#school')
.property( "value", school_var )
.on('change', function() {
var newData = d3.select(this).property('value');
school_var = newData;
updateChart();
});
d3.select('#subject')
.property( "value", subject_var )
.on('change', function() {
var newData = d3.select(this).property('value');
subject_var = newData;
updateChart();
});
function drawChart() {
//convert values to ints
ukschools.forEach(function(d) {
d.maths = Math.floor(+d.maths);
d.scie = Math.floor(+d.scie);
d.read = Math.floor(+d.read);
d.SCHOOLID = +d.SCHOOLID;
for (i = 0; i < attitudes_arr.length; i++){
thisstring = "d."+attitudes_arr[i][0]+";"
thisdatum = eval(thisstring);
thisdatum = Math.floor(+thisdatum);
}
for (i = 0; i < school_arr.length; i++){
thisstring = "d."+school_arr[i][0]+";"
thisdatum = eval(thisstring);
thisdatum = Math.floor(+thisdatum);
}
});
chartdata = makeChartData()
makeChart(0)
makeChart(1)
makeChart(2)
makeChart(3)
makeChart(4)
makeChart(5)
}
function makeChartData() {
thesechartsdata = []
// var subject_var = "math"
// var attitude_var = "ST88Q02"
thisdata = {"sagreetotal":0,"sagreenum":0,
"agreetotal":0,"agreenum":0,
"dagreetotal":0,"dagreenum":0,
"sdagreetotal":0,"sdagreenum":0}
for (i = 0; i<ukschools.length;i++) {
if (ukschools[i][attitude_var] == "Strongly agree") {
thisdata["sagreetotal"] = thisdata["sagreetotal"] + ukschools[i][subject_var];
thisdata["sagreenum"] = thisdata["sagreenum"] + 1;
}
else if (ukschools[i][attitude_var] == "Agree") {
thisdata["agreetotal"] = thisdata["agreetotal"] + ukschools[i][subject_var];
thisdata["agreenum"] = thisdata["agreenum"] + 1;
}
else if (ukschools[i][attitude_var] == "Disagree") {
thisdata["dagreetotal"] = thisdata["dagreetotal"] + ukschools[i][subject_var];
thisdata["dagreenum"] = thisdata["dagreenum"] + 1;
}
else if (ukschools[i][attitude_var] == "Strongly disagree") {
thisdata["sdagreetotal"] = thisdata["sdagreetotal"] + ukschools[i][subject_var];
thisdata["sdagreenum"] = thisdata["sdagreenum"] + 1;
}
}
thischartdata = getPercentAndScores(thisdata)
thesechartsdata.push(thischartdata)
thesecatagories = []
thisdata = {"sagreetotal":0,"sagreenum":0,
"agreetotal":0,"agreenum":0,
"dagreetotal":0,"dagreenum":0,
"sdagreetotal":0,"sdagreenum":0}
for (i = 0; i<ukschools.length;i++) {
if (ukschools[i][school_var] == "0" || ukschools[i][school_var] == "1.0") {
thisdata["sagreetotal"] = thisdata["sagreetotal"] + ukschools[i][subject_var];
thisdata["sagreenum"] = thisdata["sagreenum"] + 1;
}
else if (ukschools[i][school_var] == "1" || ukschools[i][school_var] == "2.0") {
thisdata["agreetotal"] = thisdata["agreetotal"] + ukschools[i][subject_var];
thisdata["agreenum"] = thisdata["agreenum"] + 1;
}
else if (ukschools[i][school_var] == "2"|| ukschools[i][school_var] == "3.0") {
thisdata["dagreetotal"] = thisdata["dagreetotal"] + ukschools[i][subject_var];
thisdata["dagreenum"] = thisdata["dagreenum"] + 1;
}
else if (ukschools[i][school_var] == "3" || ukschools[i][school_var] == "4.0") {
thisdata["sdagreetotal"] = thisdata["sdagreetotal"] + ukschools[i][subject_var];
thisdata["sdagreenum"] = thisdata["sdagreenum"] + 1;
}
}
thischartdata = getPercentAndScores(thisdata)
thesechartsdata.push(thischartdata)
for (i = 0; i<=3; i++) {
thisdata = {"sagreetotal":0,"sagreenum":0,
"agreetotal":0,"agreenum":0,
"dagreetotal":0,"dagreenum":0,
"sdagreetotal":0,"sdagreenum":0}
function checkschool (d) {
thisschool = false;
thisvalue = ukschools[d][school_var]
if (thisvalue == i.toString() || thisvalue == (i+1).toString() + ".0") {
thisschool = true;
} else if (thisvalue != 2) {
}
return thisschool;
}
for (j = 0; j<ukschools.length;j++) {
if (checkschool(j) && ukschools[j][attitude_var] == "Strongly agree") {
thisdata["sagreetotal"] = thisdata["sagreetotal"] + ukschools[j][subject_var];
thisdata["sagreenum"] = thisdata["sagreenum"] + 1;
}
else if (checkschool(j) && ukschools[j][attitude_var] == "Agree") {
thisdata["agreetotal"] = thisdata["agreetotal"] + ukschools[j][subject_var];
thisdata["agreenum"] = thisdata["agreenum"] + 1;
}
else if (checkschool(j) && ukschools[j][attitude_var] == "Disagree") {
thisdata["dagreetotal"] = thisdata["dagreetotal"] + ukschools[j][subject_var];
thisdata["dagreenum"] = thisdata["dagreenum"] + 1;
}
else if (checkschool(j) && ukschools[j][attitude_var] == "Strongly disagree") {
thisdata["sdagreetotal"] = thisdata["sdagreetotal"] + ukschools[j][subject_var];
thisdata["sdagreenum"] = thisdata["sdagreenum"] + 1;
}
}
thischartdata = getPercentAndScores(thisdata)
thesechartsdata.push(thischartdata)
}
return thesechartsdata
}
// get perecentages and scores from results dictionary
function getPercentAndScores(data) {
totalnum = data["sagreenum"]+data["agreenum"]+data["dagreenum"]+data["sdagreenum"]
sapercent = (data["sagreenum"]/totalnum)*100;
apercent = (data["agreenum"]/totalnum)*100;
dpercent = (data["dagreenum"]/totalnum)*100;
sdpercent = (data["sdagreenum"]/totalnum)*100;
saave = 0;
aave = 0;
dave = 0;
sdave = 0;
if (data["sagreenum"]>0) {
saave = (data["sagreetotal"]/data["sagreenum"])
}
if (data["agreenum"]>0) {
aave = (data["agreetotal"]/data["agreenum"])
}
if (data["dagreenum"]>0) {
dave = (data["dagreetotal"]/data["dagreenum"])
}
if (data["sdagreenum"]>0) {
sdave = (data["sdagreetotal"]/data["sdagreenum"])
}
thisPercentAndScores = [{startpercent:0,percent:sapercent,score:saave},
{startpercent:sapercent,percent:apercent+sapercent,score:aave},
{startpercent:apercent+sapercent,percent:apercent+sapercent+dpercent,score:dave},
{startpercent:dpercent+apercent+sapercent,percent:100,score:sdave}]
return thisPercentAndScores;
}
function isPercentileQ () {
if (school_var == "schoolmath" ||school_var == "schoolread" || school_var == "schoolscie") {
return true;
}
return false;
}
function getTicks (datanum) {
if (datanum == 1) {
return 0;
}
return 10;
}
function getXText (datanum) {
if (datanum == 1 && isPercentileQ()) {
if (school_var == "schoolmath" ) {
return "Average School Math scores for percentile bins";
}
else if (school_var == "schoolread" ) {
return "Average School Reading scores for percentile bins";
}
else {
return "Average School Science scores for percentile bins";
}
}
return "Percentage of school answers";
}
function getYText () {
if (subject_var == "maths") {
return "Average score in Maths";
}
else if (subject_var == "read") {
return "Average score in Reading";
}
else {
return "Average score in Science";
}
}
function getTitleText(chartnum) {
if (chartnum == 0) {
return getAttitudeString();
}
else if (chartnum == 1) {
return getSchoolString();
}
else if (chartnum < 6) {
return get_school_domain(chartnum - 2)
}
return ""
}
function makeChart(datanum) {
// margin = {top: 20, right: 20, bottom: 30, left: 40};
if (datanum == 0 || datanum == 1) {
// width = 340 - margin.left - margin.right;
// height = 310 - margin.top - margin.bottom;
margin = {top: 40, right: 20, bottom: 30, left: 40};
width = 340 - margin.left - margin.right;
height = 310 - margin.top - margin.bottom;
}
else {
// width = 260 - margin.left - margin.right;
// height = 180 - margin.top - margin.bottom;
margin = {top: 30, right: 60, bottom: 30, left: 80};
width = 340 - margin.left - margin.right;
height = 180 - margin.top - margin.bottom;
}
// width = 340 - margin.left - margin.right;
// height = 310 - margin.top - margin.bottom;
x = d3.scale.linear()
.range([0, width]);
y = d3.scale.linear()
.range([height,0]);
x.domain([0,100]);
y.domain([300,700]);
var svg = d3.select(divs_arr[datanum]).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 + ")");
var xAxis = d3.svg.axis()
.scale(x)
.orient("bottom")
.ticks(getTicks(datanum));
svg.append("g")
.attr("class", "x axis")
.attr("transform", "translate(0," + height + ")")
.call(xAxis)
.append("text")
.attr("class", "x_label")
.attr("x", width)
.attr("y", 25)
.style("text-anchor", "end")
.text(getXText(datanum));
var yAxis = d3.svg.axis()
.scale(y)
.orient("left");
svg.append("g")
.attr("class", "y axis")
.call(yAxis)
.append("text")
.attr("class", "y_label")
.attr("transform", "rotate(-90)")
.attr("y", -40)
.attr("dy", ".71em")
.style("text-anchor", "end")
.text(getYText());
svg.selectAll(".bar")
.data(chartdata[datanum])
.enter()
.append("rect")
.attr("class","bar")
.attr("x",function(d,i) {return x(d.startpercent);})
.attr("y",function(d) {return height-(height-y(d.score))})
.attr("width",function(d) {return x(d.percent-d.startpercent);})
.attr("height",function(d,i){
return height - y(d.score);})
.style("fill", function(d,i) {
if (datanum == 1) {
return schoolcolor(i)}
else {
return color(i)
}
});
function get_font_size() {
if (datanum < 2) {
return "20px"
}
return "8px";
}
svg.append("text")
.attr("x", (width / 2))
.attr("y", 0 - (margin.top/2))
.attr("class","main_title")
.attr("text-anchor", "middle")
.style("font-size",get_font_size())
.text(main_titles[datanum]);
svg.append("text")
.attr("x", (width / 2))
.attr("y", 0 - (margin.top/5))
.attr("class","title")
.attr("text-anchor", "middle")
.style("text-decoration", "underline")
.text(getTitleText(datanum));
if (datanum != 0 && datanum != 1) {
svg.append("rect")
.attr("x",(width - 20))
.attr("y", 0 - (margin.top - 10))
.attr("class","school_legend")
.attr("width", 20)
.attr("height", 20)
.style("fill", function () {
return schoolcolor(datanum - 2)
});
}
if (datanum == 0 || datanum == 1) {
var legend = svg.selectAll(".legend")
.data(color.domain())
.enter().append("g")
.attr("class", "legend")
.attr("transform", function(d, i) { return "translate(0," + i * 20 + ")"; })
legend.append("rect")
.attr("x", width - 18)
.attr("width", 18)
.attr("height", 18)
.style("fill", function (d) {
if (datanum == 0) {
return color(d)
}
else
{
return schoolcolor(d);
}
});
legend.append("text")
.attr("class","text")
.attr("x", width - 24)
.attr("y", 9)
.attr("dy", ".35em")
.style("text-anchor", "end")
.text(function(d) {
if (datanum == 0) {
return attitudes_domain[d];
}
else
{
return get_school_domain(d)
}
});
}
svgs[datanum] = svg
xAxiss[datanum] = xAxis
yAxiss[datanum] = yAxis
if (datanum == 0 || datanum == 1) {
legends[datanum] = legend
}
};
function updateChart() {
for (k = 0; k< svgs.length; k++) {
updateChartNum(k)
}
// updateChartNum(0)
// updateChartNum(1)
}
function updateChartNum(chartnum) {
if (chartnum == 0 || chartnum == 1) {
// width = 340 - margin.left - margin.right;
// height = 310 - margin.top - margin.bottom;
margin = {top: 40, right: 20, bottom: 30, left: 40};
width = 340 - margin.left - margin.right;
height = 310 - margin.top - margin.bottom;
}
else {
// width = 260 - margin.left - margin.right;
// height = 180 - margin.top - margin.bottom;
margin = {top: 30, right: 60, bottom: 30, left: 80};
width = 340 - margin.left - margin.right;
height = 180 - margin.top - margin.bottom;
}
// margin = {top: 20, right: 20, bottom: 30, left: 40};
// if (chartnum == 0 || chartnum == 1) {
// width = 340 - margin.left - margin.right;
// height = 310 - margin.top - margin.bottom;
// }
// else {
// width = 260 - margin.left - margin.right;
// height = 180 - margin.top - margin.bottom;
// }
x = d3.scale.linear()
.range([0, width]);
y = d3.scale.linear()
.range([height,0]);
x.domain([0,100]);
y.domain([300,700]);
chartdata = makeChartData()
svg = svgs[chartnum]
xAxis = xAxiss[chartnum]
yAxis = yAxiss[chartnum]
svg.selectAll(".bar")
.data(chartdata[chartnum])
.transition()
.duration(100)
.attr("x",function(d,i) {return x(d.startpercent);})
.attr("y",function(d) {return height-(height-y(d.score))})
.attr("width",function(d) {return x(d.percent-d.startpercent);})
.attr("height",function(d,i){
return height - y(d.score);});
if (chartnum == 1) {
legend = legends[chartnum]
legend.selectAll(".text")
.transition()
.text(function(d) {
return get_school_domain(d);
})
}
svg.selectAll(".y_label")
.text(getYText())
svg.selectAll(".x_label")
.text(getXText(chartnum))
svg.selectAll(".title")
.text(getTitleText(chartnum))
}
function get_school_domain(d) {
if (isPercentileQ()) {
return percentile_domain[d];
} else {
return school_domain[d];
}
}
</script>
</body>
</html>