chart = {
const width = 900,
height = 1050;
const svg = d3.create("svg")
.attr("viewBox", [50, 50, width-100, height-100]);
var projection = d3
.geoMercator()
.fitSize([width - 50, height - 50], gbox);
var path1 = d3.geoPath().projection(projection);
var path2 = d3.geoPath().projection(projection);
var path3 = d3.geoPath().projection(projection);
var g = svg.append("g").attr("id", "paths");
g.selectAll("path2")
.data(streets.features)
.enter()
.append("path")
.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','.75')
.style("stroke-width", '2')
.style("stroke", "rgb(250, 149, 7)")
g.selectAll("path3") //d3 geopath
.data(gbld.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(250, 149, 7)")
.style("fill-opacity", ".1")
.style('stroke-opacity','.4')
.style("stroke-width", '.75')
.style("stroke", "rgb(250, 149, 7)")
var c = svg.selectAll("circle") //d3 geopath
.data(spots)
.enter() //there are more data than elements, this selects them
.append("circle") //appends path to data
.attr("cx", function(d) {return projection([d.long,d.lat])[0]})
.attr("cy", function(d) {return projection([d.long,d.lat])[1]})
.attr('r','6')
.attr('fill',colorType)
.style('fill-opacity','1')
.style('stroke',"rgb(250, 149, 7)")
.style('stroke-width','5')
.style('stroke-opacity','.25')
.on('mouseover',spotText)
.on('mouseout',removeText)
function colorType(d,i){
var color = 'rgb(187,231,254)'
if(d.type=='bar'){
color = 'rgb(187,231,254)'
}
if(d.type=='food'){
color = 'rgb(187,231,254)'
}
return color
}
svg.append("text")
// .attr('class','spotInfo')
.attr('x','600')
.attr('y','160')
.attr('font-family','Helvetica')
.attr('font-size','1em')
.attr('font-weight','bold')
.attr('font-anchor','start')
.text(totalValues[0])
svg.append("text")
// .attr('class','spotInfo')
.attr('x','560')
.attr('y','160')
.attr('font-family','Helvetica')
.attr('font-size','1em')
// .attr('font-weight','bold')
.attr('font-anchor','start')
.text('cost:')
svg.append("text")
// .attr('class','spotInfo')
.attr('x','645')
.attr('y','180')
.attr('font-family','Helvetica')
.attr('font-size','1em')
.attr('font-weight','bold')
.attr('font-anchor','start')
.text(totalValues[1])
svg.append("text")
// .attr('class','spotInfo')
.attr('x','560')
.attr('y','180')
.attr('font-family','Helvetica')
.attr('font-size','1em')
// .attr('font-weight','bold')
.attr('font-anchor','start')
.text('happiness:')
function spotText(i,d){
svg.append("text")
.attr('class','spotInfo')
.attr('x','100')
.attr('y','100')
.attr('font-family','Helvetica')
.attr('font-size','2em')
.attr('font-weight','bold')
.attr('font-anchor','start')
.text(d.name)
svg.append("text")
.attr('class','spotInfo')
.attr('x','100')
.attr('y','130')
.attr('font-family','Helvetica')
.attr('font-size','1em')
.attr('font-weight','bold')
.attr('font-anchor','start')
.text(d.description)
svg.append('line')
.attr('class','spotLine')
.attr('x1','180')
.attr('y1','110')
.attr('x2',projection([d.long,d.lat])[0])
.attr('y2',projection([d.long,d.lat])[1])
.attr('stroke-width','.5')
.attr('stroke','black')
.attr('stroke-dasharray','4 4')
}
function removeText(i,d){
d3.selectAll('text.spotInfo').remove()
d3.selectAll('line.spotLine').remove()
}
return svg.node();
}