Skip to content

Instantly share code, notes, and snippets.

@elipousson
Forked from d3noob/.block
Last active January 16, 2020 10:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save elipousson/ad787f9c9beb4cc48cd7 to your computer and use it in GitHub Desktop.
Save elipousson/ad787f9c9beb4cc48cd7 to your computer and use it in GitHub Desktop.
Abandoned Property Types/Triggers (D3.js tree diagram)

The data for this visualization is taken from "Table 1.1: Abandoned Properties and Abandonment Triggers" in Bringing Buildings Back (2006), Alan Mallach, p. 7.


This is a simple d3.js tree diagram that loads an external data file as used as an example in the book D3 Tips and Tricks.

It is derived from the Mike Bostock Collapsible tree example but it is a VERY cut down version without the ability to update (collapse).

[
{
"name": "Property Types",
"parent": "null",
"children": [
{
"name": "Multifamily Rental Property",
"parent": "Property Types",
"children": [
{
"name": "Inadequate cash flow or income base",
"parent": "Multifamily Rental Property",
"description": "e.g. Rents too low to cover costs"
},
{
"name": "Inadequate cash flow or execessive cost base",
"parent": "Multifamily Rental Property",
"description": "e.g. Mortgage payments, taxes and insurance"
},
{
"name": "Deterioration",
"parent": "Multifamily Rental Property",
"description": "Need for major repairs inadequately supported by cash flow or market value"
},
{
"name": "Difficulty in obtaining financing",
"parent": "Multifamily Rental Property",
"description": "Influenced by discimination in financial services, e.g. HOLC in 1930s, predatory lending in 2000s"
},
{
"name": "Excessive liens/liens that exceed market value",
"parent": "Multifamily Rental Property",
"description": ""
},
{
"name": "Management or maintenance difficulties",
"parent": "Multifamily Rental Property",
"description": "e.g. tenant/landlord problems, public safety, crime"
},
{
"name": "Neighborhood change",
"parent": "Multifamily Rental Property",
"description": ""
},
{
"name": "Perception of market trends",
"parent": "Multifamily Rental Property",
"description": ""
}
]
},
{
"name": "Single-family Homes",
"parent": "Property Types",
"children": [
{
"name": "Household Transition",
"parent": "Single-family Homes",
"description": "Death or relocation"
},
{
"name": "Deterioration",
"parent": "Single-family Homes",
"description": "Need for major repairs inadequately supported by market value"
},
{
"name": "Low market value",
"parent": "Single-family Homes",
"description": ""
},
{
"name": "Neighborhood change",
"parent": "Single-family Homes",
"description": ""
},
{
"name": "Market imperfections",
"parent": "Single-family Homes",
"description": ""
},
{
"name": "Lack of information about market and resources",
"parent": "Single-family Homes",
"description": "e.g. no awareness of financial incentives"
},
{
"name": "Excessive liens",
"parent": "Single-family Homes",
"description": ""
},
{
"name": "Fraudulent transactions and predatory lending",
"parent": "Single-family Homes",
"description": ""
}
]
},
{
"name": "Commercial & Mixed-use Properties",
"parent": "Property Types",
"children": [
{
"name": "Loss of commercial vitality",
"parent": "Commercial & Mixed-use Properties",
"description": "e.g. in inner-city neighborhood or substandard arterial highway shopping strip"
},
{
"name": "Inadequate cash flow",
"parent": "Commercial & Mixed-use Properties",
"description": ""
},
{
"name": "Deterioration or need for major repairs",
"parent": "Commercial & Mixed-use Properties",
"description": ""
},
{
"name": "Difficulty in obtaining financing",
"parent": "Commercial & Mixed-use Properties",
"description": ""
},
{
"name": "Excessive liens/liens that exceed market value",
"parent": "Commercial & Mixed-use Properties",
"description": ""
},
{
"name": "Crime",
"parent": "Commercial & Mixed-use Properties",
"description": ""
}
]
},
{
"name": "Industrial Properties/Brownfields",
"parent": "Property Types",
"children": [
{
"name": "Building configuration or location no longer suitable for prior use",
"parent": "Industrial Properties/Brownfields",
"description": "e.g. Multistory industrial buildings, locations along canals or rail lines"
},
{
"name": "Environmental remediation costs and uncertainties",
"parent": "Industrial Properties/Brownfields",
"description": ""
},
{
"name": "High capital cost of redevelopment",
"parent": "Industrial Properties/Brownfields",
"description": ""
},
{
"name": "Legal obstacles",
"parent": "Industrial Properties/Brownfields",
"description": ""
},
{
"name": "Difficulty in obtaining financing",
"parent": "Industrial Properties/Brownfields",
"description": ""
},
{
"name": "Excessive liens/liens that exceed market value",
"parent": "Industrial Properties/Brownfields",
"description": ""
}
]
}
]
}
]
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Abandoned Property Types and Abandonment Triggers</title>
<style>
.node circle {
fill: #fff;
stroke: steelblue;
stroke-width: 3px;
}
.node text { font: 12px sans-serif; }
.link {
fill: none;
stroke: #ccc;
stroke-width: 2px;
}
</style>
</head>
<body>
<!-- load the d3.js library -->
<script src="http://d3js.org/d3.v3.min.js"></script>
<script>
// ************** Generate the tree diagram *****************
var margin = {top: 20, right: 120, bottom: 20, left: 120},
width = 960 - margin.right - margin.left,
height = 500 - margin.top - margin.bottom;
var i = 0;
var tree = d3.layout.tree()
.size([height, width]);
var diagonal = d3.svg.diagonal()
.projection(function(d) { return [d.y, d.x]; });
var svg = d3.select("body").append("svg")
.attr("width", width + margin.right + margin.left)
.attr("height", height + margin.top + margin.bottom)
.append("g")
.attr("transform", "translate(" + margin.left + "," + margin.top + ")");
// load the external data
d3.json("abandoned-property-types-triggers.json", function(error, treeData) {
root = treeData[0];
update(root);
});
function update(source) {
// Compute the new tree layout.
var nodes = tree.nodes(root).reverse(),
links = tree.links(nodes);
// Normalize for fixed-depth.
nodes.forEach(function(d) { d.y = d.depth * 180; });
// Declare the nodes…
var node = svg.selectAll("g.node")
.data(nodes, function(d) { return d.id || (d.id = ++i); });
// Enter the nodes.
var nodeEnter = node.enter().append("g")
.attr("class", "node")
.attr("transform", function(d) {
return "translate(" + d.y + "," + d.x + ")"; });
nodeEnter.append("circle")
.attr("r", 10)
.style("fill", "#fff");
nodeEnter.append("text")
.attr("x", function(d) {
return d.children || d._children ? -13 : 13; })
.attr("dy", ".35em")
.attr("text-anchor", function(d) {
return d.children || d._children ? "end" : "start"; })
.text(function(d) { return d.name; })
.style("fill-opacity", 1);
// Declare the links…
var link = svg.selectAll("path.link")
.data(links, function(d) { return d.target.id; });
// Enter the links.
link.enter().insert("path", "g")
.attr("class", "link")
.attr("d", diagonal);
}
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment