Public
Edited
Dec 14, 2023
Insert cell
# UD Fall 2023 - New Orleans Vacant Lots
Insert cell
d3 = require("d3@6")
Insert cell
chart = {
const width = 2660,
height = 1660;
const svg = d3.create("svg")
.attr("viewBox", [600, 615, width-1950, height-1145]); //use in tandom to create a better square
var projection = d3
.geoMercator()
.fitSize([width - 50, height - 50], bbox);

var path1 = d3.geoPath().projection(projection);//any path that comes from qgis
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")
.data(bldgs.features)
.enter()
.append("path")
.attr('class','outlines')
.attr("d", path3)
.style("fill", "rgb(240,240,240)")
.style("fill-opacity", "1")
.style('stroke-opacity','.1')
.style("stroke-width", '.5')
.style("stroke", "black")

g.selectAll("path3") //d3 geopath
.data(traffic.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", '3')
.style("stroke", "blue")

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", '1')
.style("stroke", "red")
var c = svg.selectAll("circle")
.data(mypoints.features)
.enter()
.append("circle")
.attr("cx", function(d) {return path1.centroid(d)[0]})
.attr("cy", function(d) {return path1.centroid(d)[1]})
.attr('r',1)
.style('fill','cyan')
.style('fill-opacity','1')
.on('mouseover',fireText)
.on('mouseout',removefireText)

function fireText(event,d){
console.log(d)

svg
.append("text")
.attr('x','625')
.attr('y','750')
.attr('class','mypoints_position')
.style('font-family','helvetica')
.style('font-size','10px')
.style('font-weight','light')
.text(d.properties.description)

var wrap = svg.selectAll("text.mypoints_position")
.each(function(d, i) { wrap_text(d3.select(this), 100) });

svg
.append("line")
.attr('x1','750')
.attr('y1','740')
.attr('x2', path1.centroid(d)[0])
.attr('y2', path1.centroid(d)[1])
.attr('class','fireLine')
.style("stroke-width", '3')
.style("stroke", "rgb(0,0,0)")
.style('stroke-dasharray', '6 4')
}

function removefireText(){
d3.selectAll('text.mypoints_position').remove()
d3.selectAll('line.fireLine').remove()
}

c.enter().append("circle")
.data(fire)
.enter()
.append("circle")
.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)
.style('stroke','black')
.style('stroke-width','1')
.style('fill','cyan')
.style('fill-opacity','1')
var t = svg.selectAll("text")
.data(mypoints.features)
.enter()
.append("text")
.attr("x", function(d) {return path1.centroid(d)[0]})
.attr("y", function(d) {return path1.centroid(d)[1]-3})
.style('font-family','helvetica')
.style('font-size','5px')
.style('text-anchor','middle')
.style('font-weight','bold')
.text(function(d) {return d.properties.name})

var z = svg.selectAll("text")
.data(fire.features)
.enter()
.append("text")
.attr("x", function(d) {return path4.centroid(d)[0]})
.attr("y", function(d) {return path4.centroid(d)[1]-7})
.style('font-family','helvetica')
.style('font-size','8px')
.style('text-anchor','middle')
.style('font-weight','bold')
.text(function(d) {return d.properties.name})

svg
.append("text")
.attr('x','620')
.attr('y','660')
.style('font-family','helvetica')
.style('font-size','50px')
.style('font-weight','bold')
.text('New Orleans')

svg
.append("text")
.attr('x','620')
.attr('y','720')
.style('font-family','helvetica')
.style('font-size','20px')
.style('font-weight','bold')
.text('Neighborhood:')

svg
.append("line")
.attr('x1','620')
.attr('y1','680')
.attr('x2','920')
.attr('y2','680')
.style("stroke-width", '10')
.style("stroke", "rgb(0,0,0)")
return svg.node();
}
Insert cell
bbox = FileAttachment("Bbox.geojson").json()
Insert cell
streets = FileAttachment("streets.geojson").json()
Insert cell
bldgs = FileAttachment("wards.geojson").json()
Insert cell
traffic = FileAttachment("Rivers.geojson").json()
Insert cell
fire = FileAttachment("firre4.geojson").json()
Insert cell
mypoints = FileAttachment("vacant_lots.geojson").json()
Insert cell
newspots = "https://docs.google.com/spreadsheets/d/e/2PACX-1vTS_GG1TTa5r13v7BXc6ZRO0NYMtDpPqVzfREZYS5EW0dGJcl8IJBtUtoWn6qasLt38DN8RlVB0RQ8F/pub?output=csv"
Insert cell
newspots_2 = d3.csv(newspots,d3.autoType)
Insert cell
import { wrap_text, wrap_text_nchar } from "@ben-tanen/svg-text-and-tspan-word-wrapping"
Insert cell
tester = FileAttachment("newnewnew.txt").text()
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