-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.js
81 lines (70 loc) · 3.66 KB
/
index.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
import { summary } from './template.js';
import { listViol } from './listViol.js';
import { selectors } from './menus.js';
import { uniqueMaps } from './uniqueMaps.js';
import { exportList } from './exportList.js';
import { bars } from './bars.js';
import { cali } from './cali-map.js';
import { barsHistory } from './viol-history.js';
fetch('data/violations.json')
.then(function(response) {
return response.json();
})
.then(function(incomingJSON) {
let myJson = incomingJSON;
let mapsObj = uniqueMaps(myJson);
document.querySelector('.summary').innerHTML = summary(myJson)
document.querySelector('.violating-systems').innerHTML = listViol(myJson)
document.querySelector('.selectors').innerHTML = selectors(mapsObj.systemMap, mapsObj.cityMap, mapsObj.countyMap, mapsObj.zipMap, mapsObj.analyteMap, mapsObj.senatorMap, mapsObj.assemblyMap);
cali();
barsHistory(myJson, '.chart-container.history');
bars(myJson, '.chart-container.analytes');
// setup selector listeners
let selects = document.querySelectorAll('.selectors select');
selects.forEach( (selectInput) => {
let summaryEl = document.querySelector('.summary');
let violatorsEl = document.querySelector('.violating-systems');
selectInput.addEventListener('change', function(event) {
let currentIndex = document.querySelector('select[name="'+this.name+'"]').selectedIndex;
let mapKey = document.querySelector('select[name="'+this.name+'"]').options[currentIndex].value;
if(mapKey == '') {
// if you changed a selector back to the default value, reset summary view to full state
document.querySelector('.summary').innerHTML = summary(myJson)
document.querySelector('.violating-systems').innerHTML = listViol(myJson)
document.querySelector('h1').innerHTML = 'California Drinking Water';
cali();
barsHistory(myJson, '.chart-container.history');
bars(myJson, '.chart-container.analytes');
} else {
summaryEl.innerHTML = summary(mapsObj[this.name+'Map'].get(mapKey))
violatorsEl.innerHTML = listViol(mapsObj[this.name+'Map'].get(mapKey));
if(this.name == 'senator') {
document.querySelector('h1').innerHTML = 'CA State Senate District '+mapKey+' Drinking Water';
} else if(this.name == 'assembly') {
document.querySelector('h1').innerHTML = 'CA State Assembly District '+mapKey+' Drinking Water';
// writeMapData(mapsObj[this.name+'Map'].get(mapKey));
} else {
document.querySelector('h1').innerHTML = mapKey+' Drinking Water';
}
cali();
barsHistory(mapsObj[this.name+'Map'].get(mapKey), '.chart-container.history');
bars(mapsObj[this.name+'Map'].get(mapKey), '.chart-container.analytes');
}
resetElements(this.name,currentIndex);
})
})
document.getElementById("export-list").addEventListener("click", function() {
exportList(document.querySelectorAll('.violating-systems span'), document.querySelectorAll('.violating-systems span.head').length);
})
});
function resetElements(currentName, currentIndex) {
// revert everything not touched back to default
document.querySelector('select[name="system"]').selectedIndex = 0;
document.querySelector('select[name="city"]').selectedIndex = 0;
document.querySelector('select[name="county"]').selectedIndex = 0;
document.querySelector('select[name="zip"]').selectedIndex = 0;
document.querySelector('select[name="analyte"]').selectedIndex = 0;
document.querySelector('select[name="senator"]').selectedIndex = 0;
document.querySelector('select[name="assembly"]').selectedIndex = 0;
document.querySelector('select[name="'+currentName+'"]').selectedIndex = currentIndex;
}