chcart = {
const width = 900,
height = 900;
const svg = d3.create("svg")
.attr("viewBox", [0, 0, width-50, height-10]);
var projection = d3
.geoMercator()
.fitSize([width, height], box_restaurant);
var path = d3.geoPath().projection(projection);
var path2 = d3.geoPath().projection(projection);
var path3 = d3.geoPath().projection(projection);
var path4 = d3.geoPath().projection(projection);
var path5 = d3.geoPath().projection(projection);
var g = svg.selectAll('g').attr("id", "paths");
var c = svg.selectAll("circle")
var p = svg.selectAll("polyline")
staticLines(path2, subways.features,"none",1,1,"rgb(0,200,100)")
staticLines(path3, parks.features,"rgb(200,225,200)",'.25','.1',"rgb(0,255,0)")
staticLines(path4, blocks.features,"none",1,.5,"rgb(8,8,8)",'.25','.1',"rgb(0,100,0)")
staticLines(path5, boroughs.features,"none",1,1,"rgb(8,8,8)")
function staticLines(path, data, sfill, sOpac, sW, stroke){
g.enter().append("path")
.data(data)
.enter()
.append("path")
.attr('class','outlines')
.attr("d", path)
.style("fill", sfill)
.style('stroke-opacity',sOpac)
.style("stroke-width", sW)
.style("stroke", stroke)
}
staticCircles(stations.features,'2','red','1',"0")
function staticCircles(data,r,sfill, sOpac, sWidth){
c.enter().append('circle')
.data(data)
.enter()
.append("circle")
.attr('cx',function(d) {return path.centroid(d)[0]})
.attr("cy",function(d) {return path.centroid(d)[1]})
.attr('r', r)
.attr('fill', sfill)
.style('fill-opacity',sOpac)
.style("stroke-width", sWidth)
}
c.enter().append('circle')
.data(restaurants)
.enter()
.append("circle")
.attr('class','spots')
.attr('cx',function(d) {return projection([d.Longitude,d.Latitude])[0]})
.attr("cy",function(d) {return projection([d.Longitude,d.Latitude])[1]})
.attr('r', 3)
.attr('fill', fillColor)
.style('fill-opacity','1')
.style("stroke-width", "1.5")
.style("stroke", "black")
.on("mouseover", addText)
.on("mouseout", removeText)
function fillColor(d){
var color = 'rgb(255,0,0)'
if(d.Rating == 1){color = 'rgb(255,0,0)'}
if(d.Rating == 1.5){color = 'rgb(255,100,0)'}
if(d.Rating == 2){color = 'rgb(255,165,0)'}
if(d.Rating == 2.5){color = 'rgb(255,255,0)'}
if(d.Rating == 3){color = 'rgb(0,100,0)'}
if(d.Rating == 3.5){color = 'rgb(144,238,144)'}
if(d.Rating == 4){color = 'rgb(50,205,50)'}
if(d.Rating == 4.5){color = 'rgb(50,205,50)'}
if(d.Rating == 5){color = 'rgb(0,255,0)'}
return color
}
function addText(event,d){
svg
.append("text")
.attr('class','mText')
.attr('x',projection([d.Longitude,d.Latitude])[0])
.attr("y",projection([d.Longitude,d.Latitude])[1])
.attr('fill', 'black')
.style('font-family','helvetica')
.style("font-size", "15px")
.text(d.Restaurant)
svg
.append("text")
.attr('class','mText')
.attr('x',50)
.attr("y",300)
.attr('fill', 'black')
.style('font-family','helvetica')
.style("font-size", "11px")
.text(d.Description)
svg
.append("text")
.attr('class','mText')
.attr('x',50)
.attr("y",200)
.attr('fill', 'black')
.style('font-family','helvetica')
.style("font-size", "25px")
.text(d.Rating)
var wrap = svg.selectAll("text.mText")
.each(function(d, i) { wrap_text(d3.select(this), 100) });
}
function removeText(){
svg.selectAll('text.mText').remove()
}
return svg.node();
}