Public
Edited
Feb 6, 2024
Insert cell
# base map - UD Spring 2024 - Kriti's Version 4
Insert cell
d3 = require("d3@6")
Insert cell
chart = {
const width = 960,
height = 900;
const svg = d3.create("svg")
.attr("viewBox", [50, 50, width-50, height-50]);

// Use Mercator projection
var projection = d3
.geoMercator()
.fitSize([width - 50, height - 50], boundingBox);

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("path2") //d3 geopath
.data(parisCountiesLayer.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", "rgb(128,128,128)")
.style("fill-opacity", ".05")
.style('stroke-opacity','.25')
.style("stroke-width", '.5')
.style("stroke", "rgb(128,128,128)")

g.selectAll("path3") //d3 geopath
.data(parisGreenSpacesLayer.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(153,184,147)")
.style("fill-opacity", ".5")
.style('stroke-opacity','1')
.style("stroke-width", '.4')
.style("stroke", "rgb(153,184,147)")

g.selectAll("path4") //d3 geopath
.data(parisBikePathLayer.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", "none")
.style("fill-opacity", ".5")
.style('stroke-opacity','1')
.style("stroke-width", '.5')
.style("stroke", "rgb(0,0,100)")

g.selectAll("path5") //d3 geopath
.data(parisRiversLayer.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(149,200,216)")
.style("fill-opacity", "1")
.style('stroke-opacity','1')
.style("stroke-width", '1')
.style("stroke", "rgb(149,200,216)")

g.selectAll("path6") //d3 geopath
.data(parisBuiltAreasLayer.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(128,128,128)")
.style("fill-opacity", ".1")
.style('stroke-opacity','1')
.style("stroke-width", '.25')
.style("stroke", "rgb(128,128,128)")

var c = svg.selectAll("circle") //d3 geopath
.data(Dream_Vacation)
.enter() //there are more data than elements, this selects them
.append("circle") //appends path to data
.attr('class','Vacationpts')
.attr("cx", function(d) {return projection([d.Long,d.Lat])[0]})
.attr("cy", function(d) {return projection([d.Long,d.Lat])[1]})
.attr('r',5)
.style('fill','rgb(166, 166, 166)')
.style('fill-opacity','1')
.on('mouseover',Vacationinfo)//listens for a mousover, and calls function
.on('mouseout',Vacationinfoout)

svg
.append('line')
//.attr('class','steakLine')
.attr('x1','125')
.attr('y1','725')
.attr('x2','400')
.attr('y2','725')
.style('stroke','rgb(166, 166, 166)')
.style('stroke-width','1')
.style('stroke-dasharray', '4,4,8,8')
function Vacationinfo(event,d){
d3.select(this).style('fill','red')


svg
.append('text')
.attr('class', 'VacationText')
.attr('x', '150')
.attr('y', '500')
.style("font-family", "Helvetica")
.style('font-size', '.75em')
.style('fill', 'rgb(166, 166, 166)')
.style('text-anchor', 'start')
.text(d.Name);

svg
.append('text')
.attr('class', 'VacationText')
.attr('x', '150')
.attr('y', '600')
.style("font-family", "Helvetica")
.style('font-size', '.5em')
.style('fill', 'rgb(166, 166, 166)')
.style('text-anchor', 'start')
.text(d.Rating);

svg
.append('text')
.attr('class', 'VacationText')
.attr('x', '150')
.attr('y', '700')
.style("font-family", "Helvetica")
.style('font-size', '.5em')
.style('fill', 'rgb(166, 166, 166)')
.style('text-anchor', 'start')
.text(d.Description);

svg
.append('line')
.attr('class','VacationLine')
.attr('x1','125')
.attr('y1','725')
.attr('x2','400')
.attr('y2','725')
.style('stroke','rgb(166, 166, 166)')
.style('stroke-width','1')
}
function Vacationinfoout(event,d){
d3.selectAll('circle.Vacationpts').style('fill','rgb(166, 166, 166)')
d3.selectAll('text.VacationText').remove()
d3.selectAll('line.VacationLine').remove()
d3.selectAll('rect.VacationRect').remove();
}
/*
var line = svg.append('line')
.data(Dream_Vacation)
.attr('class','VacationLine')
.attr('x1', '150')
.attr('y1', '725')
.attr('x2', function(d) {return projection([d.Long,d.Lat])[0]})
.attr('y2', function(d) {return projection([d.Long,d.Lat])[1]})
.style('stroke','rgb(166, 166, 166)')
.style('stroke-width','1');
*/


//var bbox = text.node().getBBox();
var rect = svg.append('rect')
.attr('class', 'VacationRect')
.attr('x', bbox.x - 5)
.attr('y', bbox.y - 5)
.attr('width', bbox.width + 10)
.attr('height', bbox.height + 10)
.style('fill', 'none')
.style('stroke', 'rgb(166, 166, 166)')
.style('stroke-width', '1');

/*
function handleMouseOut(){
d3.select(this).style('fill','rgb(166, 166, 166)');
Name.remove();
Rating.remove();
Description.remove();
line.remove();
rect.remove();
}
*/
//c.on('mouseout', handleMouseOut);
return svg.node();
}


Insert cell
subSts = FileAttachment("sub_stops.geojson").json()
Insert cell
bldgs = FileAttachment("bldgs.geojson").json()
Insert cell
bbox = FileAttachment("site_boundary.geojson").json()
Insert cell
subLns = FileAttachment("subway_lines.geojson").json()
Insert cell
bbox_01 = FileAttachment("bbox_01.geojson").json()
Insert cell
helena_roads = FileAttachment("helena_roads_01.geojson").json()
Insert cell
trails = FileAttachment("trails.geojson").json()
Insert cell
bbox_02 = FileAttachment("bbox_02.geojson").json()
Insert cell
streams = FileAttachment("streams.geojson").json()
Insert cell
Insert cell
steak = d3.csv(steak_link,d3.autoType)
Insert cell
boundingBox = FileAttachment("Bounding Box.geojson").json()
Insert cell
parisCountiesLayer = FileAttachment("Paris Counties Layer .geojson").json()
Insert cell
parisGreenSpacesLayer = FileAttachment("Paris Green Spaces Layer .geojson").json()
Insert cell
parisBikePathLayer = FileAttachment("Paris Bike Path Layer .geojson").json()
Insert cell
Insert cell
Dream_Vacation = d3.csv(Dream_Vacation_link, d3.autoType)
Insert cell
parisRiversLayer = FileAttachment("Paris Rivers Layer .geojson").json()
Insert cell
parisBuiltAreasLayer = FileAttachment("Paris Built Areas Layer.geojson").json()
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