Public
Edited
Dec 17
Insert cell
Insert cell
chart = {
const width = 900,//pixel size of the map
height = 600;
const svg = d3.create("svg")
.attr("viewBox", [0, 0, width-50, height-10]);

// Use Mercator projection
var projection = d3
.geoMercator()//projection system used
.fitSize([width, height], bbox_usa);//out bounding box is here

var path = d3.geoPath().projection(projection);//need one of these for each line layer from qgis
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.selectAll('g').attr("id", "paths");//qgis lines variable //one variable for each geometry type
var c = svg.selectAll("circle")//for circles
var p = svg.selectAll("polyline")//for polylines from rhino
var t = svg.selectAll("text")
var l = svg.selectAll("line")


//static lines from qgis
//staticLines(path3, subways.features,"none",1,.5,"rgb(180,180,180)")
staticLines(path4, usaState.features,"rgb(100,200,200)",'.25','.1',"rgb(1,255,255)")
staticLines(path5, redline_usa.features,"none",'1','.25',"rgb(200,0,0)")

function staticLines(path, data, sfill, sOpac, sW, stroke){

g.enter().append("path")
.data(data) //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", path) //The d attribute defines a path to be drawn, only applies to appended elements
.style("fill", sfill)
.style('stroke-opacity',sOpac)
.style("stroke-width", sW)
.style("stroke", stroke)
}
//static points from qgis
staticCircles(cityPoint.features,'5','black','1',"0")

function staticCircles(data,r,sfill, sOpac, sWidth){

c.enter().append('circle')
.data(data) //get data to define path
.enter() //there are more data than elements, this selects them
.append("circle") //appends path to data
.attr('cx',function(d) {return path.centroid(d)[0]-8})
.attr("cy",function(d) {return path.centroid(d)[1]-5})
.attr('r', r)
.attr('fill', sfill)
.style('fill-opacity',sOpac)
.style("stroke-width", sWidth)
.on("mouseover", addText)
}
function addText(event,d){
svg//draw text
.append("text") //appends path to data
.attr("class", "dText")
.attr('x', path.centroid(d)[0])
.attr("y", path.centroid(d)[1])
.attr("fill", "black")
.style("font-family", "helvetica")
.style("font-size", "15px")
.text(d.properties.City)

}

//lines from rhino
polyline(rec,"rgb(200,0,0)",'1','0','none')
polyline(pointCity,'black','1','2','black')

function polyline(data, sfill, sOpac, sW, stroke,classVar){

g.enter().append("polyline")
.data(data) //get data to define path
.enter() //there are more data than elements, this selects them
.append('polyline')
.attr('class',classVar)
.attr("points", function(d){return d}) //The d attribute defines a path to be drawn, only applies to appended elements
.style("fill", sfill)
.style('stroke-opacity',1)
.style("stroke-width", sW)
.style("stroke", stroke)
}
svg//draw text
.append("text") //appends path to data
.attr('class','mText')
.attr('x',80)
.attr("y",500)
.attr('fill', 'black')
.style('font-family','helvetica')
.style("font-size", "11px")
.text("Areas with redlining distribution")

svg//draw text
.append("text") //appends path to data
.attr('class','mText')
.attr('x',80)
.attr("y",520)
.attr('fill', 'black')
.style('font-family','helvetica')
.style("font-size", "11px")
.text("City under study")
return svg.node();
}
Insert cell
untitled = FileAttachment("11.txt").tsv({array:true})
Insert cell
pointCity = FileAttachment("point city@1.txt").tsv({array:true})
Insert cell
rec = FileAttachment("rec.txt").tsv({array:true})
Insert cell
cityPoint = FileAttachment("city point.geojson").json()
Insert cell
redline_usa = FileAttachment("redline_USA.geojson").json()
Insert cell
usaState = FileAttachment("USA State.geojson").json()
Insert cell
bbox_usa = FileAttachment("bbox_USA.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