chart = {
const width = 960,
height = 900;
const svg = d3.create("svg")
.attr("viewBox", [-60, 0, width, height]);
var projection = d3
.geoMercator()
.fitSize([width - 50, height - 50], zips);
var path = d3.geoPath().projection(projection);
var path2 = d3.geoPath().projection(projection);
svg.selectAll('line')
.data(racks.features)
.enter()
.append('line')
.attr('x1',function(d) {return path.centroid(d)[0]})
.attr('y1',function(d) {return path.centroid(d)[1]})
.attr('x2',52)
.attr('y2',function(d,i){return i*2+10})
.attr('stroke-width','.4')
.attr('stroke-opacity','.08')
.style('stroke','rgb(0,0,0)')
var g = svg.append("g").attr("id", "paths");
g.selectAll("path")
.data(zips.features)
.enter()
.append("path") //appends path to data
.attr('class','outlines')
.attr("d", path) //The d attribute defines a path to be drawn, only applies to appended elements
.style("fill", "white")
.style('fill-opacity','.8')
.style("stroke-width", ".25")
.style("stroke", "#ccc")
//insert parks into map
g.selectAll("path") //d3 geopath
//svg
//.selectAll('path')
.data(nycParks.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", path) //The d attribute defines a path to be drawn, only applies to appended elements
.style("fill", "red")
.style('fill-opacity','.25')
.style("stroke-width", ".2")
.style("stroke", "rgb(255,0,0)")
.on('mouseover', addFill)
.on('mouseleave', removeFill)
g.selectAll("path2") //d3 geopath
//svg
//.selectAll('path')
.data(subway_lines.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", path) //The d attribute defines a path to be drawn, only applies to appended elements
.style('fill-opacity','0')
.style("stroke-width", ".35")
.style("stroke", "rgb(0,0,0)")
var c = svg.selectAll("circle") //d3 geopath
//svg
//.selectAll('path')
.data(subSts.features) //get data to define path
.enter() //there are more data than elements, this selects them
.append("circle") //appends path to data
.attr('cx',function(d) {return path.centroid(d)[0]})
.attr("cy",function(d) {return path.centroid(d)[1]})
.attr('r',1.5)
.attr('fill','black')
.style('fill-opacity','.9')
.on('mouseover', addBox)
.on('mouseout', removeBox)
c.enter().append('circle')
//svg
//.selectAll('path')
.data(racks.features) //get data to define path
.enter() //there are more data than elements, this selects them
.append("circle") //appends path to data
.attr('cx',function(d) {return path.centroid(d)[0]})
.attr("cy",function(d) {return path.centroid(d)[1]})
.attr('r',.75)
.attr('fill','rgb(100,100,100)')
.style('fill-opacity','.2')
.on('mouseover', addRack)
.on('mouseout', removeBox)
//add bike rack text
svg.selectAll('text')
.data(racks.features)
.enter()
.append('text')
.attr('x','50')
.attr('y',function(d,i){return i*2+10})
.attr('font-size','.15em')
.attr('text-anchor','end')
.text(function(d){return d.properties.Name})
//add park labels and park fill
function addFill(event,d) {
d3.select(this).style("fill", "blue")
d3.select(this).style('fill-opacity','.8')
svg
.append('text')
.attr("class","labels")
.attr('x','100')
.attr('y','100')
.attr('font-size','.85em')
.text(d.properties.park_name)
}
//take away park labels/park fill
function removeFill(event,d) {
d3.selectAll("text.labels").remove()
d3.select(this).style("fill", "red")
d3.select(this).style('fill-opacity','.25')
}
//add subway stop tool tip
var tooltip = svg.append("g");
function addBox(event, d) {
var centroid = path.centroid(d);
tooltip.call(
callout,
`${d.properties.name}
${d.properties.line}, ${d.properties.line}`
);
tooltip.attr("transform", "translate(" + centroid + ")");
}
//add bike rack box
function addRack(event, d) {
var centroid = path.centroid(d);
tooltip.call(
callout,
`${d.properties.Name}
${d.properties.total_rack}`
);
tooltip.attr("transform", "translate(" + centroid + ")");
}
function removeBox(event, d) {
tooltip.call(callout,null)
}
return svg.node();
}