chart = {
const width = 900,
height = 700;
const svg = d3.create("svg")
.attr("viewBox", [50, 50, width-100, height-100]);
var projection = d3
.geoMercator()
.fitSize([width - 25, height - 50], SINbound);
var path1 = 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 path6 = d3.geoPath().projection(projection);
var path7 = d3.geoPath().projection(projection);
var path8 = d3.geoPath().projection(projection);
var g = svg.append("g").attr("id", "paths");
g.selectAll("path4")
.data(SINisland.features)
.enter()
.append("path")
.attr('class','outlines')
.attr("d", path4)
.style("fill", "rgb(242,234,233)")
.style("fill-opacity", ".6")
.style('stroke-opacity','.4')
.style("stroke-width", '.25')
.style("stroke", "rgb(99,48,64)")
g.selectAll("path5")
.data(SINroads.features)
.enter()
.append("path")
.attr('class','outlines')
.attr("d", path5)
.style("fill", "none")
.style('stroke-opacity','.4')
.style("stroke-width", '.6')
.style("stroke", "rgb(160,160,160)")
g.selectAll("path6")
.data(SINrail.features)
.enter()
.append("path")
.attr('class','outlines')
.attr("d", path6)
.style("fill", "none")
.style('stroke-opacity','1')
.style("stroke-width", '.5')
.style("stroke", "rgb(99,48,64)")
var c = svg.selectAll("circle")
.data(SINstations)
.enter()
.append("circle")
.attr("cx", function(d) {return projection([d.lng,d.lat])[0]})
.attr("cy", function(d) {return projection([d.lng,d.lat])[1]})
.attr('r',4.5)
.attr('fill',colorType)
.attr('stroke-opacity','.85')
.attr("stroke-width", "1.5")
.attr("stroke", "rgb(255,255,255)")
.style('fill-opacity','1')
.on('mouseover', spotText)
.on('mouseout', removeSpotText)
function colorType(d,i) {
var color = 'black'
if(d.type=='MRT'){color = 'rgb(204,0,102)'}
if(d.type=='LRT'){color = 'rgb(153,51,255)'}
return color
}
function spotText(event,d){
d3.select(this)
.attr('fill','deepskyblue')
.attr('r',7)
.style("stroke", "rgb(128, 223, 255)")
.style("stroke-opacity",'.75')
.style("stroke-width", '10')
svg.append('text')
.attr('class','spots')
.attr('x','710')
.attr('y','505')
.attr('font-family','Tahoma')
.attr('font-size','0.8em')
.attr('fill','black')
.attr('text-anchor','start')
.attr('font-weight','400')
.text(d.station_name)
svg.append('line')
.attr('class','spotLine')
.attr('x1','700')
.attr('y1','500')
.attr('x2',projection([d.lng,d.lat])[0])
.attr('y2','500')
.style('stroke-width','1')
.style('stroke','black')
.style('stroke-dasharray','4 2')
svg.append('line')
.attr('class','spotLine')
.attr('x1',projection([d.lng,d.lat])[0])
.attr('y1','500')
.attr('x2',projection([d.lng,d.lat])[0])
.attr('y2',projection([d.lng,d.lat])[1])
.style('stroke-width','1')
.style('stroke','black')
.style('stroke-dasharray','4 2')
}
function removeSpotText(event,d) {
d3.select(this).attr('fill',colorType)
d3.select(this).style("stroke", "rgb(255,255,255)")
d3.select(this).style('stroke-opacity','.85')
d3.select(this).style("stroke-width", "1.5")
d3.select(this).attr('r',4.5)
d3.selectAll('text.spots').remove()
d3.selectAll('line.spotLine').remove()
}
return svg.node();
}