forked from danxmoran/box-and-whiskers
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
722 lines (664 loc) · 27.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
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
<!DOCTYPE html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width,initial-scale=1">
<title>DS4200 Final Project</title>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet">
<link href="style.css" rel="stylesheet">
</head>
<body data-spy="scroll" data-target="#nav">
<nav class="navbar navbar-default navbar-fixed-top" id="navbar">
<div class="container">
<div class="navbar-header">
<button type="button" class="navbar-toggle collapsed"
data-toggle="collapse" data-target="#nav"
aria-expanded="false" aria-controls="navbar">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<span class="navbar-brand" href="#">DS4200 Final Project</span>
</div>
<div id="nav" class="navbar-collapse collapse">
<ul class="nav navbar-nav" role="tablist">
<li>
<a href="#final-viz">Visualizations</a>
</li>
<li>
<a href="#motivation">Motivation</a>
</li>
<li>
<a href="#task-analysis">Task Analysis</a>
</li>
<li>
<a href="#data">Data</a>
</li>
<li>
<a href="#design-process">Design Process</a>
</li>
<li>
<a href="#analysis">Data Analysis</a>
</li>
<li>
<a href="#conclusion">Conclusion</a>
</li>
</ul>
</div>
</div>
</nav>
<div id="main-content" class="container">
<div class="row">
<div class="col-md-12">
<a class="anchor" id="final-viz"></a><h1>Visualizations</h1>
<div class="row">
<div class="col-md-6">
<h3>Service-Learning Partner Locations, 2013-2016</h3>
<h4 id="map-subtitle"></h4>
<svg id="map">
<rect class="background"></rect>
<g class="foreground">
<g class="tooltip-anchor"></g>
<g class="map-layer"></g>
<g class="legend" transform="translate(250,500)">
<linearGradient id="map-gradient">
<stop offset="0%"></stop>
<stop offset="100%"></stop>
</linearGradient>
<text class="title" x="0" y="10">Organization Count:</text>
<rect x="0" y="15" width="200" height="20" fill="url(#map-gradient)"></rect>
<text class="tick" x="0" y="50" text-anchor="middle"></text>
<text class="tick" x="200" y="50" text-anchor="middle"></text>
</g>
</g>
</svg>
</div>
<div class="col-md-6">
<h3>Service-Learning Student Roles, 2013-2016</h3>
<h4 id="bubbles-subtitle"></h4>
<svg id="bubbles">
<rect class="background"></rect>
<g class="foreground"></g>
</svg>
</div>
</div>
<div class="row">
<div class="col-md-12">
<p>
These visualizations were created during a Service-Learning project for the
<a href="https://www.northeastern.edu/communityservice/">Northeastern University Center of Community Service</a>,
as part of the course DS4200 Information Presentation and Visualization.
Read on below for more information about the process of the project.
</p>
</div>
</div>
</div>
</div>
<div class="row">
<div class="col-md-12">
<a class="anchor" id="motivation"></a><h1>Motivation</h1>
<p>
The NU Center of Community Service (CCS) is a department within Northeastern's
division of City and Community Affairs. CCS runs many programs, one of
which is Service-Learning (S-L). S-L is a form of experiential learning
for students and a teaching tool for faculty that integrates academics
and service to meet classroom and community goals. S-L projects can involve
anything from technical support to meal preparation to tutoring at after-school
programs. Ultimately, the S-L team aims to enrich the academic experience of,
and inspire lifelong community engagement by, NU students, while strenghtening
the University's local and global communities.
</p>
<p>
CCS has collected data on its S-L courses for many years, but has never
undertaken an effort to analyze or visualize their stockpile of information.
Naturally, the S-L staff would prefer to know of any interesting patterns
in their course offerings and community partnerships.
</p>
</div>
</div>
<div class="row">
<div class="col-md-12">
<a class="anchor" id="task-analysis"></a><h1>Task Analysis</h1>
<p>
We began our project by interviewing the directors of the S-L program
at CCS to idenfify the team's most pressing needs. Through our conversation,
it became obvious that the S-L team needed to a quick, manageable way
to find data about each partner organization and service learning opportunity,
as well as a way to analyze where S-L has the most room to grow. They
also had a desire to craft a bigger story from their data for external
audiences.
</p>
<p>
After the interview, we decided that while the S-L team was most in need
of a proper data-management solution, building such a tool would likely
be beyond the scope of our course. Instead, we set out to visualize the
distribution of S-L partner organizations across Boston's neighborhoods
and the breakdown of services provided by students in S-L courses. We
hoped that these visualizations could help the S-L team identify areas
for growth, as well as provide an attractive display others curious about
the program.
</p>
</div>
</div>
<div class="row">
<div class="col-md-12">
<a class="anchor" id="data"></a><h1>Data</h1>
<p>
Following our initial interview, the S-L team at CCS provided us with
information for around 200 S-L partner organizations and 4000 student
service records, covering the semesters from Fall 2013 to Fall 2016.
Organizations were listed once in the data if they had offered a S-L
project during any semester in the covered time range. Student records
were listed for every S-L class-per-semester a given student participated in.
</p>
</div>
</div>
<div class="row">
<div class="col-md-12">
<a class="anchor" id="design-process"></a><h1>Design Process</h1>
<p>
Based upon our task analysis and the provided data, we sketched out nine
potential visualizations.
</p>
<div id="sketch-carousel" class="carousel slide" data-ride="carousel">
<ol class="carousel-indicators">
<li data-target="#sketch-carousel" data-slide-to="0" class="active"></li>
<li data-target="#sketch-carousel" data-slide-to="1"></li>
<li data-target="#sketch-carousel" data-slide-to="2"></li>
<li data-target="#sketch-carousel" data-slide-to="3"></li>
<li data-target="#sketch-carousel" data-slide-to="4"></li>
<li data-target="#sketch-carousel" data-slide-to="5"></li>
<li data-target="#sketch-carousel" data-slide-to="6"></li>
<li data-target="#sketch-carousel" data-slide-to="7"></li>
<li data-target="#sketch-carousel" data-slide-to="8"></li>
</ol>
<div class="carousel-inner" role="listbox">
<div class="item active">
<img src="img/1.jpg">
</div>
<div class="item">
<img src="img/2.jpg">
</div>
<div class="item">
<img src="img/3.jpg">
</div>
<div class="item">
<img src="img/4.jpg">
</div>
<div class="item">
<img src="img/5.jpg">
</div>
<div class="item">
<img src="img/6.jpg">
</div>
<div class="item">
<img src="img/7.jpg">
</div>
<div class="item">
<img src="img/8.jpg">
</div>
<div class="item">
<img src="img/9.jpg">
</div>
</div>
<a class="left carousel-control" href="#sketch-carousel" role="button" data-slide="prev">
<span class="glyphicon glyphicon-chevron-left" aria-hidden="true"></span>
<span class="sr-only">Previous</span>
</a>
<a class="right carousel-control" href="#sketch-carousel" role="button" data-slide="next">
<span class="glyphicon glyphicon-chevron-right" aria-hidden="true"></span>
<span class="sr-only">Next</span>
</a>
</div>
<p>
After laying out our ideas, we identified three favorites to follow up on.
First, we wanted to build an interactive map to show the spread of
service learning sites. Next, we wanted to include a bubble chart is to
display the breakdown of service learning roles held by students. Lastly,
we wanted to to include a search bar to allow users to browse through the
displayed data.
</p>
<p>
In our final visualization, we merged the interactive map and bubble
chart ideas. The search system was tabled, since building it properly
would have required more work than could be fit into our semester.
</p>
</div>
</div>
<div class="row">
<div class="col-md-12">
<a class="anchor" id="analysis"></a><h1>Data Analysis</h1>
<p>
After creating our visualization, we discovered a couple of interesting
insights. The majority of S-L partners are located in the Roxbury, Fenway,
and Downtown neighborhoods. Fenway might be misleading, however, because
the majority of partners there lie on or near Northeastern's campus.
There are surprisingly few S-L partners in Mission Hill, and more than
we expected in Jamaica Plain.
</p>
<p>
Within the bubble chart, the three largest categories of service provided
by students overall are "Tutor", "Activity Assistant", and "Consultant".
These three categories remain large when focused on any of the neighborhoods
with a significant number of S-L partner organizations, but their relative
proportions shift. For example, in Fenway there are far more Consultants
than either Activity Assistants or Tutors, while in Roxbury the opposite
is true. Jamaica plain has relatively few Tutors. Lastly, Downtown has
utilized few Activity Assistants.
</p>
</div>
</div>
<div class="row">
<div class="col-md-12">
<a class="anchor" id="conclusion"></a><h1>Conclusion</h1>
<p>
At the moment, our visualization allows users to focus on single neighborhoods
on the map and have the bubble chart auto-adapt. Just in our own testing,
this has enabled the discovery of interesting differences in the distribution
of S-L opportunities across Boston.
</p>
<p>
An obvious improvement would be to implement parallel functionality
for drilling into specific types of service. This would allow for a
finer-grained understanding of the distribution of services across
neighborhoods (for example, math tutors might be more prevalent in some
locations, while civics tutors dominate others). It would also allow for
more service-type-driven exploration of the data, so that users interested
in seeing the distribution of a single service type across all of Boston
will only need to click one bubble to see what they're interested in,
as opposed to clicking every neighborhood.
</p>
<p>
Another useful extension to our visualization would be to allow the
displayed data to be filtered by time. This would allow users to identify
trends of growth and decline in the number of S-L opportunities in each
neighborhood and type of service.
</p>
</div>
</div>
</div>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>
<script src="https://d3js.org/d3.v4.min.js"></script>
<script>
/************************************/
/***** Shared variables. *****/
/************************************/
var width = 575, height = 600;
var defaultMapSubtitle = "Click a neighborhood to view specific organization locations",
defaultBubbleSubtitle = "Click a neighborhood to show only bubbles for that neighborhood";
var mapSubtitle = d3.select("#map-subtitle")
.text(defaultMapSubtitle);
var bubblesSubtitle = d3.select("#bubbles-subtitle")
.text(defaultBubbleSubtitle);
/************************************/
/***** Map-only variables. *****/
/************************************/
var mapCentered, mapData;
var projection = d3.geoMercator()
.scale(120000)
// Center the Map in Boston
.center([-71.0589, 42.323])
.translate([width / 2, height / 2]);
var path = d3.geoPath()
.projection(projection);
// Set svg width & height
var map = d3.select("#map")
.attr("width", width)
.attr("height", height);
map.select("rect.background")
.attr("width", width)
.attr("height", height)
.on("click", mapClicked);
var mapFg = map.select(".foreground");
var mapLayer = mapFg.select(".map-layer");
var mapTooltipAnchor = map.select(".tooltip-anchor")
.attr("transform", "translate(" + width + ",0)");
// Define color scale
var mapColor = d3.scaleLinear()
.range(["#f7fbff","#084594"]);
map.selectAll(".legend linearGradient stop")
.data(mapColor.range())
.attr("stop-color", function(d) { return d; });
// Get neighborhood"s number of organizations
function numOrgs(d){
return d.orgs ? d.orgs.length : 0;
}
// Get province color
function fillFn(d){
return mapColor(numOrgs(d));
}
// When pin is clicked, open the service learning organization's website in a new tab
function pinClicked(d) {
if(d.website.substring(0,4)==="http") {
window.open(d.website);
}
else {
window.open("http://" + d.website);
}
}
function neighborhoodTooltipPos(tip, element) {
var data = d3.select(element).datum();
var centroid = path.centroid(data.borders);
if (mapCentered) {
var centeredCentroid = path.centroid(mapCentered.borders);
var centeredBbox = path.bounds(mapCentered.borders);
if (centroid[1] < centeredBbox[0][1]) return "bottom";
else if (centroid[1] > centeredBbox[1][1]) return "top";
else if (centroid[0] > centeredCentroid[0]) return "left";
else return "right";
return { top: top, left: left };
} else {
if (centroid[0] < width / 2) {
return "right";
} else {
return "left";
}
}
}
// When map is clicked, zoom in and redraw the bubbles
function mapClicked(d) {
var x, y, k;
if(d && d.orgs.length !== 0) {
// Compute centroid of the selected path
// Zoom in to view the neighborhood.
if (d && mapCentered !== d & d.orgs.length !== 0) {
// Set the zoom scale based on the size of the neighborhood.
var centroid = path.centroid(d.borders),
neighborhoodBounds = path.bounds(d.borders),
xrange = neighborhoodBounds[1][0] - neighborhoodBounds[0][0],
yrange = neighborhoodBounds[1][1] - neighborhoodBounds[0][1];
x = centroid[0];
y = centroid[1];
k = xrange > yrange ? (width*.9)/xrange : (height*.9)/yrange;
mapCentered = d;
} else {
x = width / 2;
y = height / 2;
k = 1;
mapCentered = null;
}
// Highlight the mapClicked province
mapLayer.selectAll("path")
.style("fill", function(d) {
if (mapCentered) {
return d === mapCentered ? "white" : "#d9d9d9";
} else {
return fillFn(d);
}
});
// Zoom
mapFg.transition()
.duration(750)
.attr("transform", "translate(" + width / 2 + "," + height / 2 + ")scale(" + k + ")translate(" + -x + "," + -y + ")");
// Draw pins for organization locations in the selected neighborhood.
if (mapCentered) {
path.pointRadius(3 / k);
var dots = mapFg.selectAll(".pin").data(d.orgs,function(d){ return d.id });
// Remove any dots on the map from some other neighborhood.
dots.exit().remove();
// Draw the new dots.
dots.enter().append("path")
.attr("d", function(d){
return path({ type: "Point", coordinates: [parseFloat(d.lng), parseFloat(d.lat)] });
})
.attr("class", "pin")
.attr("fill", "blue")
.on('click', pinClicked)
.on('mouseover', function(d){ d3.select(this).style("fill", "#fee391") })
.on('mouseout', function(d){ d3.select(this).style("fill", "blue") })
.style('cursor', 'pointer')
.attr("data-original-title", function(d) {
return "<span>" + d.name + "</span><br /><span>" + d.address + "</span><br /><span>(Click to open website)</span>"
})
.attr("data-toggle", "tooltip");
$(this).tooltip("destroy");
var prevClicked = $('.neighborhood.disabled[data-toggle="tooltip"]');
prevClicked.tooltip({
container: "body",
html: true,
placement: neighborhoodTooltipPos
});
prevClicked.removeClass("disabled");
$(this).addClass("disabled");
$('.pin[data-toggle="tooltip"]').tooltip({ container: "body", html: true });
mapSubtitle.text(d.orgs.length + " organization" + (d.orgs.length === 1 ? "" : "s") + " in " + d.name + " (Click again to un-zoom)");
bubblesSubtitle.text("Distribution for " + d.name);
} else {
// Clean up and zoom out.
path.pointRadius(null);
mapFg.selectAll(".pin").remove();
var prevClicked = $('.neighborhood.disabled[data-toggle="tooltip"]');
prevClicked.tooltip({
container: "body",
html: true,
placement: neighborhoodTooltipPos
});
prevClicked.removeClass("disabled");
mapSubtitle.text(defaultMapSubtitle);
bubblesSubtitle.text(defaultBubbleSubtitle);
}
setTimeout(drawBubbles, 100);
}
}
function mouseover(d) {
// Highlight hovered province
d3.select(this).style("fill", function (d) {
if (mapCentered && d === mapCentered) {
return "white";
} else if (d.orgs.length !== 0) {
return "#fee391";
} else {
return d3.select(this).style("fill");
}
});
}
function mouseout(d) {
// Reset province color
mapLayer.selectAll("path")
.style("fill", function(d){
if (mapCentered) {
return d === mapCentered ? "white" : "#d9d9d9";
} else {
return fillFn(d);
}
});
}
function drawMap() {
// Update color scale domain based on data
mapColor.domain([0, d3.max(mapData, numOrgs)]);
map.selectAll("text.tick")
.data(mapColor.domain())
.text(function(d) { return d; })
// Draw each province as a path
mapLayer.selectAll(".neighborhood")
.data(mapData)
.enter().append("path")
.attr("d", function(d) {
return path(d["borders"]);
})
.attr("vector-effect", "non-scaling-stroke")
.attr("class", "neighborhood")
.style("fill", fillFn)
.style("cursor", function(d) {
return d.orgs.length === 0 ? "not-allowed" : "pointer";
})
.on("mouseover", mouseover)
.on("mouseout", mouseout)
.on("click", mapClicked)
.attr("data-original-title", function(d) {
var num = numOrgs(d);
return "<span>" + d.name + "</span><br /><span>" + num +
" Organization" + (num === 1 ? "" : "s") + "</span>" +
(num === 0 ? "" : "<br /><span>(Click to see org locations)</span>");
})
.attr("data-toggle", "tooltip");
$('.neighborhood[data-toggle="tooltip"]').tooltip({
container: "body",
html: true,
placement: neighborhoodTooltipPos
});
}
/************************************/
/***** Bubble-only variables. *****/
/************************************/
var bubbleCentered, bubbleData;
var format = d3.format(",d");
var bubbleColor = d3.scaleOrdinal().range(d3.schemeCategory20c);
var bubbleTitleThreshold = 25;
var bubbleMargin = 20;
var bubble = d3.pack()
.size([width - bubbleMargin, height - bubbleMargin])
.padding(1.5);
var bubbles = d3.select("#bubbles")
.attr("width", width)
.attr("height", height);
bubbles.select("rect.background")
.attr("width", width)
.attr("height", height);
var bubbleFg = bubbles.select(".foreground")
.attr("transform",
"translate(" + (bubbleMargin / 2) + "," + (bubbleMargin / 2) + ")");
function drawBubblesOverview(data) {
var nodes = bubbleFg.selectAll(".node")
.data(data, function(d) { return d.id; });
nodes.exit().selectAll("circle")
.transition()
.duration(750)
.attr("r", 0)
.attr("data-original-title", null)
.attr("data-toggle", null)
.each(function() {
$(this).tooltip("destroy");
});
nodes.attr("data-original-title", function(d) {
return (d.r < bubbleTitleThreshold ? "<span>" + d.class + "</span><br />" : "") +
"<span>" + d.value + " Volunteer" + (d.value == 1 ? "" : "s") + "</span>";
})
.transition()
.duration(750)
.attr("transform", function(d) {
return "translate(" + d.x + "," + d.y + ")";
});
nodes.selectAll("circle")
.data(data, function(d) { return d.id; })
.transition()
.duration(750)
.attr("r", function(d) { return d.r; });
nodes.selectAll("text")
.data(data, function(d) { return d.id; })
.selectAll("tspan")
.data(function(d) {
return d.class.split(/(?=[A-Z][^A-Z])/g).map(function(ts) {
return { text: ts, r: d.r };
});
})
.transition()
.duration(750)
.attr("font-size", function(d) { return d.r / 3; })
.attr("y", function(d, i, nodes) {
return (5 * d.r / 12) + (i - nodes.length / 2 - 0.5) * (d.r / 3);
})
.text(function(d) {
return d.r > bubbleTitleThreshold ? d.text : "";
});
var newNodes = nodes.enter()
.append("g")
.attr("class", "node")
.attr("transform", function(d) { return "translate(" + d.x + "," + d.y + ")"; })
.attr("data-original-title", function(d) {
return (d.r < bubbleTitleThreshold ? "<span>" + d.class + "</span><br />" : "") +
"<span>" + d.value + " Volunteer" + (d.value == 1 ? "" : "s") + "</span>";
})
.attr("data-toggle", "tooltip");
newNodes.append("circle")
.attr("id", function(d) { return d.id; })
.attr("r", function(d) { return d.r; })
.style("fill", function(d) { return bubbleColor(d.package); });
newNodes.append("clipPath")
.attr("id", function(d) { return "clip-" + d.id; })
.append("use")
.attr("xlink:href", function(d) { return "#" + d.id; });
newNodes.append("text")
.attr("text-anchor", "middle")
.attr("clip-path", function(d) { return "url(#clip-" + d.id + ")"; })
.style("font-weight", 350)
.selectAll("tspan")
.data(function(d) {
return d.class.split(/(?=[A-Z][^A-Z])/g).map(function(ts) {
return { text: ts, r: d.r };
});
})
.enter().append("tspan")
.attr("x", 0)
.attr("y", function(d, i, nodes) {
return (5 * d.r / 12) + (i - nodes.length / 2 - 0.5) * (d.r / 3);
})
.attr("font-size", function(d) { return d.r / 3; })
.text(function(d) { return d.r > bubbleTitleThreshold ? d.text : ""; });
$('.node[data-toggle="tooltip"]').tooltip({ container : "body", html: true });
}
function drawBubbles() {
var filteredData;
if (mapCentered) {
filteredData = {
name: bubbleData.name,
children: bubbleData.children.map(function(c) {
return {
name: c.name,
children: c.children.filter(function(c2) {
return c2.child_type === 'subtype' || c2.neighborhood === mapCentered.name;
}).map(function(c2) {
if (c2.child_type !== 'subtype') {
return c2;
} else {
return {
name: c2.name,
child_type: c2.child_type,
children: c2.children.filter(function(c3) {
return c3.neighborhood === mapCentered.name;
})
};
}
}).filter(function(c2) {
return !c2.children || c2.children.length > 0;
})
};
}).filter(function(c) {
return !c.children || c.children.length > 0;
})
};
} else {
filteredData = bubbleData;
}
var root = d3.hierarchy(filteredData)
.each(function(d) {
var name;
if (name = d.data.name) {
var i = name.lastIndexOf(".");
d.id = name.replace(/\s+/g, "-");
d.package = i < 0 ? name : name.slice(0, i);
d.class = name.slice(i + 1);
}
})
.sum(function(d) {
return d.volunteers ? d.volunteers : 0;
});
var data = bubble(root).children;
drawBubblesOverview(data);
}
/************************************/
/***** Initial plot setup. *****/
/************************************/
d3.json("data/orgs-by-neighborhood.json", function(error, data) {
if (error) throw error;
mapData = data;
drawMap();
});
d3.json("data/courses-by-service.json", function(error, data) {
if (error) throw error;
bubbleData = data;
drawBubbles();
});
</script>
</body>