Public
Edited
Feb 9, 2023
Insert cell
# base map - Feb 01 2023 - Kelvin's Version
Insert cell
d3 = require("d3@6")
Insert cell
scSteps = ["Raw Extraction", "Material Processing", "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], boundingboxplswork);

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(statev21.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", "rgb(240,240,240)")
.style("fill-opacity", ".5")
.style('stroke-opacity','.4')
.style("stroke-width", '.5')
.style("stroke", "rgb(0,0,0)")

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','outlines')
.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]})
.attr("class",nySpots)
.style("fill", fillcolor)
.style("fill-opacity", ".5")
.style('stroke-opacity','.4')
.style("stroke-width", '2')
.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", "4") //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", "red")
.style("fill-opacity", "0")
.style('stroke-opacity','.4')
.style("stroke-width", '2')
.style("stroke", "rgb(0,0,0)")
.on("mouseover",animateMap)
.on("mouseout",stopAnimateMap)

function animateMap(event,d){

var tColor = "cyan"

if(d == "Raw Extraction"){
tColor = "yellow"

p.enter().append("polyline")//use this for all polylines after the first polyline
.data(faclines2) //get data to define path
.enter() //there are more data than elements, this selects them
.append("polyline") //appends path to data
.attr('points', function(d){return d})
.attr("class", "mouseIcon")
.attr("transform", "translate(200,200)")
.style("fill", "magenta")
.style('stroke-opacity','1')
.style("stroke-width", '0')
.style("stroke", "rgb(0,0,0)")

p.enter().append("polyline")//use this for all polylines after the first polyline
.data(teststep2) //get data to define path
.enter() //there are more data than elements, this selects them
.append("polyline") //appends path to data
.attr('points', function(d){return d})
.attr("class","mouseIcon")
.style("fill", "none")
.style('stroke-opacity','1')
.style("stroke-width", '2')
.style("stroke", "rgb(0,0,0)")
.style("stroke-dasharray","4 4")

}
svg
.append("text") //appends path to data
//.attr('class','outlines')
.attr("x", "300")
.attr("y", "700")
.attr("class","mouseText")
.style("font-family", "Helvetica")
.style("font-weight", "bold")
.style("font-size", "10px")
.style("text-anchor", "start")
.style("fill", tColor)
.style("fill-opacity", "1")
.text(d)

var wrap = svg.selectAll("text.description")
.each(function(d, i) { wrap_text(d3.select(this), 150) });//control how long the text lines are
}
function stopAnimateMap(event,d){
svg.selectAll("text.mouseText").remove()
svg.selectAll("polyline.mouseIcon").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("x", "160")
.attr("y", function(d,i) {return 155+(i*20)})
.style("font-family", "Helvetica")
.style("font-weight", "bold")
.style("font-size", "10px")
.style("text-anchor", "start")
.style("fill", "black")
.style("fill-opacity", "1")
.text(function(d) {return d})
var p = svg.selectAll("polyline")
.data(lineTextFile) //get data to define path
.enter() //there are more data than elements, this selects them
.append("polyline") //appends path to data
.attr('points', function(d){return d})
.style("fill", "none")
.style('stroke-opacity','1')
.style("stroke-width", '2')
.style("stroke", "rgb(0,0,0)")
.style("stroke-dasharray","4 4")

var p = svg.selectAll("polyline")
.data(teststep2) //get data to define path
.enter() //there are more data than elements, this selects them
.append("polyline") //appends path to data
.attr('points', function(d){return d})
.style("fill", "none")
.style('stroke-opacity','1')
.style("stroke-width", '2')
.style("stroke", "rgb(0,0,0)")
.style("stroke-dasharray","4 4")

p.enter().append("polyline")//use this for all polylines after the first polyline
.data(faclines2) //get data to define path
.enter() //there are more data than elements, this selects them
.append("polyline") //appends path to data
.attr('points', function(d){return d})
.style("fill", "black")
.style('stroke-opacity','1')
.style("stroke-width", '0')
.style("stroke", "rgb(0,0,0)")
//.style("stroke-dasharray","4 4")





//.attr("cx", function(d) {return projection([d.long,d.lat])[0]})

return svg.node();
}
Insert cell
import { wrap_text, wrap_text_nchar } from "@ben-tanen/svg-text-and-tspan-word-wrapping"
Insert cell
teststep2 = FileAttachment("teststep2.txt").tsv({array:true})
Insert cell
teststep1 = FileAttachment("teststep1.txt").tsv({array:true})
Insert cell
statework = FileAttachment("statework.geojson").json()
Insert cell
faclines2 = FileAttachment("faclines2.txt").tsv({array:true})
Insert cell
facLines = FileAttachment("fac lines.txt").tsv({array:true})
Insert cell
boundingboxplswork = FileAttachment("boundingboxPLSWORK.geojson").json()
Insert cell
boundingboxv2 = FileAttachment("boundingboxv2.geojson").json()
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
statev21 = FileAttachment("statev2@1.geojson").json()
Insert cell
Insert cell
nySpots = d3.csv(nySpotsLink,d3.autoType())
Insert cell
lineTextFile = FileAttachment("line text file.txt").tsv({array:true})
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