Public
Edited
Feb 9, 2023
Insert cell
# base map - Feb 01 2023
Insert cell
d3 = require("d3@6")
Insert cell
scSteps = ["Raw Extraction", "Material Processing", "Material Distribution", "Job Site", "Full Supply Chain"]
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], nys_boundary);

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 g = svg.append("g").attr("id", "paths");

g.selectAll("path3") //d3 geopath
.data(nys_map.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", path3) //The d attribute defines a path to be drawn, only applies to appended elements
.style("fill", "black")
.style("fill-opacity", "1")
.style('stroke-opacity','1')
.style("stroke-width", '0.5')
.style("stroke", "red")

var cir = svg.selectAll("circle") //d3 geopath
.data(nyspots) //get data to define path
.enter() //there are more data than elements, this selects them
.append("circle") //appends path to data
.attr('class','nyspots')
.attr("r", "3") //The d attribute defines a path to be drawn, only applies to appended elements
.attr("cx", function(d) {return projection([d.Long,d.Lat])[0]})
.attr("cy", function(d) {return projection([d.Long,d.Lat])[1]})
.style("fill", "cyan")
.style("fill-opacity", "1")
.style('stroke-opacity','1')
.style("stroke-width", '.5')
.style("stroke", "rgb(0,0,0)")


function fillColor(d,i){

var color = "rgb(200,0,200)"

if(d.Type=="food"){color = "rgb(255,0,0)"}
if(d.Type=="game"){color = "rgb(0,0,255)"}
return color
}

cir.enter().append("circle") //d3 geopath
.data(scSteps) //get data to define path
.enter() //there are more data than elements, this selects them
.append("circle") //appends path to data
//.attr('class','outlines')
.attr("r", "5") //The d attribute defines a path to be drawn, only applies to appended elements
.attr("cx", "150")
.attr("cy", function(d,i) {return 150+(i*20)})
.style("fill", "white")
.style("fill-opacity", "1")
.style('stroke-opacity','1')
.style("stroke-width", '2')
.style("stroke", "red")
.on("mouseover", animateMap)
.on("mouseout", stopAnimateMap)

function animateMap(event,d){

var tColor = "cyan"

if(d == "Raw Extraction"){tColor = "red"}
var circle = svg.selectAll(circle.nyspots).attr('r',8)
svg
.append("text")
.attr("x", "300")
.attr("y", "700")
.attr("class", "mouseText")
.style("font-family", "Helvetica")
.style("font-weight", "light")
.style("text-anchor", "start")
.style("font-size", "10px")
.style("fill", tColor)
.style("fill-opacity", "1")
.text(d)
}
function stopAnimateMap(event,d){
svg.selectAll("text.mouseText").remove()
}
var tx = svg.selectAll("text") //d3 geopath
.data(scSteps) //get data to define path
.enter() //there are more data than elements, this selects them
.append("text") //appends path to data
//.attr('class','outlines')
.attr("r", "3") //The d attribute defines a path to be drawn, only applies to appended elements
.attr("x", "160")
.attr("y", function(d,i) {return 155+(i*20)})
.style("font-family", "Helvetica")
.style("font-weight", "light")
.style("text-anchor", "start")
.style("font-size", "10px")
.style("fill", "black")
.style("fill-opacity", "0.5")
.style('stroke-opacity','1')
.style("stroke-width", '0.5')
.style("stroke", "rgb(0,0,0)")
.text(function(d) {return d})

return svg.node();
}
Insert cell
hammertest = FileAttachment("hammerTest.txt").text()
Insert cell
usa_outline = FileAttachment("usa_outline.geojson").json()
Insert cell
testtext = FileAttachment("testtext.txt").tsv({array:true})
Insert cell
bldgs = FileAttachment("bldgs.geojson").json()
Insert cell
bbox = FileAttachment("site_boundary.geojson").json()
Insert cell
boundary = FileAttachment("nyc_boundary.geojson").json()
Insert cell
nys_boundary = FileAttachment("nys_boundary.geojson").json()
Insert cell
nys_map = FileAttachment("usa_outline.geojson").json()
Insert cell
usa_boundary = FileAttachment("usa_boundary.geojson").json()
Insert cell
Insert cell
nyspots = d3.csv(nyspotsLink,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