chart = {
const width =1000,
height = 1100;
const svg = d3.create("svg")
.attr("viewBox", [100, 100, width-400, height-450]);
var projection = d3
.geoMercator()
.fitSize([width - 100, height - 200], bbox);
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 g = svg.append("g").attr("id", "paths");
var clickYear = 2000
//show current transit sytems
//display connected parks
//display proposed sytem
//Movable object across an array of points along a single curve
//select parks for information
//hover over tram to get information on it
//mouse over current metro stops
g.selectAll("path2") //d3 geopath
.data(berlinTransportStops1.features) //get data to define path
.enter() //there are more data than elements, this selects them
.append("path") //appends path to data
.attr('class','stops')
.style("fill", "black")
.style("fill-opacity", "0")
.style('stroke-opacity','0')
.style("stroke-width", '0')
.style("stroke", "none")
g.selectAll("path2") //d3 geopath
.data(waterways.features) //get data to define path
.enter() //there are more data than elements, this selects them
.append("path") //appends path to data
.attr('class','water')
.attr("d", path2) //The d attribute defines a path to be drawn, only applies to appended elements
.style("fill", "azure")
.style("fill-opacity", "1")
.style('stroke-opacity','1')
.style("stroke-width", '.5')
.style("stroke", "white")
var c = svg.selectAll("circle")
.data(berlinTransportStops1.features)
.enter()
.append("circle")
.attr("cx", function(d) {return path1.centroid(d)[0]})
.attr("cy", function(d) {return path1.centroid(d)[1]})
.attr('r','1.5')
.attr('fill','red')
.style('fill-opacity','1')
.style("stroke-width", '0.8')
.style("stroke", "black")
.on('mouseover',metrostops)
.on('mouseout',removespotText)
var c = svg.selectAll("circle")
.data(Berlinparklink)
.enter()
.append("circle")
.attr("cx", function(d) {return projection([d.long,d.lat])[0]})
.attr("cy", function(d) {return projection([d.long,d.lat])[1]})
.attr('r','4')
.attr('fill','blue')
.style('fill-opacity','1')
.style("stroke-width", '0.8')
.style("stroke", "black")
.on('mouseover',parkmouse)
.on('mouseout',removespotText)
function layersClick(event,d){
console.log(d)
if(d=='Current'){
clickYear = Current
d3.selectAll('path.outlines').remove()
d3.selectAll('text.layersText').remove()
g.selectAll("path2") //d3 geopath
.data(Current.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", 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", "black")
svg.append('text')
.attr('class','layersText')
.attr('x', '410')
.attr('y','400')
.attr('font-family','Helvetica')
.attr('font-size', '.65em')
.attr('text.anchor','start')
.attr('font-weight', 'Bold')
.text('The system continues to grow and the restorations also continue')
svg.append('text')
.attr('class','layersText')
.attr('x', '110')
.attr('y','85')
.attr('font-family','Helvetica')
.attr('font-size', '.55em')
.attr('text.anchor','start')
.attr('font-weight', 'normal')
.text('')
svg.append('text')
.attr('class','layersText')
.attr('x', '110')
.attr('y','95')
.attr('font-family','Helvetica')
.attr('font-size', '.55em')
.attr('text.anchor','start')
.attr('font-weight', 'normal')
.text('')
}
}
//make parks change opacity & give a info blurb
//hey, you're naming this function the same thing as your dataset - 'Parkpoints' - name it something else!!!!
function parkmouse(event,d) {
d3.select(this).attr('fill','yellow')
d3 .select(this) .attr('r',4)
svg.append('text')//use this for second and all subsequent text add
.attr("x", '650')
.attr("y", '720')
.attr('class','parks')
.attr('font-family','helvetica')
.attr('font-size','.55em')
.attr('font-weight','bold')
.style("fill", "rgb(0,0,0)")
.attr('text-anchor','start')
.text(d.Name)
svg.append('text')//use this for second and all subsequent text add
.attr("x", '650')
.attr("y", '730')
.attr('class','parks')
.attr('font-family','helvetica')
.attr('font-size','.55em')
.attr('font-weight','400')
.style("fill", "rgb(50,50,50)")
.attr('text-anchor','start')
.text(d.description)
svg.append('line')
.attr('class','spotline')
.attr('x1','650')
.attr('y1','720')
.attr('x2',path1.centroid(d)[0])
.attr('y2','720')
.style('stroke-width','1')
.style('stroke','black')
.style('stroke-dasharray','4 2')
svg.append('line')
.attr('class','spotline')
.attr('x1',path1.centroid(d)[0])
.attr('y1','720')
.attr('x2',path1.centroid(d)[0])
.attr('y2',path1.centroid(d)[1])
.style('stroke-width','1')
.style('stroke','black')
.style('stroke-dasharray','4 2')
}
//makes a metro sign pop up or tells what stop it is
function metrostops(event,d) {
d3.select(this).attr('fill','yellow')
d3 .select(this) .attr('r',2.5)
svg.append('text')//use this for second and all subsequent text add
.attr("x", '650')
.attr("y", '720')
.attr('class','metrostops')
.attr('font-family','helvetica')
.attr('font-size','.55em')
.attr('font-weight','bold')
.style("fill", "rgb(0,0,0)")
.attr('text-anchor','start')
.text('Metrostop')
svg.append('text')//use this for second and all subsequent text add
.attr("x", '650')
.attr("y", '730')
.attr('class','metrostops')
.attr('font-family','helvetica')
.attr('font-size','.55em')
.attr('font-weight','400')
.style("fill", "rgb(50,50,50)")
.attr('text-anchor','start')
.text('U & S Bahn')
svg.append('line')
.attr('class','spotline')
.attr('x1','650')
.attr('y1','720')
.attr('x2',path1.centroid(d)[0])
.attr('y2','720')
.style('stroke-width','1')
.style('stroke','black')
.style('stroke-dasharray','4 2')
svg.append('line')
.attr('class','spotline')
.attr('x1',path1.centroid(d)[0])
.attr('y1','720')
.attr('x2',path1.centroid(d)[0])
.attr('y2',path1.centroid(d)[1])
.style('stroke-width','1')
.style('stroke','black')
.style('stroke-dasharray','4 2')
}
function removeparktext(event,d)
{
d3.selectAll('text.parkmouse').remove()
d3.selectAll('line.parkmouse').remove()
}
function removespotText(event,d)
{d3.selectAll('text.metrostops').remove()
d3.selectAll('text.parks').remove()
d3.selectAll('line.spotline').remove()
d3.select(this).attr('fill','red')
d3 .select(this).attr('r',1.5)
}
return svg.node();
}