-
Notifications
You must be signed in to change notification settings - Fork 0
/
naep.js
184 lines (156 loc) · 4.59 KB
/
naep.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
//MCAS Vis
const data= d3.json('naep.json').then(data=> {
var margin = { top:100, right: 100, bottom: 50, left: 100 },
width = 600 - margin.left - margin.right,
height = 450 - margin.top - margin.bottom;
// append svg object to the body of the page
var container1 = d3
.select("#charts")
.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 + ")");
//Line Chart 1 (12th Grade) ---------------------------------------------
{
let parseDate = d3.timeParse("%Y")
data.forEach(function (d) {
d.year = parseDate(d.year);
});
// Add x-axis
var x1 = d3.scaleTime()
.domain(d3.extent(data,d=>d.year))
.rangeRound([0,width])
container1
.append("g")
.attr("transform", "translate(0," + height + ")")
.call(d3.axisBottom(x1))
.call((g) =>
g
.append("text")
.attr("x", width)
.attr("y", margin.bottom - 4)
.attr("fill", "black")
.attr("text-anchor", "end")
.attr('font-size','11px')
.attr('font-weight','bold')
.text('Year')
);
//Add Y axis
//var formatPercent = d3.format(".0%");
var y1 = d3.scaleLinear()
.domain([0,90])
.rangeRound([height,0])
//var axis = axisBottom(y1).tickFormat(format('~%'))
container1
.append("g")
.call(d3.axisLeft(y1))
.call((g) =>
g
.append("text")
.attr("x", -margin.left)
.attr("y", 10)
.attr("fill", "black")
.attr("text-anchor", "start")
.attr('font-size','11px')
.attr('font-weight','bold')
.text('% at or above Proficiency (12th Grade)')
.attr('y',-25)
.attr('x',-80)
);
// Add the White line
container1.append("path")
.datum(data)
.attr("fill", "none")
.attr("stroke", "#d4caa5")
.attr("stroke-width", 2)
.attr("d", d3.line()
// adds segments
.x(function(d) { return x1(d.year) })
.y(function(d) { return y1(d["White"]) })
)
// Annotation White
container1.append('text')
.attr('x', 410)
.attr('y',200)
.attr('font-size','13px')
.text("White")
// Add Asian line
container1.append("path")
.datum(data)
.attr("fill", "none")
.attr("stroke", "#f0c62e")
.attr("stroke-width", 2)
.attr("d", d3.line()
// adds segments
.x(function(d) { return x1(d.year) })
.y(function(d) { return y1(d["Asian"]) })
)
// Annotation Asian
container1.append('text')
.attr('x', 410)
.attr('y',125)
.attr('font-size','13px')
.text("Asian")
// Add Hispanic line
container1.append("path")
.datum(data)
.attr("fill", "none")
.attr("stroke", "#b02e07")
.attr("stroke-width", 2)
.attr("d", d3.line()
// adds segments
.x(function(d) { return x1(d.year) })
.y(function(d) { return y1(d["Hispanic/Latino"])})
)
// Annotation Hispanic
container1.append('text')
.attr('x', 410)
.attr('y',260)
.attr('font-size','13px')
.text("Hispanic/Latino")
// Add Black line
container1.append("path")
.datum(data)
.attr("fill", "none")
.attr("stroke", "#1f1a19")
.attr("stroke-width", 2)
.attr("d", d3.line()
// adds segments
.x(function(d) { return x1(d.year) })
.y(function(d) { return y1(d["Black"])})
)
// Annotation Black
container1.append('text')
.attr('x', 410)
.attr('y',280)
.attr('font-size','13px')
.text("Black")
// Add State Average line
container1.append("path")
.datum(data)
.attr("fill", "none")
.attr("stroke", "#97bdc9")
.attr("stroke-width", 2)
.attr("d", d3.line()
// adds segments
.x(function(d) { return x1(d.year) })
.y(function(d) { return y1(d["National Average"])})
)
// Annotation Black
container1.append('text')
.attr('x', 410)
.attr('y',220)
.attr('font-size','13px')
.text("National Average")
//Overall Title
d3.select("svg").append('text')
.attr('x',300)
.attr('y',20)
.attr('font-size','18px')
.attr('font-weight','bold')
.attr('text-anchor','middle')
.text("NAEP Math Scores By Demographic (Available years: 2005-2019)")
}
});
// ==================================================================================================================