Published
Edited
May 14, 2022
Insert cell
# ARCH5400 Final Project
Insert cell
<div id="viz_box">
<svg width="815" height="1899" id="canvas"></svg>

<div id="controls">
<h1>Manhattan Trees </br> and Their "Roots"</h1>
<p><i>Trees might be planted into the ground, but their </br> locations are rooted in redlining practices, </br> especially in cities. </br></br> Discover 1937 Manhattan, and hover </br> over each button to see more details.</i></p>
</br>
<div>
<button id="btnShowAll"
<div title="Click below to see how the region was redlined.">show all</button>
</br>
<button id="btnA" style="background-color:#8cb369"
<div title="aka white neighborhoods">"best neighborhoods"</div>
</button>
<button id="btnB" style="background-color: #8EB8E5"
<div title="neighborhoods with very few minorities">"still desirable"</button>
</br>
<button id="btnC" style="background-color: #F4E285"
<div title="neighborhoods with a growing number of minorities">"definitely declining"</button>
</br>
<button id="btnD" style="background-color: #DB5461"
<div title="aka neighborhoods of minorities">"hazardous"</button>
</br>
<button id="btnDimAll">hide all</button>

</br></br>
<button id="btnFlood" style="background-color: #D4D4D4"
<div title="facing fragility, historically redlined neighborhoods are now forced to deal with heavier consequences of global warming due to the prevented provision of green infrastructure and vegetation. By 2050, given current projections, parts of those neighborhoods will be underwater.">consequences? fragility</button>
</div>
</div>
</div>
Insert cell
Insert cell
projection = d3.geoMercator() // just the standard, common, Mercator projection
.center([-73.95635, 40.852])
.scale(482000)
Insert cell
pathGenerator = d3.geoPath().projection(projection); // to create SVG paths from the points of the GIS features
Insert cell
Insert cell
map = d3.select("#viz_box").select("#canvas")
Insert cell
worldFlood = FileAttachment("Sea Level Rise Maps (2020s 100-year Floodplain).geojson").json()
Insert cell
drawFloodMap = {
let mapLayer = map.append("g").attr("id","flood_zones")
.selectAll("path")
.data(worldFlood.features)
.join("path")
.attr("d", pathGenerator)
.style("fill", "#D4D4D4")
.style("opacity", "0")
return mapLayer;
}
Insert cell
Insert cell
FileAttachment("NYManhattan1937.geojson")
Insert cell
world = FileAttachment("NYManhattan1937.geojson").json()
Insert cell
drawMap = {
let mapLayer = map.append("g").attr("id","neighborhood")
.selectAll("path")
.data(world.features)
.join("path")
.attr("d", pathGenerator)
.attr("class", d => d.properties["holc_grade"]);
return mapLayer;
}
Insert cell
<style>
.A {fill:#8cb369; opacity:0}
.B {fill:#8EB8E5; opacity:0}
.C {fill:#f4e285; opacity:0}
.D {fill:#DB5461; opacity:0}
</style>
Insert cell
Insert cell
data = FileAttachment("Manhattan_Trees.csv").csv()
Insert cell
toNum = (text) => Number(text.replace(/,/g,''))
Insert cell
viz = d3.select("#viz_box").select("#canvas")
Insert cell
cirlces = viz.selectAll("circles")
.data(data)
.join("circle")
.attr('cx', d => projection([toNum(d.longitude),toNum(d.latitude)])[0])
.attr('cy', d => projection([toNum(d.longitude),toNum(d.latitude)])[1])
.attr("r", d => rFromDiameter(d['tree_dbh']) * 0.08)
Insert cell
rFromDiameter = (tree_dbh) => toNum(tree_dbh)/2
Insert cell
Insert cell
function hideAll() {drawMap.style("opacity", "0")}
Insert cell
function showFlood() {drawFloodMap.style("opacity", ".5")}
Insert cell
function hideFlood() {drawFloodMap.style("opacity", "0")}
Insert cell
function showAll() {drawMap.style("opacity", "1")}
Insert cell
function filter(field, value) {
hideAll();
drawMap.filter(d => d.properties[field] == value).style("opacity", "1");
}
Insert cell
function filterValue(field,value) {
hideAll();
drawMap.filter(d => d.properties[field] > value).style("opacity", "1");
}
Insert cell
{
const btns = d3.select("#viz_box").select("#controls");
btns.select("#btnA").on("click", () => filter("holc_grade",'A'));
btns.select("#btnB").on("click", () => filter("holc_grade",'B'));
btns.select("#btnC").on("click", () => filter("holc_grade",'C'));
btns.select("#btnD").on("click", () => filter("holc_grade",'D'));

btns.select("#btnShowAll").on("click", showAll);
btns.select("#btnDimAll").on("click", hideAll);
btns.select("#btnFlood").on("click", showFlood);
btns.select("#btnFlood").on("dblclick", hideFlood);
}
Insert cell
<style>
#viz_box {
text-align: center;
}
#controls {
position: absolute;
top: 10px;
left: 5px;
font-size: 12px;
text-align: enter
}
#controls button {
width: 200px;
border-radius: 15px;
border: 1px solid gray;
margin: 2px;
}
#controls button:hover {
cursor: pointer;
}
#mytext {fill: red;}
</style>
Insert cell

One platform to build and deploy the best data apps

Experiment and prototype by building visualizations in live JavaScript notebooks. Collaborate with your team and decide which concepts to build out.
Use Observable Framework to build data apps locally. Use data loaders to build in any language or library, including Python, SQL, and R.
Seamlessly deploy to Observable. Test before you ship, use automatic deploy-on-commit, and ensure your projects are always up-to-date.
Learn more