Public
Edited
Sep 27, 2023
Insert cell
# 2023 Fall Studio 9/28 -Lower Manhattan Work & Transportation Plan
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(outline)
.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.3px")
.style("fill",fillColor)
.on("mouseover",polyHover)
.on("mouseout",polyHoverOut)

function fillColor(d,i){

var color = "rgb(230,230,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="rgb(139,69,19)"}
if(d.TotalYearlyRidership2021== "6,767,364"){color="pink"}
if(d.AvgWeekdayRidership2021== "2112"){color="pink"}
if(d.AvgWeekdayRidership2021== "44"){color="pink"}
if(d.Transportation=="R, W"){color="rgb(255,255,0)"}
if(d.Transportation=="N/A"){color="rgb(255,128,0)"}


return color
}


p.enter().append("polyline") //use this line after the first polyline is added
.data(basedetail)
.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","grey")//style
.style("stroke-width","0.1px")
.style("fill","none")

p.enter().append("polyline") //use this line after the first polyline is added
.data(red2)
.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","red")//style
.style("stroke-width","1.5px")
.style("fill","none")

p.enter().append("polyline") //use this line after the first polyline is added
.data(blue)
.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","blue")//style
.style("stroke-width","1.5px")
.style("fill","none")

p.enter().append("polyline") //use this line after the first polyline is added
.data(green)
.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","rgb(0,102,51)")//style
.style("stroke-width","1.5px")
.style("fill","none")

p.enter().append("polyline") //use this line after the first polyline is added
.data(yellow)
.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","yellow")//style
.style("stroke-width","1.5px")
.style("fill","none")

p.enter().append("polyline") //use this line after the first polyline is added
.data(darkred)
.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","rgb(180,0,0)")//style
.style("stroke-width","1.5px")
.style("fill","none")

p.enter().append("polyline") //use this line after the first polyline is added
.data(brown)
.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","rgb(139,69,19)")//style
.style("stroke-width","1.5px")
.style("fill","none")

p.enter().append("polyline") //use this line after the first polyline is added
.data(busline)
.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","rgb(128,255,255)")//style
.style("stroke-width","0.5px")
.style("fill","none")

p.enter().append("polyline") //use this line after the first polyline is added
.data(outlinedetail)
.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","white")//style
.style("stroke-width","0.5px")
.style("fill","none")

p.enter().append("polyline") //use this line after the first polyline is added
.data(boundary)
.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","grey")//style
.style("stroke-width","1.5px")
.style("fill","none")



function polyHover(event,d){
d3.select(this).style("fill","red")


svg
.append("text")
.attr("x","300")
.attr("y","400")
.attr("class","hoverText")
.text(d.Address)
.style ("font-size", "6px")
svg
.append("text")
.attr("x","230")
.attr("y","400")
.attr("class","hoverText")
.text("Address:")
.style ("font-size", "6px")
svg
.append("text")
.attr("x","300")
.attr("y","410")
.attr("class","hoverText")
.text(d.Transportation)
.style ("font-size", "6px")
svg
.append("text")
.attr("x","230")
.attr("y","410")
.attr("class","hoverText")
.text("Mode of Transportation:")
.style ("font-size", "6px")

svg
.append("text")
.attr("x","300")
.attr("y","420")
.attr("class","hoverText")
.text(d.TotalYearlyRidership2021)
.style ("font-size", "6px")
svg
.append("text")
.attr("x","230")
.attr("y","420")
.attr("class","hoverText")
.text("Yearly Ridership:")
.style ("font-size", "6px")
svg
.append("text")
.attr("x","300")
.attr("y","430")
.attr("class","hoverText")
.text(d.AvgWeekdayRidership2021)
.style ("font-size", "6px")
svg
.append("text")
.attr("x","230")
.attr("y","430")
.attr("class","hoverText")
.text("Weekly Ridership:")
.style ("font-size", "6px")

}

function polyHoverOut(){
d3.select(this).style("fill",fillColor)
svg.selectAll("text.hoverText").remove()
}

svg
.append("text")
.attr("x","5")
.attr("y","20")
.text("Transportation in Lower Manhattan")
.style ("font-size", "14px")
return svg.node();
}
Insert cell
basedetail = FileAttachment("Basedetail.txt").tsv({array:true})
Insert cell
boundary = FileAttachment("Boundary@1.txt").tsv({array:true})
Insert cell
outlinedetail = FileAttachment("Outlinedetail.txt").tsv({array:true})
Insert cell
outlines1 = FileAttachment("Outlines.txt").tsv({array:true})
Insert cell
blue = FileAttachment("Blue.txt").tsv({array:true})
Insert cell
brown = FileAttachment("Brown.txt").tsv({array:true})
Insert cell
busline = FileAttachment("Busline.txt").tsv({array:true})
Insert cell
darkred = FileAttachment("Darkred.txt").tsv({array:true})
Insert cell
green = FileAttachment("Green.txt").tsv({array:true})
Insert cell
red2 = FileAttachment("Red@2.txt").tsv({array:true})
Insert cell
yellow = FileAttachment("Yellow.txt").tsv({array:true})
Insert cell
outline = {
var list = outlines1
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 Workersnumber
var Transportation
var Availability
var TotalYearlyRidership2021
var AvgWeekdayRidership2021
var PublicTransportnumber
var Bikednumber
var Walkednumber
var Drovenumber

for (let k = 0; k < spreadsheet.length; k++) {
if(idNum==spreadsheet[k].Key){
//console.log("match!!!!!!!")
Address = spreadsheet[k].Address
BuildingType = spreadsheet[k].BuildingType
Workersnumber = spreadsheet[k].Workersnumber
Transportation = spreadsheet[k].Transportation
Availability = spreadsheet[k].Availability
TotalYearlyRidership2021 = spreadsheet[k].TotalYearlyRidership2021
AvgWeekdayRidership2021 = spreadsheet[k].AvgWeekdayRidership2021
PublicTransportnumber = spreadsheet[k].PublicTransportnumber
Bikednumber = spreadsheet[k].Bikednumber
Walkednumber = spreadsheet[k].Walkednumber
Drovenumber = spreadsheet[k].Drovenumber
}
}
//cleanLines.push({pts:st3[i],id:st3[i+1][0]})
cleanLines.push({pts:list[i],id:idNum,Address:Address,BuildingType:BuildingType,Workersnumber:Workersnumber,Transportation: Transportation,Availability:Availability,TotalYearlyRidership2021:TotalYearlyRidership2021,AvgWeekdayRidership2021:AvgWeekdayRidership2021,PublicTransportnumber:PublicTransportnumber,Bikednumber:Bikednumber,Walkednumber:Walkednumber,Drovenumber:Drovenumber})
}


return cleanLines
}
Insert cell
Insert cell
buildingList = d3.csv(buildingList_link,d3.autoType)
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