Public
Edited
Oct 2, 2023
Insert cell
# Slider Map Manhattan
Insert cell
// Defined Values
Insert cell
Co2Capita = 16.28
Insert cell
Co2Factor = 0.01803491773
Insert cell
SF = 0
Insert cell
ResidentialSF = 0
Insert cell
NumOfHousehold = 0
Insert cell
StandardManPop = 1.86
Insert cell
{var EE;}
Insert cell
//GHG = SF * Co2Factor
Insert cell
{var HouseholdSF;
}
Insert cell
//Household SF base condition

{
var HouseholdSF;
if(NumOfHousehold === 0){
HouseholdSF = ResidentialSF / StandardManPop
} else{
HouseholdSF = ResidentialSF / NumOfHousehold
}
var HouseholdGHG = HouseholdSF * Co2Factor
var NewCapita = HouseholdGHG / Pop
}
Insert cell
//Slider Value Switch
{
var Rating;
let NewCapita = 'Neutral'
if (NewCapita > Co2Capita){
Rating = 'BAD'
} else if (NewCapita = Co2Capita){
Rating = "Neutral"
} else{
Rating = 'Good'
}
}
Insert cell
co2Calc = {

var totalCo2SF = 0
var totalOccupants = 0
//Per capita = 16.28
//Average SF = 0.01803491C773
// Pop=# of People
// Co2Capita = 16.28
// SF = SF
// Co2SF=(ocMult*16.28)/SF
// Co2SF-Factor = 0.01803491773
// HouseholdSF = TotalResidentialSF / NumOfHouseholds
// GHG = Co2SF_Factor * HouseholdSF
// NewCapita = GHG/Slider
// If New Capita > Co2Capita then ('Bad')
// If not ('Good')
//do some calc and rtrn value
//for (let i = 0; i < list.length-1; i=i+2)
for (let i = 0; i < outlines.length-1; i=i+1) {

var alteredOcc = Math.round(outlines[i].Res * Pop) // multiplying occ of each bldg by occupancy

//totalCo2 = totalCo2 + outlines[i].co2
if(typeof(outlines[i].Num) !== "undefined" && outlines[i].Num !== null ){
totalCo2SF = totalCo2SF + outlines[i].sf/outlines[i].Num
break
}
//totalCo2SF = totalCo2SF + parseFloat(outlines[i].sf+outlines[i].Res)
var totalOccupants = 16.28*Pop
var houseHold = outlines[i].sf

}
return [Math.round(totalOccupants),Math.round(totalCo2SF)]
}
Insert cell
Pop
Insert cell
viewof Pop = Inputs.range([0, 10], {value: 1, step: 0.01, label: "Population"})
Insert cell
chart = {
const width = 1250,
height = 1250;
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","3px")
.style("fill","rgb(255,0,0)")
.on("mouseover",polyHover)
.on("mouseout",polyHoverOut)

function polyHover(event,d){
//console.log("hello studious students")
if (d.E_M2 === 0) {
d3.select(this).style("fill","blue");
} else {
d3.select(this).style("fill","yellow")
}
//d3.select(this).style("fill","blue");
svg
.append("text")
.attr("x","100")
.attr("y","100")
.attr("class","hoverText")
.text("Square Feet " + d.sf)

svg
.append("text")
.attr("x","100")
.attr("y","115")
.attr("class","hoverText")
.text("Meters Squared M2 " + d.M2)
svg
.append("text")
.attr("x","100")
.attr("y","130")
.attr("class","hoverText")
.text("Energy per M2 " + d.E_M2)

svg
.append("text")
.attr("x","100")
.attr("y","145")
.attr("class","hoverText")
.text()

svg
.append("text")
.attr("x","50")
.attr("y","50")
.attr("class","hoverText")
.text('Energy per M2 times Meters: '+(d.E_M2) * Pop)

svg
.append("text")
.attr("x","50")
.attr("y","75")
.attr("class","hoverText")
.text('Addess: ' + d.id)


}

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

}


return svg.node();
}
Insert cell
shpFile = FileAttachment("buildings_manhattan.txt").tsv({array:true})
Insert cell
Insert cell
buildingList = d3.csv(buildingList_link,d3.autoType)
Insert cell
outlines = {

var list = shpFile
var spreadsheet = buildingList
var cleanLines = []
for (let i = 0; i < list.length-1; i=i+2) {
var id = list[i+1][0]
var Type
var B_Class
var Floors
var Residental_Units
var SF
var Num_of_Units
var GHG
var M2
var E_M2
for (let k = 0; k < spreadsheet.length; k++) {
if(id==spreadsheet[k].address){
//console.log("match!!!!!!!")
Residental_Units = spreadsheet[k].Residental_Units
SF = parseInt(spreadsheet[k].SF)
Num_of_Units = spreadsheet[k].Num_of_Units
GHG = spreadsheet[k].GHG
M2 = SF * 0.092903
E_M2 = parseInt(spreadsheet[k].Total_E_Use_Per_M2)
}
}
cleanLines.push({pts:list[i],id:id, Res:Residental_Units, sf:SF, Num:Num_of_Units, GHG:GHG, M2:M2, E_M2:E_M2, })//add features to our final list of objects
}


return cleanLines
}
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