chart = {
const width = 960,
height = 550;
const svg = d3.create("svg")
.attr("viewBox", [50, 50, width-100, height-100]);
var projection = d3
.geoMercator()
.fitSize([width - 50, height - 50], planBoundary);
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");
.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", '.75')
.style("stroke", "rgb(0,0,0)")
*/
g.selectAll("path3") //d3 geopath
.data(allLinesSimplified.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(240,240,240)")
.style("fill-opacity", ".5")
.style('stroke-opacity','.4')
.style("stroke-width", '.5')
.style("stroke", "rgb(0,0,0)")
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',3)
.attr('fill',colorType)
.style('fill-opacity','1')
.style('stroke','black')
.style('stroke-width','1')
.on('mouseover',spottext)
.on('mouseout',removetext)
function colorType(d,i) {
var color = 'black'
if (d.type=='Food'){color='cyan'}
if (d.type=='Work'){color='red'}
if (d.type=='Living'){color='green'}
if (d.type=='Shopping'){color='blue'}
return color
}
function spottext(i,d) {
svg.append("text")
.attr('class','spotInfo')
.attr('x','100')
.attr('y','100')
.attr('font-family','Helvetica')
.attr('font-size','1em')
.attr('font-weight','Bold')
.attr('text-anchor','start')
.text(d.name)
svg.append("text")
.attr('class','spotInfo')
.attr('x','100')
.attr('y','115')
.attr('font-family','Helvetica')
.attr('font-size','.8em')
.attr('font-weight','normal')
.attr('text-anchor','start')
.text(d.desc)
svg.append('line')
.attr('class','spotLine')
.attr('x1','115')
.attr('y1','120')
.attr('x2',projection([d.long,d.lat])[0])
.attr('y2',projection([d.long,d.lat])[1])
.attr('stroke-width','.5')
.attr('stroke','black')
}
function removetext(i,d) {
d3.selectAll('text.spotInfo').remove()
d3.selectAll('line.spotLine').remove()
}
svg.append("text")
// .attr('class','spotInfo')
.attr('x','130')
.attr('y','460')
.attr('font-family','Helvetica')
.attr('font-size','.6em')
.attr('font-weight','200')
.attr('text-anchor','end')
.text("Total Cost: ")
svg.append("text")
// .attr('class','spotInfo')
.attr('x','130')
.attr('y','480')
.attr('font-family','Helvetica')
.attr('font-size','.6em')
.attr('font-weight','200')
.attr('text-anchor','end')
.text("Total Happiness: ")
svg.append("text")
// .attr('class','spotInfo')
.attr('x','130')
.attr('y','460')
.attr('font-family','Helvetica')
.attr('font-size','.6em')
.attr('font-weight','Bold')
.attr('text-anchor','start')
.text(totalValues[0])
svg.append("text")
// .attr('class','spotInfo')
.attr('x','130')
.attr('y','480')
.attr('font-family','Helvetica')
.attr('font-size','.6em')
.attr('font-weight','Bold')
.attr('text-anchor','start')
.text(totalValues[1])
if (totalValues[0] > 100){
svg.append("text")
// .attr('class','spotInfo')
.attr('x','480')
.attr('y','275')
.attr('font-family','Helvetica')
.attr('font-size','10em')
.attr('font-weight','Bold')
.attr('text-anchor','middle')
.attr('fill','red')
.text("BROKE :/")
}
if (totalValues[0] < 100){
if (totalValues[1] > 30){
svg.append("text")
// .attr('class','spotInfo')
.attr('x','480')
.attr('y','275')
.attr('font-family','Helvetica')
.attr('font-size','6em')
.attr('font-weight','Bold')
.attr('text-anchor','middle')
.attr('fill','green')
.text("Un-Depressed!")
}
}
return svg.node();
}