Public
Edited
Jan 30, 2023
Fork of base map
1 fork
Insert cell
# Points of Interest near my nook in Troy.
Insert cell
d3 = require("d3@6")
Insert cell
hR = [
{name:"RPI",cost:0,happiness:2},
{name:"GreeneBuilding",cost:0,happiness:1},
{name:"Home",cost:0,happiness:3},
{name:"ProspectPark",cost:0,happiness:4},
{name:"LaCasaDelPizzaria",cost:20,happiness:5},
{name:"Manorys",cost:30,happiness:5},
{name:"HairCut",cost:25,happiness:7},
{name:"LaCapital",cost:15,happiness:7},
{name:"TheRuck",cost:30,happiness:5},
{name:"TroyBeerGarden",cost:60,happiness:7},
{name:"UncleSamsLanes",cost:20,happiness:6},
{name:"Bootleggers",cost:40,happiness:8}

]
Insert cell
totalValues = {
var totalCost = 0
var totalHappiness = 0
totalCost = totalCost +(hR[0].cost*RPI)
totalCost = totalCost +(hR[1].cost*GreeneBuilding)
totalCost = totalCost +(hR[2].cost*Home)
totalCost = totalCost +(hR[3].cost*ProspectPark)
totalCost = totalCost +(hR[4].cost*LaCasaDelPizzaria)
totalCost = totalCost +(hR[5].cost*Manorys)
totalCost = totalCost +(hR[6].cost*HairCut)
totalCost = totalCost +(hR[7].cost*LaCapital)
totalCost = totalCost +(hR[8].cost*TheRuck)
totalCost = totalCost +(hR[9].cost*TroyBeerGarden)
totalCost = totalCost +(hR[10].cost*UncleSamsLanes)
totalCost = totalCost +(hR[11].cost*Bootleggers)

totalHappiness = totalHappiness +(hR[0].happiness*RPI)
totalHappiness = totalHappiness +(hR[1].happiness*GreeneBuilding)
totalHappiness = totalHappiness +(hR[2].happiness*Home)
totalHappiness = totalHappiness +(hR[3].happiness*ProspectPark)
totalHappiness = totalHappiness +(hR[4].happiness*LaCasaDelPizzaria)
totalHappiness = totalHappiness +(hR[5].happiness*Manorys)
totalHappiness = totalHappiness +(hR[6].happiness*HairCut)
totalHappiness = totalHappiness +(hR[7].happiness*LaCapital)
totalHappiness = totalHappiness +(hR[8].happiness*TheRuck)
totalHappiness = totalHappiness +(hR[9].happiness*TroyBeerGarden)
totalHappiness = totalHappiness +(hR[10].happiness*UncleSamsLanes)
totalHappiness = totalHappiness +(hR[11].happiness*Bootleggers)
return[totalCost,totalHappiness]
}
Insert cell
viewof y = Inputs.range([0, 255], {step: 10, label: "Fade", value:0})
Insert cell
viewof spotSize = Inputs.radio([3, 4, 5, 6, 9], {label: "spotSize",value:3})
Insert cell
viewof RPI = Inputs.radio([0, 1, 2, 3, 4, 5, 6, 7, 8, 9], {label: "RPI",value:3})
Insert cell
viewof GreeneBuilding = Inputs.radio([0, 1, 2, 3, 4, 5, 6, 7, 8, 9], {label: "Greene Building",value:3})
Insert cell
viewof Home = Inputs.radio([0, 1, 2, 3, 4, 5, 6, 7, 8, 9], {label: "Home",value:3})
Insert cell
viewof ProspectPark = Inputs.radio([0, 1, 2, 3, 4, 5, 6, 7, 8, 9], {label: "Prospect Park",value:3})
Insert cell
viewof LaCasaDelPizzaria = Inputs.radio([0, 1, 2, 3, 4, 5, 6, 7, 8, 9], {label: "La Casa Del Pizzaria",value:3})
Insert cell
viewof Manorys = Inputs.radio([0, 1, 2, 3, 4, 5, 6, 7, 8, 9], {label: "Manory's",value:3})
Insert cell
viewof HairCut = Inputs.radio([0, 1, 2, 3, 4, 5, 6, 7, 8, 9], {label: "Hair Cut",value:3})
Insert cell
viewof LaCapital = Inputs.radio([0, 1, 2, 3, 4, 5, 6, 7, 8, 9], {label: "La Capital",value:3})
Insert cell
viewof TheRuck = Inputs.radio([0, 1, 2, 3, 4, 5, 6, 7, 8, 9], {label: "The Ruck",value:3})
Insert cell
viewof TroyBeerGarden = Inputs.radio([0, 1, 2, 3, 4, 5, 6, 7, 8, 9], {label: "Troy Beer Garden",value:3})
Insert cell
viewof UncleSamsLanes = Inputs.radio([0, 1, 2, 3, 4, 5, 6, 7, 8, 9], {label: "Uncle Sam's Lanes",value:3})
Insert cell
viewof Bootleggers = Inputs.radio([0, 1, 2, 3, 4, 5, 6, 7, 8, 9], {label: "Bootlegger's",value:3})
Insert cell
chart = {
const width = 960,
height = 900;
const svg = d3.create("svg")
.attr("viewBox", [50, 50, width-100, height-100]);

// Use Mercator projection
var projection = d3
.geoMercator()
.fitSize([width - 50, height - 50], BoundBox);

var path1 = d3.geoPath().projection(projection);
var path2 = d3.geoPath().projection(projection);
var path3 = d3.geoPath().projection(projection);
var path4 = d3.geoPath().projection(projection);
var path5 = d3.geoPath().projection(projection);

var g = svg.append("g").attr("id", "paths");
//i'm not using the boundary lines, so I'm going to comment them out
/*
g.selectAll("path1") //d3 geopath
.data(boundary.features) //get data to define path
.enter() //there are more data than elements, this selects them
.append("path") //appends path to data
.attr('class','outlines')
.attr("d", path1) //The d attribute defines a path to be drawn, only applies to appended elements
.style("fill", "none")
.style('stroke-opacity','1')
.style("stroke-width", '.5')
.style("stroke", "rgb(0,0,0)")
*/

g.selectAll("path5")
.data(parks.features)
.enter()
.append("path")
.attr('class','outlines')
.attr("d", path5)
.style("fill", "rgb(170,226,173)")
.style("fill-opacity", ".5")
.style('stroke-opacity','.4')
.style("stroke-width", '.5')
.style("stroke", "none")

g.selectAll("path5")
.data(pParcels.features)
.enter()
.append("path")
.attr('class','outlines')
.attr("d", path5)
.style("fill", "red")
.style("fill-opacity", ".2")
.style('stroke-opacity','.7')
.style("stroke-width", '.5')
.style("stroke", "red")

g.selectAll("path5")
.data(parcels.features)
.enter()
.append("path")
.attr('class','outlines')
.attr("d", path5)
.style("fill", "rgb(220,220,220)")
.style("fill-opacity", ".2")
.style('stroke-opacity','.4')
.style("stroke-width", '.5')
.style("stroke", "rgb(140,140,140)")
g.selectAll("path2") //d3 geopath
.data(streets.features) //get data to define path
.enter() //there are more data than elements, this selects them
.append("path") //appends path to data
.attr('class','outlines')
.attr("d", path2) //The d attribute defines a path to be drawn, only applies to appended elements
.style("fill", "none")
.style('stroke-opacity','1')
.style("stroke-width", '2')
.style("stroke", "rgb(250,250,250)")

g.selectAll("path3")
.data(rensBldg.features)
.enter()
.append("path")
.attr('class','outlines')
.attr("d", path3)
.style("fill", "white")
.style("fill-opacity", "1")
.style('stroke-opacity','.4')
.style("stroke-width", '1')
.style("stroke", "rgb(0,0,0)")
g.selectAll("path3")
.data(Solid.features)
.enter()
.append("path")
.attr('class','outlines')
.attr("d", path3)
.style("fill", "rgb(240,240,240)")
.style("fill-opacity", ".25")
.style('stroke-opacity','.2')
.style("stroke-width", '.25')
.style("stroke", "rgb(0,0,0)")

g.selectAll("path2") //d3 geopath
.data(contour.features) //get data to define path
.enter() //there are more data than elements, this selects them
.append("path") //appends path to data
.attr('class','outlines')
.attr("d", path2) //The d attribute defines a path to be drawn, only applies to appended elements
.style("fill", "none")
.style('stroke-opacity','.5')
.style("stroke-width", '.5')
.style("stroke", "rgb(200,200,200)")
g.selectAll("path5")
.data(river.features)
.enter()
.append("path")
.attr('class','outlines')
.attr("d", path5)
.style("fill", "rgb(100,100,100)")
.style("fill-opacity", ".1")
.style('stroke-opacity','.6')
.style("stroke-width", '.5')
.style("stroke", "none")


var c = svg.selectAll("circle") //d3 geopath
.data(spots)
.enter() //there are more data than elements, this selects them
.append("circle") //appends path to data
.attr("cx", function(d) {return projection([d.long,d.lat])[0]})
.attr("cy", function(d) {return projection([d.long,d.lat])[1]})
.attr('r',spotSize)
.attr('fill',colorType)
.style('fill-opacity','1')
.on('mouseover', spotText)
.on('mouseout', removespotText)


function colorType(d,i){
var color = 'red'
if(d.type=='food'){color = 'rgb(255,255,'+y+')'}
if(d.type=='apartment'){color = 'cyan'}
if(d.type=='education'){color = 'blue'}
if(d.type=='care'){color = 'black'}
if(d.type=='park'){color = 'green'}

return color
}
svg.append('text')
// .attr('class', 'spots')
.attr('x', '150')
.attr('y', '220')
.attr('font-family','Helvetica')
.attr('font-size', '1em')
.attr('text-anchor', 'start')
.attr('font-weight','bold')
.text(totalValues[0])

svg.append('text')
// .attr('class', 'spots')
.attr('x', '90')
.attr('y', '220')
.attr('font-family','Helvetica')
.attr('font-size', '1em')
.attr('text-anchor', 'start')
.attr('font-weight','light')
.text("cost:")


svg.append('text')
// .attr('class', 'spots')
.attr('x', '150')
.attr('y', '190')
.attr('font-family','Helvetica')
.attr('font-size', '1em')
.attr('text-anchor', 'start')
.attr('font-weight','bold')
.text(totalValues[1])

svg.append('text')
// .attr('class', 'spots')
.attr('x', '50')
.attr('y', '190')
.attr('font-family','Helvetica')
.attr('font-size', '1em')
.attr('text-anchor', 'start')
.attr('font-weight','light')
.text("Happiness:")






function spotText(event,d){
d3.select(this).attr('fill','magenta')

svg.append('text')
.attr('class', 'spots')
.attr('x', '150')
.attr('y', '150')
.attr('font-family','Helvetica')
.attr('font-size', '1em')
.attr('text-anchor', 'start')
.attr('font-weight','bold')
.text(d.name)

svg.append('text')
.attr('class', 'spots')
.attr('x', '150')
.attr('y', '165')
.attr('font-family','Helvetica')
.attr('font-size', '.7em')
.attr('text-anchor', 'start')
.attr('font-weight','normal')
.text(d.description)

svg.append('line')
.attr('class','spotLine')
.attr('x1','150')
.attr('y1','150')
.attr('x2','350')
.attr('y2','150')
.style('stroke-width', '1')
.style('stroke', 'black')
}
function removespotText(event,d){
d3.select(this).attr('fill',colorType)
d3.selectAll('text.spots').remove()
d3.selectAll('line.spotLine').remove()
}



return svg.node();
}
Insert cell
contour = FileAttachment("contour.geojson").json()
Insert cell
river = FileAttachment("water v2.geojson").json()
Insert cell
rensBldg = FileAttachment("aa RensBuildingFP.geojson").json()
Insert cell
pParcels = FileAttachment("State Parcels v1.geojson").json()
Insert cell
parcels = FileAttachment("parcel.geojson").json()
Insert cell
Solid = FileAttachment("albany bldg v1.geojson").json()
Insert cell
Insert cell
streets = FileAttachment("streets v1.geojson").json()
Insert cell
Insert cell
spots = d3.csv(spotsLink,d3.autoType)
Insert cell
parks = FileAttachment("parks v1.geojson").json()
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