Public
Edited
Sep 21, 2023
Insert cell
# 2023 Fall Studio 9/17 -Lower Manhattan Work & Transportation Isometric
Insert cell
chart = {
const width = 500,
height = 500;
const svg = d3.create("svg")
.attr("viewBox", [0, 0, width, height]);
var g = svg.append("g").attr("id", "paths");

var p = svg.selectAll("polyline") //d3 geopath
.data(outlines)
.enter() //there are more data than elements, this selects them
.append("polyline") //appends path to data
.attr("points", function(d) {return d.pts})//required attributes
.style("stroke","black")//style
.style("stroke-width","0.6px")
.style("fill",fillColor)
.on("mouseover",polyHover)
.on("mouseout",polyHoverOut)

function fillColor(d,i){

var color = "rgb(240,248,255)"
if(d.Transportation=="4, 5"){color="rgb(0,102,51)"}
if(d.Transportation=="2, 3"){color="blue"}
if(d.Transportation=="1"){color="rgb(180,0,0)"}
if(d.Transportation=="J, Z"){color="purple"}
if(d.Transportation=="FERRY"){color="pink"}
if(d.Transportation=="R, W"){color="rgb(255,255,0)"}


return color
}
p.enter().append("polyline") //use this line after the first polyline is added
.data(isodetail)
.enter() //there are more data than elements, this selects them
.append("polyline") //appends path to data
.attr("points", function(d) {return d})//required attributes
.style("stroke","black")//style
.style("stroke-width","0.1px")
.style("fill","none")

function polyHover(event,d){
d3.select(this).style("fill","rgb(255,102,102)")

svg
.append("text")
.attr("x","350")
.attr("y","100")
.attr("class","hoverText")
.text(d.Address)
.style ("font-size", "5px")
svg
.append("text")
.attr("x","350")
.attr("y","105")
.attr("class","hoverText")
.text(d.BuildingType)
.style ("font-size", "5px")
svg
.append("text")
.attr("x","350")
.attr("y","110")
.attr("class","hoverText")
.text(d.BuildingGreenhouseEmission)
.style ("font-size", "5px")
svg
.append("text")
.attr("x","350")
.attr("y","365")
.attr("class","hoverText")
.text(d.Transportation)
.style ("font-size", "5px")
svg
.append("text")
.attr("x","350")
.attr("y","370")
.attr("class","hoverText")
.text(d.Availability)
.style ("font-size", "5px")
svg
.append("text")
.attr("x","350")
.attr("y","115")
.attr("class","hoverText")
.text(d.CarbonFootprintPublicTransport)
.style ("font-size", "5px")
svg
.append("text")
.attr("x","350")
.attr("y","120")
.attr("class","hoverText")
.text(d.CarbonFootprintCar)
.style ("font-size", "5px")

svg
.append("text")
.attr("x","310")
.attr("y","105")
.attr("class","hoverText")
.text("Building Types")
.style ("font-size", "5px")

svg
.append("text")
.attr("x","310")
.attr("y","100")
.attr("class","hoverText")
.text("Address")
.style ("font-size", "5px")

svg
.append("text")
.attr("x","305")
.attr("y","110")
.attr("class","hoverText")
.text("CO2 Emission")
.style ("font-size", "5px")

svg
.append("text")
.attr("x","305")
.attr("y","115")
.attr("class","hoverText")
.text("CO2 by bus/subway")
.style ("font-size", "5px")
svg
.append("text")
.attr("x","305")
.attr("y","120")
.attr("class","hoverText")
.text("CO2 by car")
.style ("font-size", "5px")

}

function polyHoverOut(){
d3.select(this).style("fill",fillColor)
svg.selectAll("text.hoverText").remove()
}
return svg.node();
}
Insert cell
isolines = FileAttachment("isolines.txt").tsv({array:true})
Insert cell
isodetail = FileAttachment("isodetail@1.txt").tsv({array:true})
Insert cell
isooutline2 = FileAttachment("isooutline@2.txt").tsv({array:true})
Insert cell
outlines = {
var list = isooutline2
var spreadsheet = buildingList
var cleanLines = []
for (let i = 0; i < list.length-1; i=i+2) {
var id = list[i+1][0]
var idNum = Number(id)

var Address
var BuildingType
var BuildingGreenhouseEmission
var CarbonFootprintCar
var CarbonFootprintPublicTransport


for (let k = 0; k < spreadsheet.length; k++) {
if(idNum==spreadsheet[k].Key){
//console.log("match!!!!!!!")
Address = spreadsheet[k].Address
BuildingType = spreadsheet[k].BuildingType
BuildingGreenhouseEmission = spreadsheet[k].BuildingGreenhouseEmission
CarbonFootprintPublicTransport = spreadsheet[k].CarbonFootprintPublicTransport
CarbonFootprintCar = spreadsheet[k].CarbonFootprintCar
}
}
//cleanLines.push({pts:st3[i],id:st3[i+1][0]})
cleanLines.push({pts:list[i],id:idNum,Address:Address,BuildingType:BuildingType,BuildingGreenhouseEmission:BuildingGreenhouseEmission,CarbonFootprintPublicTransport:CarbonFootprintPublicTransport,CarbonFootprintCar:CarbonFootprintCar})
}


return cleanLines
}
Insert cell
Insert cell
buildingList = d3.csv(buildingList_link,d3.autoType)
Insert cell

Purpose-built for displays of data

Observable is your go-to platform for exploring data and creating expressive data visualizations. Use reactive JavaScript notebooks for prototyping and a collaborative canvas for visual data exploration and dashboard creation.
Learn more