Public
Edited
Jul 16, 2024
Insert cell
Insert cell
chart = {
const width = 900,//pixel size of the map
height = 900;
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], cityLinesWeb);

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



//static lines from qgis
staticLines(path3, boxBlack.features,"black",'1','1',"none")
staticLines(path4, parksWeb2.features,"rgb(111,193,67)",'.25','.1',"rgb(0,255,0)")
staticLines(path4, cityLinesWeb.features,"none",'1','1',"rgb(241,165,77)")
staticLines(path3, subwayLineWeb.features,"none",'1','4',"yellow")





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)
}
//lines from rhino
polyline(lines,'rgb(240,31,36)','1.2','1.2','rgb(240,31,36)')
polyline(text,'yellow','4','0.5','black')

//static points from qgis
staticCircles(subwayWeb.features,'5','rgb(235,220,40)','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]})
.attr("cy",function(d) {return path.centroid(d)[1]})
.attr('r', r)
.attr('fill', sfill)
.style('fill-opacity',sOpac)
.style("stroke-width", sWidth)
}



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

g.enter().append("polyline")
.data(data) //get data to define path
.enter() //there are more data than elements, this selects them
.append('polyline')
.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',sOpac)
.style("stroke-width", sW)
.style("stroke", stroke)
}




/*
//points from spreadsheet
c.enter().append('circle')
.data(spots) //get data to define path
.enter() //there are more data than elements, this selects them
.append("circle") //appends path to data
.attr('class','spots')
.attr('cx',function(d) {return projection([d.long,d.lat])[0]})
.attr("cy",function(d) {return projection([d.long,d.lat])[1]})
.attr('r', 3)
.attr('fill', 'black')
.style('fill-opacity','1')
.style("stroke-width", "1")
*/



return svg.node();
}

Insert cell
lines = FileAttachment("Lines@2.txt").tsv({array:true})

Insert cell
text = FileAttachment("Text.txt").tsv({array:true})
Insert cell
boxBlack = FileAttachment("box black.geojson").json()

Insert cell
parksWeb2 = FileAttachment("Parks Web@2.geojson").json()
Insert cell
subwayLineWeb = FileAttachment("Subway line Web.geojson").json()

Insert cell
subwayWeb = FileAttachment("Subway Web.geojson").json()
Insert cell
graphic_test = FileAttachment("graphic_test.txt").tsv({array:true})

Insert cell
cityLinesWeb = FileAttachment("City Lines Web@2.geojson").json()
Insert cell
parksWeb = FileAttachment("Parks Web@1.geojson").json()
Insert cell
restrooms = FileAttachment("restrooms.geojson").json()
Insert cell
subways = FileAttachment("subways.geojson").json()
Insert cell
parks = FileAttachment("parks.geojson").json()
Insert cell
Insert cell
spots = d3.csv(spotsLink,d3.autoType)

Insert cell
bbox1 = FileAttachment("bbox@1.txt").text()
Insert cell
import { wrap_text, wrap_text_nchar } from "@ben-tanen/svg-text-and-tspan-word-wrapping"

Insert cell
untitled = FileAttachment("tvd.geojson").json()
Insert cell
untitled1 = FileAttachment("123.geojson").json()

Insert cell
tvd1 = FileAttachment("tvd@1.geojson").json()

Insert cell
parks1 = FileAttachment("parks.qmd")


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