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(post_office.features)
.enter()
.append('line')
.attr('x1',function(d) {return path.centroid(d)[0]})
.attr('y1',function(d) {return path.centroid(d)[0]})
.attr('x2',52)
.attr('y2',function(d) {return path.centroid(d)[1]})
.attr('stroke-width','0.4')
.attr('stroke-opacity','0.08')
.style('stroke','rgb(0,0,0)')
var g = svg.append("g").attr("id", "paths");
g.selectAll("path")
.data(zips.features)
.enter()
.append("path")
.attr('class','outlines')
.attr("d", path)
.style("fill", "grey")
.style('fill-opacity','.5')
.style("stroke-width", "1")
.style("stroke", "#ccc")
g.selectAll("path")
.data(nycp.features)
.enter()
.append("path")
.attr('class','outlines')
.attr("d", path)
.style("fill", "green")
.style('fill-opacity','.2')
.style("stroke-width", "0.2")
.style("stroke", "green")
.on('mouseover',addFill)
.on('mouseleave',removeFill)
g.selectAll("path2")
.data(SubwayLine.features)
.enter()
.append("path")
.attr('class','outlines')
.attr("d", path)
.style('fill-opacity','0')
.style("stroke-width", "0.5")
.style("stroke", "blue")
var c = svg.selectAll("circle")
.data(Subway_sts.features)
.enter()
.append("circle")
.attr('cx',function(d) {return path.centroid(d)[0]})
.attr("cy", function(d) {return path.centroid(d)[1]})
.attr('r',2)
.attr('fill-opacity','0.5')
.attr('fill','blue')
.on('mouseover',addBox)
.on('mouseout',removeBox)
c.enter().append('circle')
.data(post_office.features)
.enter()
.append("circle")
.attr('cx',function(d) {return path.centroid(d)[0]})
.attr("cy",function(d) {return path.centroid(d)[1]})
.attr('r',3)
.attr('fill-opacity','0.90')
.attr('fill','yellow')
.on('mouseover',addRack)
.on('mouseout',removeBox)
svg.selectAll('text')
.data(post_office.features)
.enter()
.append('text')
.attr('x','52')
.attr('y',function(d,i){return i*3.2+10})
.attr('font-size','0.15em')
.attr('text-anchor','end')
.text(function(d){return d.properties.name})
function addFill(event,d) {
d3.select(this).style("fill", "black")
d3.select(this).style('fill-opacity','0.8')
svg
.append('text')
.attr('class','labels')
.attr('x','100')
.attr('y','100')
.attr('font-size','0.85em')
.text(d.properties.eapply)
}
function removeFill(event,d) {
d3.selectAll('text.labels').remove()
d3.select(this).style("fill", "red")
d3.select(this).style('fill-opacity','0.5')
}
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 + ")");
}
function addRack(event, d) {
var centroid = path.centroid(d);
tooltip.call(
callout,
`${d.properties.name}
${d.properties.streetname}`
);
tooltip.attr("transform", "translate(" + centroid + ")");
}
function removeBox(event, d) {
tooltip.call(callout,null)
}
return svg.node();
}