-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathBurst.html
More file actions
525 lines (476 loc) · 19.2 KB
/
Burst.html
File metadata and controls
525 lines (476 loc) · 19.2 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
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
<!DOCTYPE html>
<html lang="en">
<meta charset="utf-8" name="viewport" content="width=device-width, initial-scale=1.0">
<head>
<link rel="icon" href="favicon-usaSpend.png" type="image/png" sizes="16x16">
<script src="https://d3js.org/d3.v3.min.js"></script>
<script src="http://d3js.org/queue.v1.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<link href="https://fonts.googleapis.com/css?family=Source+Sans+Pro" rel="stylesheet" type="text/css">
<title>Q2 FY17 YTD Contract Drilldown</title>
<style>
*{
font-family: 'Source Sans Pro', sans-serif;
}
circle {
fill: none;
stroke: black;
stroke-width: 2px;
pointer-events: all;
}
circle,
path {
cursor: pointer;
}
path {
stroke: #fff;
stroke-width:.4;
}
body{
background-color: #FFFFFF;
}
#circ{
position:absolute;
top: 660px;
margin-top: -18px;
width: 700px;
height: 15px;
background-color: inherit;
}
#sunburst {
float: right ;
position:fixed;
padding-right:20px;
padding-left:20px;
top: 0px;
left: 660px;
width: 700px;
height: 650px;
text-align: center;
background-color: inherit;
}
#panel {
position:relative;
top:30px;
float: left;
text-align:left;
padding-right:20px;
padding-left:40px;
width: 550px;
height: 400px;
background-color: inherit;
}
.title{
text-transform: capitalize;
/*font-variant: small-caps;*/
}
#panel h1{
font-size:3em;
font-style:inherit;
font-weight: lighter;
margin: 0;
padding: 0;
color:#0071BC;
}
#panel h2{
font-size:2.1em;
font-style:inherit;
font-weight: ultra-light;
margin: 0;
padding: 0;
color:#666666;
}
#panel h3{
font-size:1.5em;
margin: 0;
padding: 0;
text-transform: capitalize;
/*font-variant:small-caps;*/
color:#555555;
}
#panel h4{
margin-top: 10px;
margin-bottom: 0px;
font-size:1.5em;
text-transform: capitalize;
/*font-variant:small-caps;*/
font-style:inherit;
color:#555555;
}
#panel p{
font-style:inherit;
font-size:1.5em;
margin-top: -3px;
text-transform: capitalize;
/*font-variant:small-caps;*/
color:#555555;
}
#legend_colorKey {
position: fixed;
top: 560px;
left: 575px;
width: 200px;
height: 130px;
margin: 0;
padding: 0;
overflow: visible;
}
.legend_circleKeyLabel {
position: absolute;
border-top: solid 1px #DDD;
width: 70px;
}
#legend_colorKey ul {
margin: 0;
padding: 0;
}
#legend_colorKey p {
margin-bottom: 8px;
}
#legend_colorKey li{
background-image: none;
padding: 0;
margin: 0;
float: left;
display: block;
height: 100%;
}
#legend_sizeKey{
position: relative;
height: 100px;
width: 300px;
}
#legend_sizeKey, .legend_circleKeyLabel span {
font-size: 10px;
color: #999;
position: absolute;
display: block;
left: 45px;
top: -8px;
width: 90px;
z-index: 100;
}
#legend_scaleKey {
width: 225px;
height: 130px;
position: absolute;
}
.legend_scaleKeyCircle {
stroke-width:1;
stroke:#999;
stroke-dasharray:2 2;
fill:none;
}
table{
margin-top: -25px;
width:100%;
text-align: left;
}
.icon{
position:relative;
margin: 0px 0px 0px -25px;
}
.icon_svg{
position:relative;
height: 80px;
width: 80px;
margin:0px 50px 40px 0px;
}
.val{
font-size:1.3em;
color:#205493;
font-weight: bolder;
}
.name{
text-transform: capitalize;
/*font-variant:small-caps;*/
font-size:1.3em;
font-weight: lighter;
color:#6B7687;
}
img{
top: 33px;
position:absolute;
}
#tab{
margin-top: -20px;
margin-bottom: 25px;
}
#tab_2 > table > tbody > tr > td.val{
width:115px;
}
#obligation > table > tbody > tr > td{
font-size: 1.3em;
}
#psc > table > tbody > tr > td{
font-size: .85em;
}
#psc_panel{
margin: 25px 30px 0px 0px;
float:left;
position: relative;
height:150px;
width:150px;
}
#psc_panel > div > table > tbody > tr > td{
width:100px;
height:40px;
text-align: left;
}
#psc_panel > div > table{
height:15px;
}
#psc{
margin-top: 15px;
width:150px;
height: 25px;
text-align: center;
}
#obligation{
margin: 38px 0px 40px 0px;
width:150px;
height: 25px;
text-align: center;
}
.icon_x{
margin-top: -20px;
margin-bottom: 25px;
}
</style>
</head>
<body>
<div id="container" class="container-fluid">
<div id="sunburst">
<div id="circ"><h5><i>Click the Center Node to Return to a Higher Level of Abstraction</i></h5></div>
</div>
<div id="panel"></div>
<div id="legend_colorKey">
<div style="left:65px;top:14px;width:70px;" class="legend_circleKeyLabel"><span style="left:75px;">Contractor</span></div>
<div style="left:65px;top:25px;" class="legend_circleKeyLabel"><span style="left:75px;">Funding Subagency</span></div>
<div style="left:65px;top:36px;" class="legend_circleKeyLabel"><span style="left:75px;">Funding Agency</span></div>
<div style="left:65px;top:65px;" class="legend_circleKeyLabel"><span style="left:75px;">2017 Q2 Total Contracts</span></div>
<svg id="legend_scaleKey"></svg>
</div>
</div>
<script>
d3.select("#legend_scaleKey").append("circle")
.attr('r', 25)
.attr('class',"legend_scaleKeyCircle")
.attr('cx', 60)
.attr('cy', 65);
d3.select("#legend_scaleKey").append("circle")
.attr('r', 35)
.attr('class',"legend_scaleKeyCircle")
.attr('cx', 60)
.attr('cy', 65);
d3.select("#legend_scaleKey").append("circle")
.attr('r', 45)
.attr('class',"legend_scaleKeyCircle")
.attr('cx', 60)
.attr('cy', 65);
d3.select("#legend_scaleKey").append("circle")
.attr('r', 55)
.attr('class',"legend_scaleKeyCircle")
.attr('cx', 60)
.attr('cy', 65);
var width = 700,
height = 700,
radius = (Math.min(width, height) / 2) - 30; //change 2 to a larger number to make burst smaller
var formatNumber = d3.format("$,f");
var x = d3.scale.linear()
.range([0, 2 * Math.PI]);
var y = d3.scale.sqrt()
.range([0, radius]);
var color = [{"name":"Department of Health and Human Services","color":"#702550"},{"name":"Department of Veterans Affairs","color":"#553A50"},{"name":"National Aeronautics and Space Administration","color":"#4E4861"},{"name":"Department of Energy","color":"#3F566E"},{"name":"Department of Homeland Security","color":"#2C6473"},{"name":"Department of Defense","color":"#1D7170"},{"name":"Department of Commerce","color":"#277D67"},{"name":"Department of State","color":"#438659"},{"name":"Agency for International Development","color":"#648D4A"},{"name":"Department of Justice","color":"#88923E"},{"name":"General Services Administration","color":"#AE933C"},{"name":"Department of the Treasury","color":"#D39248"},{"name":"Department of Transportation","color":"#D7924A"},{"name":"Department of Agriculture","color":"#DA914C"},{"name":"Department of Education","color":"#DE914E"},{"name":"Department of Housing and Urban Development","color":"#E19151"},{"name":"Department of the Interior","color":"#E49153"},{"name":"Environmental Protection Agency","color":"#E89056"},{"name":"Department of Labor","color":"#EB9058"},{"name":"Office of Personnel Management","color":"#EE905B"},{"name":"Social Security Administration","color":"#F1905E"},{"name":"National Science Foundation","color":"#F48F61"},{"name":"Securities and Exchange Commission","color":"#F78F64"},{"name":"Nuclear Regulatory Commission","color":"#F78F64"},{"name":"Executive Office of the President","color":"#F78F64"},{"name":"National Archives and Records Administration","color":"#F78F64"},{"name":"Broadcasting Board of Governors","color":"#F78F64"},{"name":"The Judicial Branch","color":"#F78F64"},{"name":"Federal Communications Commission","color":"#F78F64"},{"name":"Consumer Financial Protection Bureau","color":"#F78F64"},{"name":"Railroad Retirement Board","color":"#F78F64"},{"name":"Federal Trade Commission","color":"#F78F64"},{"name":"Small Business Administration","color":"#F78F64"},{"name":"Commodity Futures Trading Commission","color":"#F78F64"},{"name":"Export-Import Bank of the United States","color":"#F78F64"},{"name":"Consumer Product Safety Commission","color":"#F78F64"},{"name":"Government Accountability Office","color":"#F78F64"},{"name":"Court Services and Offender Supervision Agency","color":"#F78F64"},{"name":"Equal Employment Opportunity Commission","color":"#F78F64"},{"name":"Corporation for National and Community Service","color":"#F78F64"},{"name":"Federal Election Commission","color":"#F78F64"},{"name":"Armed Forces Retirement Home","color":"#F78F64"},{"name":"National Labor Relations Board","color":"#F78F64"},{"name":"International Trade Commission","color":"#F78F64"},{"name":"Federal Mediation and Conciliation Service","color":"#F78F64"},{"name":"Merit Systems Protection Board","color":"#F78F64"},{"name":"Federal Mine Safety and Health Review Commission","color":"#F78F64"},{"name":"U.S. Postal Service","color":"#F78F64"},{"name":"National Transportation Safety Board","color":"#F78F64"},{"name":"Defense Nuclear Facilities Safety Board","color":"#F78F64"},{"name":"Institute of Museum and Library Services","color":"#F78F64"},{"name":"National Endowment for the Arts","color":"#F78F64"},{"name":"Denali Commission","color":"#F78F64"},{"name":"Election Assistance Commission","color":"#F78F64"},{"name":"The Council of the Inspectors General on Integrity and Efficiency","color":"#F78F64"},{"name":"Gulf Coast Ecosystem Restoration Council","color":"#F78F64"},{"name":"Morris K. Udall and Stewart L. Udall Foundation","color":"#F78F64"},{"name":"Federal Labor Relations Authority","color":"#F78F64"},{"name":"Access Board","color":"#F78F64"},{"name":"United States Chemical Safety Board","color":"#F78F64"},{"name":"Office of Special Counsel","color":"#F78F64"},{"name":"Office of Government Ethics","color":"#F78F64"},{"name":"Federal Maritime Commission","color":"#F78F64"},{"name":"National Mediation Board","color":"#F78F64"},{"name":"Library of Congress","color":"#F78F64"},{"name":"The Legislative Branch","color":"#F78F64"}];
var partition = d3.layout.partition()
.value(function(d) { return d.size; });
var arc = d3.svg.arc()
.startAngle(function(d) { return Math.max(0, Math.min(2 * Math.PI, x(d.x))); })
.endAngle(function(d) { return Math.max(0, Math.min(2 * Math.PI, x(d.x + d.dx))); })
.innerRadius(function(d) { return Math.max(0, y(d.y)); })
.outerRadius(function(d) { return Math.max(0, y(d.y + d.dy)); });
var svg = d3.select("#sunburst").append("svg")
.attr("width", width)
.attr("height", height)
.append("g")
.attr("transform", "translate(" + (width / 2) + "," + (height / 2-20) + ")");
d3.csv('awards_contracts.csv',function(error,newData){
d3.csv('PSC_by_Recip.csv',function(error,recip){
d3.json('Recip_Details.json',function(error,details){
d3.csv('others.csv',function(error,other){
console.log("Hierarchy: ",newData);
console.log("recip: ",recip);
console.log("details: ",details);
console.log("other: ",other);
var root = { name :"FY17 Q2 Contract Awards", children : [] },
levels = ["Agency","Subagency"];
newData.forEach(function(d){
// Keep this as a reference to the current level
var depthCursor = root.children;
// Go down one level at a time
levels.forEach(function( property, depth ){
// Look to see if a branch has already been created
var index;
depthCursor.forEach(function(child,i){
if ( d[property] == child.name ) index = i;
});
// Add a branch if it isn't there
if ( isNaN(index) ) {
depthCursor.push({ name : d[property], children : []});
index = depthCursor.length - 1;
}
// Now reference the new child array as we go deeper into the tree
depthCursor = depthCursor[index].children;
// This is a leaf, so add the last element to the specified branch
if ( depth === levels.length - 1 ) depthCursor.push({ name : d.Recipient, size : d.Obligation });
});
});
console.log("root:",root);
svg.selectAll("path")
.data(partition.nodes(root))
.enter().append("path")
.attr("d", arc)
.on("mouseover",update_legend)
.on("mouseout",remove_legend)
.style("fill", function(d) {
//console.log("d: ",d.name);
if (d.depth === 0){return "#FFFFFF";} //Root
else if (d.depth === 1) {for(i=0; i<color.length; i++){if(d.name===color[i].name){return color[i].color;}}} //Agency
else if (d.depth === 2) {for(i=0; i<color.length; i++){if(d.parent.name===color[i].name){return d3.rgb(color[i].color).darker(-.75);}}} //Subagency
else if (d.depth === 3) {for(i=0; i<color.length; i++){if(d.parent.parent.name===color[i].name){return d3.rgb(color[i].color).darker(-1.25);}}} //Contractors
})
.on("click", click)
.append("title")
.text(function(d) { return d.name + "\n" + formatNumber(d.value); });
//$('#panel').contents().filter(function(){
//return this.nodeType === 3;
//}).remove();
function click(d) {
svg.transition()
.duration(750)
.tween("scale", function() {
var xd = d3.interpolate(x.domain(), [d.x, d.x + d.dx]),
yd = d3.interpolate(y.domain(), [d.y, 1]),
yr = d3.interpolate(y.range(), [d.y ? 20 : 0, radius]);
return function(t) { x.domain(xd(t)); y.domain(yd(t)).range(yr(t)); };
})
.selectAll("path")
.attrTween("d", function(d) { return function() { return arc(d); }; });
}
var legend = d3.select("#panel");
function update_legend(d)
{
// Create central node panel --- Top 10 Agencies
if (d.depth === 0){
$("#panel").empty();
legend.append("div")
.attr("id","tab")
.attr("height",200)
.attr("width",500)
.html("<h1 class='panel_title'>"+d.name+"</h1>"+
"<h3 class='panel_desc'>"+formatNumber(d.value)+
"<br />"+"</h3>");
for(var k=0; k < 10; k++){
legend.append("div")
.attr("id","tab_2")
.attr("height",200)
.attr("width",500)
.style("margin-bottom","2px")
.html("<table class ='icon'>"
+"<tr>"+"<td class='val'>"+formatNumber(d.children[k].value)+"</td>"+
"<td class='name'>"+d.children[k].name+"</td>"+"</tr>"+"</table>");
}
}else if (d.depth === 3 && d.name != "Other"){
// Contractors
$("#panel").empty();
for(var i=0; i<details.length; i++){
if(d.name === details[i].name){
legend.html("<h2 class='title'>"+d.name.toLowerCase()+"</h2>"+
"<h1>"+formatNumber(d.value)+"</h1>"+
"<p>"+details[i].city.toLowerCase() + ', ' + details[i].state.toLowerCase() +'</p>'+
'<h3> has been awarded a net total of '+
formatNumber(details[i].size)+' in contracts in Q2 2017</h3>');
for(var q=0; q<recip.length; q++){
if( d.parent.name=== recip[q].Subagency && d.name === recip[q].Recipient){
var g = legend.append("div")
.attr("id","psc_panel")
.attr("height",200)
.attr("width",125)
.style("margin","[0,0,0,0]");
g.append("img")
.attr("src",function(){return "icons/"+recip[q].icon;})
.attr("class","icon_svg");
g.append("div")
.attr("id","psc")
.attr("height",10)
.attr("width",50)
.html("<table class ='icon_x'>"
+"<tr>"+"<td class='name'>"+recip[q].PSC+"</td>"+"</tr>"+"</table>");
g.append("div")
.attr("id","obligation")
.attr("height",10)
.attr("width",50)
.html("<table class ='icon_x'>"
+"<tr>"+"<td class='val'>"+formatNumber(recip[q].Obligation)+"</td>"+"</tr>"+"</table>");
}}
}}
}else if(d.depth === 3 && d.name == "Other"){
$("#panel").empty();
//Contractors < $1,000,000
legend.append("div")
.attr("id","tab")
.attr("height",200)
.attr("width",500)
.html("<h3>Other Contractors Supporting the </h3><h3>"+d.parent.name+"</h3><h3>with Contract Values Less Than $1,000,000</h3>"+
"<h4>These Contracts are Worth a Total Value of "+formatNumber(d.value)+"</h4>"+
"<h4>Top Contactors</h4>");
for(var l =0; l<other.length; l++){
if(d.parent.name===other[l].sub){
legend.append("div")
.attr("id","tab_2")
.attr("height",200)
.attr("width",500)
.style("margin-bottom","2px")
.html("<table class ='icon'>"
+"<tr>"+"<td class='val'>"+formatNumber(other[l].size)+"</td>"+
"<td class='name'>"+other[l].name+"</td>"+"</tr>"+"</table>");
}
}
}else{
// Agencies & Subagencies
$("#panel").empty();
legend.append("div")
.attr("id","tab")
.attr("height",200)
.attr("width",500)
.html("<h2 class='title'>"+d.name+"</h2><h1>"+formatNumber(d.value)+"</h1>"+"<h4>"+"Contractors</h4>");
if(d.children.length<=5){
var t=d.children.length;
}else{
var t=5;
}
for(var k=0; k < t; k++){
legend.append("div")
.attr("id","tab_2")
.attr("height",200)
.attr("width",500)
.style("margin-bottom","2px")
.html("<table class ='icon'>"
+"<tr>"+"<td class='val'>"+formatNumber(d.children[k].value)+"</td>"+
"<td class='name'>"+d.children[k].name+"</td>"+"</tr>"+"</table>");
}
legend.transition().duration(500).style("opacity","1");
}
}
function remove_legend(d){
legend.transition().duration(1000).style("opacity","1");
}
});
});
});
});
d3.select(self.frameElement).style("height", height + "px");
</script>
</body>
</html>