-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.html
125 lines (92 loc) · 3.47 KB
/
index.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
<!DOCTYPE HTML>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
<title>Salt Lake County Budget Viz</title>
</head>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.0.0-beta1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/randomcolor/0.4.4/randomColor.min.js"></script>
<script src="http://cdn.leafletjs.com/leaflet/v0.7.7/leaflet.js"></script>
<script src="//d3js.org/d3.v3.min.js"></script>
<link rel="stylesheet" type="text/css" href="https://fonts.googleapis.com/css?family=Open+Sans:400,600">
<link rel="stylesheet" href="http://cdn.leafletjs.com/leaflet/v0.7.7/leaflet.css" />
<link rel="stylesheet" type="text/css" href="sequence.css"/>
<body>
<div id="mapid"></div>
<div id="main">
<div id="sequence"></div>
<div id="chart">
<div id="explanation" style="visibility: hidden;">
<span id="percentage"></span><br/>
of the total budget is dedicated towards this expense
</div>
</div>
</div>
<div id="sidebar">
<div id="title">
<small>Salt Lake County</small>
Budget Explorer
</div>
<div id="legend"></div>
</div>
</body>
<script type="text/javascript">
// global
var colors = {}
$.get("budget.json")
.fail(function (e) {
console.log(e);
})
.done(function (budget) {
var hues = ["goldenrod", "silver", "olive", "lime", "teal", "fuchsia", "yellow", "navy", "maroon", "pink", "aqua", "orange", "red", "green", "blue", "purple"];
var fundhues = {}
var csv = [];
// now need to convert to csv format, w/ each line as "account-account-account-account-account-account,22781"
for (var fund in budget) {
fundhues[clean(fund)] = randomColor({hue: hues.pop(), luminosity: "dark"});
colors[clean(fund)] = shadeColor(fundhues[clean(fund)], -15);
for (var acct in budget[fund].accts) {
colors[clean(acct)] = shadeColor(fundhues[clean(fund)], 5);
for (var spec in budget[fund].accts[acct].specifics) {
if (acct == spec) { spec += " (L2)"; }
colors[clean(spec)] = shadeColor(fundhues[clean(fund)], 25);
var tot = budget[fund].accts[acct].specifics[spec];
if (Number(tot) > 0 && !isNaN(Number(tot))) {
csv.push(clean(fund) + "-" + clean(acct) + "-" + clean(spec) + "," + String(tot));
}
};
};
};
console.log("DONE"); console.log(fundhues);
createD3(csv.join("\n"))
});
function clean (str) {
return str.trim().replace(/-/g, " ");
}
function shadeColor(color, percent) {
var R = parseInt(color.substring(1,3),16);
var G = parseInt(color.substring(3,5),16);
var B = parseInt(color.substring(5,7),16);
R = parseInt(R * (100 + percent) / 100);
G = parseInt(G * (100 + percent) / 100);
B = parseInt(B * (100 + percent) / 100);
R = (R<255)?R:255;
G = (G<255)?G:255;
B = (B<255)?B:255;
var RR = ((R.toString(16).length==1)?"0"+R.toString(16):R.toString(16));
var GG = ((G.toString(16).length==1)?"0"+G.toString(16):G.toString(16));
var BB = ((B.toString(16).length==1)?"0"+B.toString(16):B.toString(16));
return "#"+RR+GG+BB;
}
var layer = L.tileLayer('http://{s}.basemaps.cartocdn.com/light_nolabels/{z}/{x}/{y}.png', {attribution: ""});
var map = L.map("mapid", {
scrollWheelZoom: false,
zoomControl: false,
center: [40.7579159, -111.9521305],
zoom: 12
});
map.addLayer(layer);
</script>
<script type="text/javascript" src="sequence.js"></script>
</html>