Skip to content

Instantly share code, notes, and snippets.

@ResidentMario
Last active February 11, 2017 06:15
Show Gist options
  • Save ResidentMario/2b78c27de7ec8af07f7e292e66ed8c03 to your computer and use it in GitHub Desktop.
Save ResidentMario/2b78c27de7ec8af07f7e292e66ed8c03 to your computer and use it in GitHub Desktop.
Unreceptive treeemap
Type Subtype Count
Air Quality Indoor Air Quality 4361
Air Quality Smoking 1629
Air Quality Unspecified Air Quality Issue 8843
Animal Issues Animal Abuse 10087
Animal Issues Animal Facility Issue 120
Animal Issues Animal in a Park 1880
Animal Issues Harboring Bees or Wasps 177
Animal Issues Illegal Animal 354
Animal Issues Unleashed Dog 623
Animal Issues Unsanitary Animal 2181
Building Maintenance Asbestos 2075
Building Maintenance Cable Complaint 1015
Building Maintenance Door or Window 37656
Building Maintenance Electrical 31486
Building Maintenance Elevator 13532
Building Maintenance Flooding or Stairs 23961
Building Maintenance General Construction or Plumbing 30369
Building Maintenance Illegal Conversion 27587
Building Maintenance Lead 11444
Building Maintenance Paint or Plaster 60463
Building Maintenance Plumbing 4170
Building Maintenance Schools 1761
Building Maintenance Sewer or Sidewalk Condition 8010
Building Maintenance Unspecified Building Maintenance Issue 14425
Construction Site Safety 1135
Consumer Complaint Food Establishment Complaint 10213
Consumer Complaint Food Poisoning 3549
Consumer Complaint For Hire Vehicle Complaint 6389
Consumer Complaint Home Care Provider Complaint 29
Consumer Complaint Home Delivered Meal Complaint 200
Consumer Complaint Municipal Parking Facility 67
Consumer Complaint Paid Professional Complaint 434
Consumer Complaint Senior Center Complaint 386
Consumer Complaint Street Vendor Complaint 4734
Consumer Complaint Taxi Complaint 18962
Consumer Complaint Unspecified Consumer Complaint 43362
Crime Disorderly Youth 234
Crime Drug Activity 261
Crime Elder Abuse 471
Crime Graffiti 12624
Crime Illegal Alcohol 1538
Crime Illegal Fireworks 221
Crime Non-Emergency Police Matter 9225
Crime Posting Advertisement 1119
Crime Unspecified Crime 8584
Crime Urinating in Public 476
Fire Safety Fire Alarm 547
Fire Safety Fire Safety Director On-Site Exam Scheduling 4964
Fire Safety Food Preparation Fire Safety 59
Fire Safety Inspection 849
General Alzheimer's Care 229
General Beach, Pool, or Sauna Complaint 170
General Complaint 1473
General Compliment 92
General Daycare Inquiry 542
General Found Property 314
General Housing Inquiry 1771
General Inquiry 502
General Other Enforcement 18292
General Unspecified Miscellaneous Issue 1099
Greenery Damaged Tree 24880
Greenery Dead or Dying Tree 10794
Greenery Illegal Tree Damage 3154
Greenery New Tree Request 18347
Greenery Overgrown Tree or Branches 12919
Greenery Poison Ivy 131
Greenery Unspecified Greenery Issue 232
Heat or Water Boilers 1719
Heat or Water Non-Residential Heat 987
Heat or Water Plumbing 52713
Heat or Water Unspecified Heat or Water Problem 222542
Heat or Water Water Conservation 4306
Heat or Water Water Leak 31439
Heat or Water Water Quality 1598
Heat or Water Water System 73486
Homelessness Homeless Encampment 5184
Homelessness Homelessness Assistance 45665
Homelessness Panhandling 479
Illegal Parking Blocked Driveway 119358
Illegal Parking City Vehicle Placard Complaint 352
Illegal Parking Derelict Vehicle 57354
Illegal Parking Unspecified Parking Violation 122724
Noise Commerical Noise 49120
Noise Helicopter 1097
Noise Park 3994
Noise Place of Worship 924
Noise Public Assembly 475
Noise Residential Noise 228582
Noise Sanitation Trucks 199
Noise Street or Sidewalk Noise 61260
Noise Unspecified Noise Complaint 58563
Noise Vehicle Noise 23883
Paperwork Benefit Card Replacement 25102
Paperwork DCA or DOH New License Application Request 1808
Paperwork Literature Request 36558
Paperwork Parking Status Request 6349
Paperwork Tattooing Paperwork Inquiry 81
Paperwork Unspecified Paperwork Inquiry 211
Parks Parks Violation 2279
Parks Unspecified Issue 1939
Property and Buildings Low Income Senior Citizen Housing 5994
Property and Buildings Disability Rent Increase Exemption 590
Property and Buildings Real Property Income and Expense Issue 244
Property and Housing DF Property Document Request 5934
Property and Housing Payment Issue 4120
Property and Housing Property Account Update 6555
Property and Housing Property Reduction 10263
Property and Housing Senior Citizen Rent Increase Exemption 6569
Property and Housing Unspecified Property Issue 1748
Public Transit Bus Stop Shelter Placement 204
Public Transit Ferry Inquiry or Complaint 917
Sanitation Electronic Waste Disposal 2965
Sanitation Hazardous Materials 3326
Sanitation Indoor Sewage 1249
Sanitation Industrial Waste 1413
Sanitation Litter Basket Request 2819
Sanitation Missed Collections 30203
Sanitation Mold 316
Sanitation Mosquitoes 1066
Sanitation Overflowing Litter Basket 1181
Sanitation Public Toilet 39
Sanitation Recycling Enforcement 648
Sanitation Rodent 32040
Sanitation Sewer 33091
Sanitation Standing Water 5633
Sanitation Sweeping 1010
Sanitation Unsanitary Pigeon Condition 654
Sanitation Unspecified Sanitary Issue 149754
Sanitation Vacant Lot Condition 2158
Street Condition Bike Rack Condition 109
Street Condition Bridge or Tunnel Condition 359
Street Condition Broken Parking Meter 25305
Street Condition Curb Condition 2802
Street Condition Damaged Sign 6970
Street Condition Dangling Sign 2173
Street Condition Derelict Bicycle 1772
Street Condition Highway Condition 3783
Street Condition Missing Sign 4753
Street Condition Public Payphone or LinkNYC Complaint 381
Street Condition Sidewalk Condition 6224
Street Condition Snow 5478
Street Condition Street Light Condition 89201
Street Condition Traffic 5485
Street Condition Traffic Signal Condition 37606
Street Condition Unspecified Street Condition 90882
Unknown Appliance 12618
<svg width=800 height=400></svg>
<script src="https://cdnjs.cloudflare.com/ajax/libs/require.js/2.3.2/require.js"></script>
<script>
requirejs.config({
paths: {
d3: "https://d3js.org/d3.v4.js"
tree: "https://unpkg.com/threshold-tree@1.0.4/umd/threshold-tree"
}
});
requirejs(['d3', 'tree'], function(d3, tree) {
d3.csv("complaint_types.csv", function(complaints) {
// Build the threshold tree and convert it to a JSON output.
let hr = new tree.ThresholdTree(complaints).as_hierarchy();
// Convert that to a hierarchy.
let root = d3.stratify().id(d => d.name).parentId(d => d.parent)(hr);
// Attach a summer to the hierarchy.
// First a utility function...
function object_is_direct_child(root, obj) {
return (root.children.filter(child => (child.id === obj.name)).length > 0);
}
// Now the sum function itself.
let nodal_summer = function(node) {
return ((object_is_direct_child(root, node)) ? node.n : 0);
}
root = root.sum(nodal_summer);
// Create our treemap layout factory function.
let treemap = d3.treemap()
.tile(d3.treemapResquarify)
.size([800, 400])
.round(true)
.paddingInner(1);
// Apply our treemap function to our data.
treemap(root);
// Select the SVG.
const svg = d3.select("svg");
// Lay out the cells (element transform on groups)
let cells = svg.selectAll("g")
.data(root.children)
.enter()
.append("g")
.attr("transform", d => `translate(${d.x0}, ${d.y0})`);
// Append rects.
let rects = cells.append("rect")
.attr("id", d => `${d.data.name}-rect`)
.attr("width", d => d.x1 - d.x0)
.attr("height", d => d.y1 - d.y0)
.attr("fill", "steelblue")
.attr("stroke", "white")
.attr("stroke-width", "1");
// Add mouseover events signaling interactivity. We want these to fire regardless of whether
// we are hoving over the text or the rect behind it, so we add invisible rects (same as the)
// visible ones) to the screen on top, which have hover effects defined on them.
let hover_rects = cells.append("rect")
.attr("id", d => `${d.data.name}-hover`)
.attr("width", d => d.x1 - d.x0)
.attr("height", d => d.y1 - d.y0)
.attr("fill", "transparent")
.attr("stroke", 0);
// Now we create and bind the click event.
let click = function(d) {
if (d.data.children.length > 0) {
// Use the hover ID to get the underlying name attr (e.g. "Noise-hover" -> "Noise")
let name = this.getAttribute("id").slice(0,-6);
// Select the new root node.
let new_root = root.children.find(c => c.id === name);
// Sum.
new_root = new_root.sum(node => ((object_is_direct_child(new_root, node)) ? node.n : 0));
// Here is the problem area. Why doesn't treemap(new_root) work as expected?
console.log(new_root);
treemap(new_root);
console.log(new_root);
}
}
hover_rects.on("click", click);
});
});
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment