forked from bengarvey/budget
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
638 lines (534 loc) · 23.3 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
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
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Mandel for Controller Bulldog Budget</title>
<script src="inc/d3.v2.js"></script>
<script src="inc/accounting.js"></script>
<script src="inc/jquery.js"></script>
<script src="inc/tt.js"></script>
<link rel="stylesheet" type="text/css" href="inc/tt.css">
<link rel="stylesheet" type="text/css" href="bootstrap/css/bootstrap-responsive.css">
<link rel="stylesheet" type="text/css" href="bootstrap/css/bootstrap.css">
<script src="inc/jquery.activity-indicator.js"></script>
<script src="bootstrap/js/bootstrap.js"></script>
<script src="bootstrap/js/bootstrap-transition.js"></script>
<script src="bootstrap/js/bootstrap-tooltip.js"></script>
<style>
@import url("inc/style.css");
.disclaimer {
color: #999;
font-size: 70%;
}
.c100 {
background-color: #B2C2D1;
}
.c200 {
background-color: #F76e4a;
}
.c300 {
background-color: #efdfbb;
}
.c400 {
color: #ddd;
background-color: #335d6b;
}
.c500 {
background-color: #7aBa7f;
}
.c700 {
color: #ddd;
background-color: #88898b;
}
.c800 {
background-color: #ff99cc;
}
.c900 {
background-color: #99ffcc;
}
.about {
color: #555;
font-size: 80%;
}
.navigate {
font-size: 100%;
margin-left: 3px;
}
.budgetinfo {
position: absolute;
top: 50px;
left: 800px;
background-color: #bce6fa;
font-size: 80%;
padding: 10px;
-moz-border-radius: 5px;
border-radius: 5px;
border: 1px solid #DDDDDD;
}
ul .nav .nav-pills {
margin-bottom: 0px;
}
#chart {
width: 960px;
height:500px;
}
text {
pointer-events: none;
}
.grandparent text {
font-weight: normal;
font-size: 150%;
color: #DDD;
}
#resultstable {
font-size: 80%;
}
rect {
fill: none;
stroke: #bce6fa;
}
rect.parent,
.grandparent rect {
stroke-width: 5px;
}
rect.parent:hover {
outline: 1px solid #883;
}
.grandparent rect {
fill: #bce6fa;
}
.children rect.parent,
.grandparent rect {
cursor: pointer;
}
rect.parent {
pointer-events: all;
}
.children:hover rect.child,
.grandparent:hover rect {
fill: #EEE;
}
</style>
<script>
// Detect for ie
var ie = ( function(){
var undef,
v = 3,
div = document.createElement('div'),
all = div.getElementsByTagName('i');
while (
div.innerHTML = '<!--[if gt IE ' + (++v) + ']><i></i><![endif]-->',
all[0]
);
return v > 4 ? v : undef;
}());
function init() {
// Alert users if they are using ie 8 or lower
if (ie < 9) {
alert("This site requires a modern web browser. Please install Google Chrome, Mozilla Firefox, Apple Safari, or Internet Explorer 9 or higher.");
}
var margin = {top: 30, right: 0, bottom: 0, left: 0},
width = 960,
height = 500 - margin.top - margin.bottom,
formatNumber = d3.format(",d"),
transitioning;
// We used to use this when using d3's standard color schemes
//var color = d3.scale.category20();
var color = function(id) {
c = {'100' : '#B2C2D1', '200' : '#F76e4a', '300' : '#efdfbb', '400' : '#335d6b', '500' : '#7aBa7f', '600' : '#5CADFF', '700' : '#88898b', '800' : '#FF99CC', '900' : '#99FFCC', '1000' : '#FF8F1F'};
rc = c[id];
// Give it a d3 color in case we missed something
if (rc == "") {
rc = d3.scale.category20();
}
return rc;
}
var x = d3.scale.linear()
.domain([0, width])
.range([0, width]);
var y = d3.scale.linear()
.domain([0, height])
.range([0, height]);
var treemap = d3.layout.treemap()
.children(function(d, depth) { return depth ? null : d.children; })
.sort(function(a, b) { return a.value - b.value; })
.ratio(height / width * 0.5 * (1 + Math.sqrt(5)))
.round(false);
var svg = d3.select("#chart").append("svg")
.attr("width", width + margin.left + margin.right)
.attr("height", height + margin.bottom + margin.top)
.style("margin-left", -margin.left + "px")
.style("margin.right", -margin.right + "px")
.append("g")
.attr("transform", "translate(" + margin.left + "," + margin.top + ")")
.style("shape-rendering", "crispEdges");
var grandparent = svg.append("g")
.attr("class", "grandparent");
grandparent.append("rect")
.attr("y", -margin.top)
.attr("width", width)
.attr("height", margin.top);
grandparent.append("text")
.attr("fill", "#777")
.style("letter-spacing", "+0.05em")
.attr("x", 6)
.attr("y", margin.top - 60)
.attr("dy", "0.5em");
// Initialize tooltips
$(document).ready(function () {
$("[rel=tooltip]").tooltip();
});
d3.json("data/all.json", function(root) {
initialize(root);
accumulate(root);
layout(root);
display(root);
function initialize(root) {
root.x = root.y = 0;
root.dx = width;
root.dy = height;
root.depth = 0;
}
// Aggregate the values for internal nodes. This is normally done by the
// treemap layout, but not here because of our custom implementation.
function accumulate(d) {
return d.children
? d.value = d.children.reduce(function(p, v) { return p + accumulate(v); }, 0)
: d.value;
}
// Compute the treemap layout recursively such that each group of siblings
// uses the same size (1x1) rather than the dimensions of the parent cell.
// This optimizes the layout for the current zoom state. Note that a wrapper
// object is created for the parent node for each group of siblings so that
// the parent's dimensions are not discarded as we recurse. Since each group
// of sibling was laid out in 1x1, we must rescale to fit using absolute
// coordinates. This lets us use a viewport to zoom.
function layout(d) {
if (d.children) {
treemap.nodes({children: d.children});
d.children.forEach(function(c) {
c.x = d.x + c.x * d.dx;
c.y = d.y + c.y * d.dy;
c.dx *= d.dx;
c.dy *= d.dy;
c.parent = d;
layout(c);
});
}
}
function display(d) {
grandparent
.datum(d.parent)
.on("click", transition)
.select("text")
.attr("dy", "1.5em")
.text(name(d) + " : " + accounting.formatMoney(d.value));
var g1 = svg.insert("g", ".grandparent")
.datum(d)
.attr("class", "depth");
var g = g1.selectAll("g")
.data(d.children)
.enter().append("g");
g.filter(function(d) { return d.children; })
.classed("children", true)
.on("click", transition);
g.selectAll(".child")
.data(function(d) { return d.children || [d]; })
.enter().append("rect")
.attr("class", "child")
.call(rect);
g.append("rect")
.attr("class", "parent")
.attr("data-placement", "top")
.attr("title", "Tooltip test")
.attr("rel", "tooltip")
.call(rect)
.append("title")
.text(function(d) { return formatNumber(d.value); });
g.append("text")
.attr("dy", ".75em")
.attr("fill", "#333")
.text(function(d) {
var w = (d.dx / d.parent.dx) * 960;
if (d.name.length*6.5 < ((d.dx / d.parent.dx) * 960) && ((d.dy / d.parent.dy) * 500) > 18 && (w > 100)) {
d.hiddendata = false;
return d.name;
}
else {
d.hiddendata = true;
return "";
}
})
.call(text);
g.append("text")
.attr("dy", "1.75em")
.attr("fill", "#333")
.text( function(d) {
if (accounting.formatMoney(d.value).length*6 > ((d.dx / d.parent.dx) * 960) || d.hiddendata) {
d.hiddendata = true;
return "";
}
else {
return accounting.formatMoney(d.value);
}
})
.call(text);
function transition(d) {
if (transitioning || !d) return;
transitioning = true;
var g2 = display(d),
t1 = g1.transition().duration(750),
t2 = g2.transition().duration(750);
// Update the domain only after entering new elements.
x.domain([d.x, d.x + d.dx]);
y.domain([d.y, d.y + d.dy]);
// Enable anti-aliasing during the transition.
svg.style("shape-rendering", null);
// Draw child nodes on top of parent nodes.
svg.selectAll(".depth").sort(function(a, b) { return a.depth - b.depth; });
// Fade-in entering text.
g2.selectAll("text").style("fill-opacity", 0);
// Transition to the new view.
t1.selectAll("text").call(text).style("fill-opacity", 0);
t2.selectAll("text").call(text).style("fill-opacity", 1);
t1.selectAll("rect").call(rect);
t2.selectAll("rect").call(rect);
// Remove the old node when the transition is finished.
t1.remove().each("end", function() {
svg.style("shape-rendering", "crispEdges");
transitioning = false;
});
}
return g;
}
function text(text) {
text.attr("x", function(d) { return x(d.x) + 6; })
.style("font-size", function(d) {
var size = "12px";
d.namedisplay = d.name;
return size;
})
.attr("y", function(d) { return y(d.y) + 6; });
}
function rect(rect) {
rect.attr("x", function(d) { return x(d.x); })
.attr("y", function(d) { return y(d.y); })
.attr("width", function(d) { tempwidth = x(d.x + d.dx) - x(d.x); return tempwidth > 0 ? tempwidth : 0; })
.attr("height", function(d) { return y(d.y + d.dy) - y(d.y); })
.style("fill", function(d) {
if (d.parent.parent != null) {
if (d.parent.parent.parent != null) {
return color(d.parent.name.substr(6,3));
}
else {
return color(d.name.substr(6, 3));
}
}
else {
return "none";
}
}
);
rect.attr("onclick", "javascript:getRecords(evt)");
rect.attr("onmouseover", "javascript:showInfo(evt)");
rect.attr("onmouseout", "javascript:hideInfo(evt)");
}
function name(d) {
return d.parent
? name(d.parent) + " : " + d.name
: "Home : " + d.name;
}
});
}
</script>
<script>
function showInfo(evt) {
evt.target.setAttributeNS(null, "opacity", 0.5);
evt.target.setAttributeNS(null, "fill", "#000000");
var data = evt.target.__data__;
var d = $('#budgetinfo');
tooltip.show(data.name + "<br>" + accounting.formatMoney(data.value));
}
function hideInfo(evt) {
tooltip.hide();
}
// Have we clicked down to see the detailed transactions? If so, get them
function getRecords(evt) {
n = evt.target.__data__;
p = n.parent;
g = p.parent;
// Check to make sure we'll get back something.
if(evt.target.__data__.children == undefined) {
updateResults(g.dept_id, p.sub_object_code, n.name,0);
}
}
// Update the search results with what we've clicked down to
function updateResults(dept, cat, desc, page) {
var html = "";
var khtml = "";
var first = true;
var search = $('#search').val();
var url = "";
// Replace any ampersands
desc = desc.replace(/&/g, '%26');
$('#working').activity();
if (dept == "") {
url = "jrequest.rb?search0=" + $('#search').val() + "&page=" + page;
}
else {
url = "jrequest.rb?dept=" + dept + "&cat=" + cat + "&desc=" + desc + "&page=" + page;
}
//alert(url);
// $('#debug').html(url);
if (page == 0) {
$('#resultstable').empty();
$('#resultstable').append('<tbody></tbody>');
}
// Update our results table with the new search results
$.ajax({
url: url,
dataType: 'json',
success:
function(data) {
$('#searchtitle').html("Search Results");
var counttext = "Found " + data.length + " results";
$('#more').empty();
if (data.length == 1) {
counttext = counttext.slice(0, -1);
}
else if (data.length > 500) {
counttext = "Found more than 500 results. Scroll down for more.";
$('#more').html("<input value='View 500 more results' type=button onclick='updateResults(\"" + dept + "\",\"" + cat + "\",\"" + desc + "\",\"" + (parseInt(page) + 1) + "\")'>");
}
$('#searchcount').html(counttext);
if (data == "") {
$('#resultstable').html("No results found");
}
else {
// In Ruby 1.8 the hashed aren't sorted, so we have to sort them here
var keys = Object.keys(data[0]);
var orderedKeys = new Array;
for(i in keys) {
orderedKeys[i] = keys[i];
}
orderedKeys.sort ();
keys = orderedKeys;
var rowhtml = "";
var khtml = "";
if (page == 0) {
for (k in keys) {
khtml += "<th>" + keys[k] + "</th>";
}
khtml = "<tr>" + khtml + "</tr>";
$('#resultstable tbody:first').append(khtml);
}
for (d in data) {
rowhtml = "";
for (k in keys) {
if (keys[k] == "Total Expenditures") {
rowhtml += "<td>" + accounting.formatMoney(data[d][keys[k]]) + "</td>";
}
else {
rowhtml += "<td>" + data[d][keys[k]] + "</td>";
}
}
// rowhtml = "<tr>" + rowhtml + "</tr>\n";
$('#resultstable').append( "<tr>" + rowhtml + "</tr>\n" );
}
//$('#resultstable').append(rowhtml);
}
$('#working').activity(false);
},
timeout: 1000*60*10,
error:
function(jqXHR, status, errorThrown){ //the status returned will be "timeout"
//do something
$('#working').activity(false);
$('#debug').html = "There was a problem retrieving the data.<br>Error: " + status + "<br>E: " + errorThrown + "<br>";
}
});
return false;
}
</script>
</head>
<body onload="javascript:init()">
<h1><a href="http://brettmandel.com"><img alt="Mandel for Controller" title="Mandel for Controller" src="images/bulldog_logo_blue.jpg"></a></h1>
<h1><a href="">Mandel for Controller Bulldog Budget</a></h1>
<ul class="nav nav-pills">
<li><a href="#aboutmodal" role="button" data-toggle="modal">About</a></li>
<li><a href="#helpmodal" role="button" data-toggle="modal">Help</a></li>
</ul>
<p id="chart"></p>
<form class="form-search" onsubmit="return(updateResults('','','', 0));" id="searchform" action="#" name="searchform">
<label for="search">Search for individual budget items</label><br>
<input type="text" placeholder="Search text" id="search" class="search-query">
<input type="button" class="btn" value="Submit" onclick="updateResults('','','',0)">
</form>
<h2 id="searchtitle"></h2>
<div id="searchcount"></div>
<div id="working"></div>
<div id="results">
<table class="table table-hover" id="resultstable">
<tbody></tbody>
</table>
</div>
<div id=more></div>
<div id=debug></div>
<div class="disclaimer">DISCLAIMER: The material on this site is made available as a public service. The data are to be used for reference purposes only. Data are provided by the City of Philadelphia through requests pursuant to the Right to Know Law. Although the data are believed to be accurate, The Committee to Elect Brett Mandel and Brett Mandel, along with their agents, consultants, contractors, and employees, provide this data AS IS without warranty of any kind, implied or expressed, as to the information being accurate or complete. With knowledge of the foregoing, each visitor to this website agrees to waive, release, and indemnify The Committee to Elect Brett Mandel and Brett Mandel, along with their agents, consultants, contractors and employees, from any and all claims, actions, or causes of action for damages or injury to persons or property arising from his/her use or inability to use this data. If you encounter an error, please email <a href="mailto:[email protected]">[email protected]</a> and describe the problem in detail.</div>
<div class="modal hide fade about" id="aboutmodal">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
<h3>About</h3>
</div>
<div class="modal-body">
<h4>Mandel for Controller Bulldog Budget</h4>
<p>The Mandel for Controller Bulldog Budget allows users, for the first time ever, to see how every single dollar of our money was spent from the Philadelphia city budget. You can dig for information like a dog digs for a bone, but before you do, a note on navigation.</p>
<p>The fiscal year 2012 covered by this site ran from July 1, 2011 to June 30, 2012</p>
<p>The Philadelphia budget is adopted by City Council each year with expenditures approved by agency and by "class" and classes refer to:<br>
<div class="c100">Class 100 - Salaries and fringe benefits</div>
<div class="c200">Class 200 - Contracts for the purchase of services and leases</div>
<div class="c300">Class 300 - Materials and supplies</div>
<div class="c400">Class 400 - Equipment</div>
<div class="c500">Class 500 - Contributions and indemnities (payments for compensation by the city)</div>
<div class="c600">Class 600 - Not used in this budget</div>
<div class="c700">Class 700 - Debt Service (payments for long-term loans/bonds)</div>
<div class="c800">Class 800 - Payments to other funds</div>
<div class="c900">Class 900 - Advances and miscellaneous payment</div>
</p>
<p>The city budget ordinance passed by City Council shows only how much money is allocated to each city agency and how that money is divided by class -- how much for personnel, how much for contracts, how much for supplies, and so on. But, with the <a href="http://brettmandel.com">Mandel for Controller</a> Bulldog Budget you can search for any agency, vendor, or type of expenditure or click through each agency to each class to each type of expenditure to see a list of the actual payments down to the last cent.</p>
<p>The Bulldog Budget was developed by Brett Mandel and Ben Garvey</p>
</div>
<div class="modal-footer">
<button class="btn" data-dismiss="modal" aria-hidden="true">Back</button>
</div>
</div>
<div class="modal hide fade help" id="helpmodal">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
<h3>Help</h3>
</div>
<div class="modal-body">
<h4>How to Use This Tool</h4>
<p>The budget data are presented in a clickable <a href="http://en.wikipedia.org/wiki/Treemapping">treemap</a>. The area of each box is set according to the magnitude of the expenditures in that category. Just click on the department or category to see greater and greater detail. Once you dive down to the lowest level, click again to bring up a search listing of all the individual expenditures that make up that box. Click the home bar to return to higher level views.</p>
<p>To search for specific expenditures, use the search tool to search across all types of budget items.</p>
<p>If you find any errors, please email <a href="mailto:[email protected]">Brett Mandel</a> so they can be corrected.</p>
<p>The Bulldog Budget supports most modern web browsers. You will experience problems using Internet Explorer 8 or less.</p>
</div>
<div class="modal-footer">
<button class="btn" data-dismiss="modal" aria-hidden="true">Back</button>
</div>
</div>
<a href="https://github.com/bengarvey/budget"><img style="position: absolute; top: 0; right: 0; border: 0;" src="https://s3.amazonaws.com/github/ribbons/forkme_right_red_aa0000.png" alt="Fork me on GitHub"></a>
<script type="text/javascript"> var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-7747442-2']);
_gaq.push(['_trackPageview']);
(function() {
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();
</script>
</script>
</script>
</body>
</html>