Public
Edited
Dec 6, 2023
1 fork
Insert cell
# Cobble Hill Foodmap
Insert cell
Type JavaScript, then Shift-Enter. Ctrl-space for more options. Arrow ↑/↓ to switch modes.

Insert cell
chart = {
const width = 430,
height = 420;
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","red")//style
.style("stroke-width",".8px")
.style("fill","blue")
.on("mouseover",polyHover)
.on("mouseout",polyHoverOut)

function polyHover(event,d){
//console.log("hello studious students")
d3.select(this).style("fill","purple")
svg
.append("text")
.attr("x","300")
.attr("y","100")
.attr("class","hoverText")
.style("font-size", "10px")
.attr("color", "blue")
.text(d.Name)

svg
.append("text")
.attr("x","300")
.attr("y","110")
.attr("class","hoverText")
.style("font-size", "10px")
.attr("color", "blue")
.text(d.Category)
//.text("I love CASE 😀")

}
p.enter().append("polyline") //after we draw our first polyline, use this line
.data(cobble_hill_foodmap_details)
.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",".7px")
.style("fill","none")
p.enter().append("polyline") //after we draw our first polyline, use this line
.data(cobble_hill_foodmap_buildings)
.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","gray")//style
.style("stroke-width",".5px")
.style("fill","none")
p.enter().append("polyline") //after we draw our first polyline, use this line
.data(cobble_hill_foodmap_parks)
.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","green")//style
.style("stroke-width",".8px")
.style("fill","none")
function polyHoverOut(){
d3.select(this).style("fill","Blue")
svg.selectAll("text.hoverText").remove()

}

return svg.node();
}
Insert cell
cobble_hill_foodmap_parks = FileAttachment("Cobble_Hill_Foodmap_Parks.txt").tsv({array:true})
Insert cell
cobble_hill_foodmap_buildings = FileAttachment("Cobble_Hill_Foodmap_Buildings.txt").tsv({array:true})
Insert cell
cobble_hill_foodmap_details = FileAttachment("Cobble_Hill_Foodmap_Details.txt").tsv({array:true})
Insert cell
outlines = {

var list = cobble_hill_foodmap_foodmarket
var spreadsheet = buildingList
var cleanLines = []
for (let i = 0; i < list.length-1; i=i+2) {
var id = list[i+1][0]

var Name
var Category

for (let k = 0; k < spreadsheet.length; k++) {
if(id==spreadsheet[k].Address){
console.log("match!!!!!!!")
Name = spreadsheet[k].Name
Category = spreadsheet[k].Category
}
}
cleanLines.push({pts:list[i],id:id,Name:Name,Category:Category})//add features to our final list of objects
}


return cleanLines
}
Insert cell
cobble_hill_foodmap_foodmarket = FileAttachment("Cobble_Hill_Foodmap_Foodmarket.txt").tsv({array:true})
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