-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathneat.js
250 lines (210 loc) · 6.51 KB
/
neat.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
/*
* neat.js
*
* Page control file.
* The master js for the NEAT App.
*
* @author Stephen Robinson
* @since: Mar 5, 2015
*/
var neat = neat || {};
//Keep track of the current graph type.
//graphType enum
neat.MAJORS = "Number of students declared per major.";
neat.PROFS = "Number of CS students compared to CS professors.";
//the display divs for the different data the app can display
neat.MAJORS_TAB_DIV = "majors_tab_div";
neat.PROFS_TAB_DIV = "profs_tab_div";
//the current graph type
neat.graphType = neat.MAJORS;
//Enum for the different classes
neat.FRESHMAN = 0;
neat.SOPHOMORE = 1;
neat.JUNIOR = 2;
neat.SENIOR = 3;
neat.CLASSES_COUNT = 4;
//Whether or not to display professor student data as a ratio.
neat.profs_ratio_display = true;
//Currently selected classes
neat.selectedClasses = [neat.FRESHMAN, neat.SOPHOMORE, neat.JUNIOR,
neat.SENIOR];
//The different class's names indexed.
neat.classes = ['Freshman', 'Sophomore', 'Junior', 'Senior'];
//Enum for the different majors
neat.EE = 0;
neat.CS = 1;
neat.ME = 2;
neat.CE = 3;
neat.MAJORS_COUNT = 4;
//Currently selected majors
neat.selectedMajors = [neat.EE, neat.CS, neat.ME, neat.CE];
//The different major's abbreviations indexed by the enum.
neat.majorsAbbr = ['EE', 'CS', 'ME', 'CE'];
//The different major's full names indexed by the enum.
neat.majors = ['Electrical Engineering',
'Computer Science',
'Mechanical Engineering',
'Civil Engineering'];
/*
* init
*
* initialize the NEAT app. Cache the data and make sure the DOM matches the
* app's internal state.
*
* @author Stephen Robinson
* @since: Mar 5, 2015
*/
neat.init = function() {
neat.updateChecks();
neat.hideClass('profs_display');
neat.cacheData(function(){
animation.stopSpinners();
neat.unhideClass('hide_until_init');
neat.createGraph();
});
}
/*
* updateChecks
*
* Update the check boxes shown on the html document to reflect the
* internal state of the NEAT app.
*
* @author Stephen Robinson
* @since: Mar 5, 2015
*/
neat.updateChecks = function() {
for (i = neat.MAJORS_COUNT - 1; i >= 0; --i) {
var selected = (neat.selectedMajors.indexOf(i) >= 0);
document.getElementById(neat.majorsAbbr[i]).checked = selected;
}
for (i = neat.CLASSES_COUNT - 1; i >= 0; --i) {
var selected = (neat.selectedClasses.indexOf(i) >= 0);
document.getElementById(neat.classes[i]).checked = selected;
}
if (neat.profs_ratio_display) {
document.getElementById("profs_ratio").checked = true;
} else {
document.getElementById("profs_raw").checked = true;
}
}
/*
* switchTabTo
*
* Perform a swich to change the type of data the NEAT app is displaying.
*
* @author Stephen Robinson
* @since: Mar 19, 2015
*/
neat.switchTabTo = function(graphType) {
if (graphType != neat.graphType) {
neat.graphType = graphType;
majorsTab = document.getElementById(neat.MAJORS_TAB_DIV);
profsTab = document.getElementById(neat.PROFS_TAB_DIV);
// Hide the graph for now
document.getElementById("google_graph_div").innerHTML = "";
// Change the tab design and display only the elements which are
// relevant to this tab.
if (graphType == neat.MAJORS) {
majorsTab.className = "tab";
profsTab.className = "tab non_selected_tab";
neat.hideClass('profs_display');
neat.unhideClass('majors_display');
} else {
majorsTab.className = "tab non_selected_tab";
profsTab.className = "tab";
neat.hideClass('majors_display');
neat.unhideClass('profs_display');
}
//OK, now we are ready for the new graph
neat.updateGraph();
}
}
/*
* hideClass
*
* All html elements with the specified class name are hidden.
*
* @author Stephen Robinson
* @since: Apr 16, 2015
*/
neat.hideClass = function(className) {
var hide_els = document.getElementsByClassName(className);
for (var i=0; i < hide_els.length; ++i) {
hide_els[i].style.visibility = "hidden";
hide_els[i].style.display = "none";
}
}
/*
* unhideClass
*
* All html elements with the specified class name are unhidden.
* The display style will be set to block.
*
* @author Stephen Robinson
* @since: Apr 16, 2015
*/
neat.unhideClass = function(className) {
var unhide_els = document.getElementsByClassName(className);
for (var i=0; i < unhide_els.length; ++i) {
unhide_els[i].style.visibility = "visible";
unhide_els[i].style.display = "block";
}
}
/*
* updateGraph
*
* The is the callback for whenever a checkbox/radio button is ticked or
* unticked. It will call update the state of the checked options and call
* neat.createGraph.
*
* @author Stephen Robinson
* @since: Mar 5, 2015
*/
neat.updateGraph = function() {
// Update the state of the NEAT app based on what checkboxes and radio
// buttons are now checked.
neat.selectedMajors = [];
for (majorNum = neat.MAJORS_COUNT - 1; majorNum >= 0; --majorNum) {
if (document.getElementById(neat.majorsAbbr[majorNum]).checked) {
neat.selectedMajors.push(majorNum);
}
}
neat.selectedClasses = [];
for (classNum = neat.CLASSES_COUNT - 1; classNum >= 0; --classNum) {
if (document.getElementById(neat.classes[classNum]).checked) {
neat.selectedClasses.push(classNum);
}
}
neat.profs_ratio_display = document.getElementById("profs_ratio").checked;
if (neat.selectedMajors.length > 0 || neat.graphType == neat.PROFS) {
if (neat.selectedClasses.length > 0) {
neat.hideClass("error_div");
neat.unhideClass("google_graph_div");
neat.createGraph();
} else {
document.getElementById("error_div").innerHTML =
"Please select classes to display.";
neat.unhideClass("error_div");
neat.hideClass("google_graph_div");
}
} else {
document.getElementById("error_div").innerHTML =
"Please select majors to display.";
neat.unhideClass("error_div");
neat.hideClass("google_graph_div");
}
}
/*
* namesController
*
* Allow angular to access class and major names
*
* @author Stephen Robinson
* @since: Mar 5, 2015
*/
neat.namesController = function ($scope, $timeout) {
$scope.classes = neat.classes;
$scope.majorsAbbr = neat.majorsAbbr;
$scope.majors = neat.majors;
$timeout(neat.init, 0);
}