-
Notifications
You must be signed in to change notification settings - Fork 5
/
index.html
191 lines (146 loc) · 5.38 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
<!DOCTYPE html>
<!-- saved from url=(0033)http://bost.ocks.org/mike/sankey/ -->
<html><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"><meta charset="utf-8">
<title>Oakland City Budget (Adopted 2012-2013)</title>
<style>
@import url(./css/style.css?20120521);
#chart {
height: 600px;
}
#hover_description{
height: 26px;
}
.node rect {
fill-opacity: .9;
shape-rendering: crispEdges;
}
.node text {
pointer-events: none;
text-shadow: 0 1px 0 #fff;
font-size: 12px;
}
.link {
fill: none;
stroke: #000;
stroke-opacity: .2;
}
.link:hover {
stroke-opacity: .5;
}
#warning{
color: red;
}
</style>
</head><body>
<header>
</header>
<h3>Oakland City Budget<br>(Revenues and Expenditures as Adopted, FY 2012-2013)<div id="warning">Draft - Data requires validation (see notes at bottom)</div></h3>
<div id="hover_description">
</div>
<p id="chart">
</p>
<h4>Source: FY2011-2013 Adopted Policy Budget <a href="http://www2.oaklandnet.com/oakca1/groups/cityadministrator/documents/report/oak032748.pdf">http://www2.oaklandnet.com/oakca1/groups/cityadministrator/documents/report/oak032748.pdf</a></h4>
<h4>Notes:</h4><p>
<ol>
<li>This is intended as an illustrative prototype; the data should be reviewed and validated for accuracy.</li>
<li>All General Fund revenues and expenditures are shown, but only non-GF transfers exceeding $2 million (rough threshold) are currently shown.</li>
<li>I've tried to exclude revenue sources that are purely accounting records (e.g., equipment and facilities rental charges) but this needs some review by a content area expert.</li>
<li>Bond items are generally excluded because I've had some trouble interpreting revenues vs. expenditures.</li>
<li>Built using <a href="http://d3js.org/">D3.js</a> and the <a href="https://github.com/d3/d3-plugins/tree/master/sankey">Sankey D3 plugin</a>.</li>
</ol></p>
<p>
<h4>Copyright 2012, Dave Guarino. E-mail me feedback <a href="mailto:[email protected]">here</a>. Really!</h4>
</p>
<script src="./js/d3.v2.min.js"></script>
<script src="./js/sankey.js"></script>
<script src="./js/jquery-1.8.3.min.js"></script>
<script type="text/javascript">
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-36860625-1']);
_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>
var margin = {top: 1, right: 1, bottom: 6, left: 1},
width = 960 - margin.left - margin.right,
height = 600 - margin.top - margin.bottom;
var formatNumber = d3.format(",.0f"),
format = function(d) { return "$" + formatNumber(d); },
color = d3.scale.category20();
var svg = d3.select("#chart").append("svg")
.attr("width", width + margin.left + margin.right)
.attr("height", height + margin.top + margin.bottom)
.append("g")
.attr("transform", "translate(" + margin.left + "," + margin.top + ")");
var sankey = d3.sankey()
.nodeWidth(30)
.nodePadding(5)
.size([width, height]);
var path = sankey.link();
// Changed to budget
function do_with_budget(energy) {
sankey
.nodes(energy.nodes)
.links(energy.links)
.layout(32);
var link = svg.append("g").selectAll(".link")
.data(energy.links)
.enter().append("path")
.attr("class", "link")
.attr("d", path)
.style("stroke-width", function(d) { return Math.max(1, d.dy); })
.sort(function(a, b) { return b.dy - a.dy; })
.on("mouseover", function(d){$("#hover_description").append($("<span>" + d.source.name + " to " + d.target.name + ": " + format(d.value) + "</span>"));})
.on("mouseout", function(){$("#hover_description").find("span:last").remove();});;
link.append("title")
.text(function(d) { return d.source.name + " → " + d.target.name + "\n" + format(d.value); })
var node = svg.append("g").selectAll(".node")
.data(energy.nodes)
.enter().append("g")
.attr("class", "node")
.attr("transform", function(d) { return "translate(" + d.x + "," + d.y + ")"; })
node.append("rect")
.attr("height", function(d) { return d.dy; })
.attr("width", sankey.nodeWidth())
.style("fill", function(d) { return d.color = color(d.name.replace(/ .*/, "")); })
.style("stroke", function(d) { return d3.rgb(d.color).darker(2); })
.append("title")
.text(function(d) { return d.name + "\n" + format(d.value); });
node.append("text")
.attr("x", -6)
.attr("y", function(d) { return d.dy / 2; })
.attr("dy", ".35em")
.attr("text-anchor", "end")
.attr("transform", null)
.text(function(d) { return d.name; })
.filter(function(d) { return d.x < width / 2; })
.attr("x", 6 + sankey.nodeWidth())
.attr("text-anchor", "start");
};
//do_with_energy(energy);
//do_with_budget(budget);
$.get("./js/oakland.json", function(data){
do_with_budget(data);
});
//$("#chart svg g g g.node rect").hover(
/*
$('svg g').hover(
function () {
$("h3").append($("<span> " + "sd" + "</span>"));
},
function () {
$("h3").find("span:last").remove();
}
);
*/
/*
d3.json("energy.json", function (budget_data) {
console.log(budget_data);
do_with_budget(budget_data);
});
*/
</script></body></html>