chart = {
const width = 960,
height = 900;
const svg = d3.create("svg")
.attr("viewBox", [50, 50, width-100, height-100]);
var projection = d3
.geoMercator()
.fitSize([width - 50, height - 50], wbox);
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','1')
.style("stroke-width", '.5')
.style("stroke", "rgb(0,0,0)")
g.selectAll("path3") //d3 geopath
.data(wbldgs.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") //circle
.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',spotRadius)
.attr('fill',colorType) //add function to control color by 'type'
.style('fill-opacity','1')
.style('stroke','black')
.style('stoke-width','.5')
.on('mouseover',spotText)
.on('mouseout',removeText)
function colorType(d,i){ //non-listening event functions pass the data and then index
var color = 'black'
//if the type is live, make the color yellow
if(d.cuisine == 'Japanese'){color = 'rgb(0,128,128)'}
if(d.cuisine == 'American'){color = 'rgb(4,118,208)'}
if(d.cuisine == 'Vietnamese'){color = 'rgb(220,174,150)'}
if(d.cuisine == 'Chinese'){color = 'rgb(242,133,0)'}
return color
}
//create an if statement that says if the budget is too high, text pops up says it's too high
//create an if statement that says if happiness is above a certain level, and budget is below a certain level, you win!
if (totalValues[0] > 500) {
svg.append("text")
.attr('x','875')
.attr('y','800')
.attr('font-family','Helvetica')
.attr('font-size','1em')
.attr('font-weight','bold')
.attr('text-anchor','end')
.text("STOP DINING OUT AND")
svg.append("text")
.attr('x','875')
.attr('y','820')
.attr('font-family','Helvetica')
.attr('font-size','1em')
.attr('font-weight','bold')
.attr('text-anchor','end')
.text("GO COOK BY YOURSELF")
} else {
svg.append("text")
.attr('x','875')
.attr('y','800')
.attr('font-family','Helvetica')
.attr('font-size','1em')
.attr('font-weight','bold')
.attr('text-anchor','end')
.text("YEP STILL WITHIN THE BUDGET")
}
if (totalValues[1] == 165) {
svg.append("text")
.attr('x','75')
.attr('y','800')
.attr('font-family','Helvetica')
.attr('font-size','1em')
.attr('font-weight','bold')
.attr('text-anchor','start')
.text("GREAT JOB!")
svg.append("text")
.attr('x','75')
.attr('y','820')
.attr('font-family','Helvetica')
.attr('font-size','1em')
.attr('font-weight','bold')
.attr('text-anchor','start')
.text("YOU'RE TRULY A FOODIE NOW")
}
svg.append("text")
//.attr('class','spotInfo')
.attr('x','575')
.attr('y','190')
.attr('font-family','Helvetica')
.attr('font-size','.5em')
.attr('font-weight','regular')
.attr('text-anchor','start')
.text(totalValues[0])
svg.append("text")
//.attr('class','spotInfo')
.attr('x','575')
.attr('y','190')
.attr('font-family','Helvetica')
.attr('font-size','.5em')
.attr('font-weight','light')
.attr('text-anchor','end')
.text('COST=')
svg.append("text")
//.attr('class','spotInfo')
.attr('x','575')
.attr('y','200')
.attr('font-family','Helvetica')
.attr('font-size','.5em')
.attr('font-weight','regular')
.attr('text-anchor','start')
.text(totalValues[1])
svg.append("text")
//.attr('class','spotInfo')
.attr('x','575')
.attr('y','200')
.attr('font-family','Helvetica')
.attr('font-size','.5em')
.attr('font-weight','light')
.attr('text-anchor','end')
.text('HAPPINESS=')
function spotText(i,d) {
//what happen when mouseovering the spot
//name
svg.append("text")
.attr('class','spotInfo')
.attr('x','455')
.attr('y','150')
.attr('font-family','Helvetica')
.attr('font-size','.8em')
.attr('font-weight','bold')
.attr('text-anchor','left')
.text(d.name)
//description
svg.append("text")
.attr('class','spotInfo')
.attr('x','455')
.attr('y','162')
.attr('font-family','Helvetica')
.attr('font-size','.6em')
.attr('font-weight','regular')
.attr('text-anchor','left')
.text(d.description)
//spotlines
svg.append('line')
.attr('class','spotLine')
.attr('x1','457')
.attr('y1','170')
.attr('x2','457')
.attr('y2',projection([d.long,d.lat])[1])
.attr('stroke-width','1')
.attr('stroke','black')
.attr('stroke-dasharray','4 2 1 2')
svg.append('line')
.attr('class','spotLine')
.attr('x1',projection([d.long,d.lat])[0])
.attr('y1',projection([d.long,d.lat])[1])
.attr('x2','457')
.attr('y2',projection([d.long,d.lat])[1])
.attr('stroke-width','1')
.attr('stroke','black')
.attr('stroke-dasharray','4 2 1 2')
}
function removeText(i,d){
d3.selectAll('text.spotInfo').remove() //to remove a class of object
d3.selectAll('line.spotLine').remove()
}
function spotProfile3(event,d){
d3.select(this).attr('fill','lavenderblush')
svg.append('image')
.attr('href',Annie)
.attr('class','spotProfile3')
.attr('x', '100')
.attr('y','103')
.attr('width', 295)
.attr('height', 145)
}
return svg.node();
}