Repository navigation
Expand file tree
/
Copy pathdataLoading.js
More file actions
275 lines (256 loc) · 7.81 KB
/
Copy pathdataLoading.js
File metadata and controls
275 lines (256 loc) · 7.81 KB
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
// all tooltip shit comes from the free d3-tip.js file and this example
// http://bl.ocks.org/davegotz/bd54b56723c154d25eedde6504d30ad7
var myData;
var margin = {top: 10, right: 10, bottom: 30, left: 100};
var currentBranch;
/*
var svgWidth = 800 - margin.left - margin.right;
var svgHeight = 500 - margin.top - margin.bottom;
*/
var svgWidth = 800 - margin.left - margin.right;
var svgHeight = 500 - margin.top - margin.bottom;
//can define fader as a thing also.
var color = d3.scaleOrdinal(d3.schemeCategory10);
//
//I think the idea is to have a bunch of loadData methods - one for each JSON file. Then just wipe shit and call createTreeMap
//naming conventions - (Branch)_(Consulting or LinkedIn)_(Employer, Industry, SizeCompany, Function).json
//basically all the JSON files have a common namihg scheme as described above. The string will be generated based on what the user selects
//Right now its just a bunch of buttons, but later on it'll be based on where he clicks
var consultingTag = "Consult";
var civilianTag = "Civilian";
var employerTag = "Employer";
var industryTag = "Industry";
var functionTag = "Function";
var sizeCompanyTag = "sizeCompany";
var airForceTag = "AF";
var armyTag = "Army";
var navyTag = "Navy";
var marineCorpsTag = "MC";
var coastGuardTag = "CG";
var militaryTag = "M";
var academyFlag = false;
var colorByParent = false;
var categoryToColorBy = industryTag; //variable to hold what category the user wants to look at
var currCategoryTag; //variable to hold whichever flag is chosen
var preFolderString = "";
//called immediatley after data loading
function firstCall()
{
loadUSNavy();
}
//function to make the fileName of the JSON file based on what the user has specified
function makeFileName(branchTag, sourceTag, categoryTag, academyFlag)
{
colorByParent = false;
if(categoryTag == industryTag) {colorByParent = true;}
if(academyFlag)
{
return "US" + branchTag + "A" + "_" + sourceTag + "_" + categoryTag + ".json";
}
else
{
return "US" + branchTag + "_" + sourceTag + "_" + categoryTag + ".json";
}
}
//function to change the category tag to have what the user specifies be loaded.
function changeDisplayCategory()
{
if(document.getElementById('CiviliansBtn').checked)
{
if(document.getElementById('civFunctionBtn').checked)
{
categoryToColorBy = functionTag;
}
if(document.getElementById('civIndustryBtn').checked)
{
categoryToColorBy = industryTag;
}
if(document.getElementById('civSizeCompanyBtn').checked)
{
categoryToColorBy = sizeCompanyTag;
}
}
if(document.getElementById('ConsultantsBtn').checked)
{
if(document.getElementById('consEmplyerBtn').checked)
{
categoryToColorBy = employerTag;
}
if(document.getElementById('consIndustryBtn').checked)
{
categoryToColorBy = industryTag;
}
}
//document.getElementById("USNavyBtn").checked = true;
loadUSNavy();
}
//functions to change between civilians data and consultants data
function changeToCivilians()
{
academyFlag = true;
//document.getElementById("USNavyBtn").checked = true;
changeDisplayCategory();
loadUSNavy();
makeCivBar();
}
function changeToConsultants()
{
academyFlag = false;
// document.getElementById("USNavyBtn").checked = true;
changeDisplayCategory();
loadUSNavy();
makeConBar();
}
//Functions that load the data actual data. One of these is called on any change. They all look the same except different file names
function loadUSNavy()
{
removeTreeMap();
if(document.getElementById("CiviliansBtn").checked == true)
{
d3.json(preFolderString + "jsonFiles/" + makeFileName(navyTag, civilianTag, categoryToColorBy, academyFlag), function(data)
{
//console.log(makeFileName(navyTag, civilianTag, industryTag, academyFlag));
myData = data
//console.log(myData);
createTreeMap_Civilians();
});
}
else if(document.getElementById("ConsultantsBtn").checked == true)
{
d3.json(preFolderString + "jsonFiles/" + makeFileName(navyTag, consultingTag, categoryToColorBy, academyFlag), function(data)
{
myData = data
//console.log(myData);
createTreeMap_Consultants();
});
}
else
{
console.log("fuk");
}
}
function loadUSAirForce()
{
removeTreeMap();
if(document.getElementById("CiviliansBtn").checked == true)
{
d3.json(preFolderString + "jsonFiles/" + makeFileName(airForceTag, civilianTag, categoryToColorBy, academyFlag), function(data)
{
myData = data
//console.log(myData);
createTreeMap_Civilians();
});
}
else if(document.getElementById("ConsultantsBtn").checked == true)
{
d3.json(preFolderString + "jsonFiles/" + makeFileName(airForceTag, consultingTag, categoryToColorBy, academyFlag), function(data)
{
myData = data
//console.log(myData);
createTreeMap_Consultants();
});
}
else
{
console.log("fuk");
}
}
//maybe we shold lump the USMA and USArmy_Consultants into the same button
function loadUSArmy()
{
removeTreeMap();
if(document.getElementById("CiviliansBtn").checked == true)
{
d3.json(preFolderString + "jsonFiles/" + makeFileName(militaryTag, civilianTag, categoryToColorBy, academyFlag), function(data)
{
myData = data
//console.log(myData);
createTreeMap_Civilians();
});
}
else if(document.getElementById("ConsultantsBtn").checked == true)
{
d3.json(preFolderString + "jsonFiles/" + makeFileName(armyTag, consultingTag, categoryToColorBy, academyFlag), function(data)
{
myData = data
//console.log(myData);
createTreeMap_Consultants();
});
}
else
{
console.log("fuk");
}
}
function loadUSCoastGuard()
{
removeTreeMap();
if(document.getElementById("CiviliansBtn").checked == true)
{
d3.json(preFolderString + "jsonFiles/" + makeFileName(coastGuardTag, civilianTag, categoryToColorBy, academyFlag), function(data)
{
myData = data
//console.log(myData);
createTreeMap_Civilians();
});
}
else if(document.getElementById("ConsultantsBtn").checked == true)
{
d3.json(preFolderString + "jsonFiles/" + makeFileName(coastGuardTag, consultingTag, categoryToColorBy, academyFlag), function(data)
{
myData = data
//console.log(myData);
createTreeMap_Consultants();
});
}
else
{
console.log("fuk");
}
}
//We should get rid of the USMC data altogether. Its minimal.
//I've taken out the option to select USMC but left this in just to have it around
function loadUSMarineCorps()
{
removeTreeMap();
if(document.getElementById("CiviliansBtn").checked == true)
{
//theres only 4 things here
loadNoData();
}
else if(document.getElementById("ConsultantsBtn").checked == true)
{
loadNoData();
/*
d3.json(preFolderString + "jsonFiles/" + makeFileName(marineCorpsTag, consultingTag, industryTag, academyFlag), function(data)
{
myData = data
console.log(makeFileName(marineCorpsTag, consultingTag, industryTag, academyFlag));
console.log(myData);
createTreeMap_Consultants();
});
*/
}
else
{
console.log("fuk");
}
}
//
function loadNoData()
{
//for some reason this doesnt work all the time. but we shouldnt ever need to use it
removeTreeMap()
d3.json(preFolderString + "jsonFiles/noData.json", function(data)
{
myData = data
//console.log(myData);
createTreeMap_Consultants();
});
}
//Function to remove the treemap and tooltips for whenever we change around the stuff
function removeTreeMap() {
d3.select("#the_treeMap").remove();
d3.select("#the_toolTip").remove();
}
window.onload = firstCall();