chart = {
const width = 1000,
height = 900;
const svg = d3.create("svg")
.attr("viewBox", [100, 10, width-150, height-150]);
var projection = d3
.geoMercator()
.fitSize([width - 100, height - 100], 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
g.selectAll("path2")
.data(Current.features)
.enter()
.append("path")
.attr('class','outlines')
.attr("d", path2)
.style("fill", "none")
.style('stroke-opacity','.5')
.style("stroke-width", '.3')
.style("stroke", "black")
g.selectAll("path2")
.data(berlinTransportStops1.features)
.enter()
.append("path")
.attr('class','stops')
.attr("d", path2)
.style("fill", "black")
.style("fill-opacity", ".6")
.style('stroke-opacity','.8')
.style("stroke-width", '.5')
.style("stroke", "black")
g.selectAll("path2")
.data(waterways.features)
.enter()
.append("path")
.attr('class','water')
.attr("d", path2)
.style("fill", "azure")
.style("fill-opacity", "1")
.style('stroke-opacity','.4')
.style("stroke-width", '.5')
.style("stroke", "black")
g.selectAll("path3")
.data(bldgs.features)
.enter()
.append("path")
.attr('class','parks')
.attr("d", path3)
.style("fill", "green")
.style("fill-opacity", ".7")
.style('stroke-opacity','1')
.style("stroke-width", '.2')
.style("stroke", "black")
g.selectAll("path3")
.data(bldgs2.features)
.enter()
.append("path")
.attr('class','buildings')
.attr("d", path3)
.style("fill", "beige")
.style("fill-opacity", ".3")
.style('stroke-opacity','.4')
.style("stroke-width", '.5')
.style("stroke", "rgb(0,0,0)")
var c = svg.selectAll("path3")
.data(bldgs)
.enter()
.append("path")
.attr('class','outlines')
.attr('d',path3)
.style("fill", "blue")
.style('fill-opacity','0.2')
.style('stroke-opacity','0.1')
.style("stroke-width", '.6')
.style("stroke", "rgb(0,0,0)")
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',2)
.attr('fill','rgb(120,120,120)')
.style('fill-opacity','1')
.style("stroke-width", '0.5')
.style("stroke", "blue")
var t = svg.selectAll("text")
.data(layers)
.enter()
.append('text')
.attr('x',120)
.attr('y',function(d,i) {return 200+20*i})
.attr('fill','black')
.attr('font-family','Helvetica')
.attr('font-size', '.65em')
.attr('text.anchor','start')
.attr('font-weight', 'bold')
.text(function(d) {return d})
c.enter().append('circle')
.data(layers)
.enter()
.append('circle')
.attr('cx',110)
.attr('cy',function(d,i) {return 195+20*i})
.attr('r',5)
.attr('fill','aqua')
.style("stroke-width", '.5')
.style("stroke", "black")
.on('click',layersClick)
function layersClick(event,d){
console.log(d)
if(d=='1902'){
clickYear = 1902
d3.selectAll('path.outlines').remove()
d3.selectAll('path.stops').remove()
d3.selectAll('text.layersText').remove()
svg.append('text')
.attr('class','layersText')
.attr('x', '110')
.attr('y','70')
.attr('font-family','Helvetica')
.attr('font-size', '.65em')
.attr('text.anchor','start')
.attr('font-weight', 'Bold')
.text('Untergrundbahn (Now U1 & U2)')
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('Berlins First Unntergrund or Underground Railway')
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('Opened Between Warshauer, Brucke and Potsdamer Platz')
}
if(d=='1910'){
clickYear = 1910
d3.selectAll('path.outlines').remove()
d3.selectAll('path.stops').remove()
d3.selectAll('text.layersText').remove()
g.selectAll("path2")
.data(Line2.features)
.enter()
.append("path")
.attr('class','outlines')
.attr("d", path2)
.style("fill", "none")
.style('stroke-opacity','1')
.style("stroke-width", '1.5')
.style("stroke", "rgb(0,0,0)")
svg.append('text')
.attr('class','layersText')
.attr('x', '110')
.attr('y','70')
.attr('font-family','Helvetica')
.attr('font-size', '.65em')
.attr('text.anchor','start')
.attr('font-weight', 'Bold')
.text('U1 & U2 Extend further West & East')
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('More Cities are connected by the underground rail')
}
if(d=='1920'){
clickYear = 1920
d3.selectAll('path.outlines').remove()
d3.selectAll('path.stops').remove()
d3.selectAll('text.layersText').remove()
g.selectAll("path2")
.data(Line3.features)
.enter()
.append("path")
.attr('class','outlines')
.attr("d", path2)
.style("fill", "none")
.style('stroke-opacity','1')
.style("stroke-width", '1.5')
.style("stroke", "rgb(0,0,0)")
svg.append('text')
.attr('class','layersText')
.attr('x', '110')
.attr('y','70')
.attr('font-family','Helvetica')
.attr('font-size', '.65em')
.attr('text.anchor','start')
.attr('font-weight', 'Bold')
.text('The U3 is added')
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('Wittenbergplatz is now connected to uhlandstrabe & Theilplatz')
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('')
}
if(d=='1930'){
clickYear = 1930
d3.selectAll('path.outlines').remove()
d3.selectAll('path.stops').remove()
d3.selectAll('text.layersText').remove()
g.selectAll("path2")
.data(Line4.features)
.enter()
.append("path")
.attr('class','outlines')
.attr("d", path2)
.style("fill", "none")
.style('stroke-opacity','1')
.style("stroke-width", '1.5')
.style("stroke", "rgb(0,0,0)")
svg.append('text')
.attr('class','layersText')
.attr('x', '110')
.attr('y','70')
.attr('font-family','Helvetica')
.attr('font-size', '.65em')
.attr('text.anchor','start')
.attr('font-weight', 'Bold')
.text('Line 6 (now U6) opens and connects to 8 new cities)')
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('Berlins First electric railway opens in 1924')
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('The U2 & U7 extend to new cities and the system scales up dramaticaly')
}
if(d=='1940'){
clickYear = 1940
d3.selectAll('path.outlines').remove()
d3.selectAll('path.stops').remove()
d3.selectAll('text.layersText').remove()
g.selectAll("path2")
.data(Line5.features)
.enter()
.append("path")
.attr('class','outlines')
.attr("d", path2)
.style("fill", "none")
.style('stroke-opacity','1')
.style("stroke-width", '1.5')
.style("stroke", "rgb(0,0,0)")
svg.append('text')
.attr('class','layersText')
.attr('x', '110')
.attr('y','70')
.attr('font-family','Helvetica')
.attr('font-size', '.65em')
.attr('text.anchor','start')
.attr('font-weight', 'Bold')
.text('Bombing of berlin results in many stations to cease operations')
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('Berlin is divided into occupation zones controlled by allied powers that later becomes east and west berlin')
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(' East and west Germany were established and Berlin officially split into two.')
}
if(d=='1970'){
clickYear = 1970
d3.selectAll('path.outlines').remove()
d3.selectAll('path.stops').remove()
d3.selectAll('text.layersText').remove()
g.selectAll("path2")
.data(Line6.features)
.enter()
.append("path")
.attr('class','outlines')
.attr("d", path2)
.style("fill", "none")
.style('stroke-opacity','1')
.style("stroke-width", '1.5')
.style("stroke", "rgb(0,0,0)")
svg.append('text')
.attr('class','layersText')
.attr('x', '110')
.attr('y','70')
.attr('font-family','Helvetica')
.attr('font-size', '.65em')
.attr('text.anchor','start')
.attr('font-weight', 'Bold')
.text('1961 marks the construction of berlin wall completely cut off west berlin from the rest of east germany')
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('s-bahn ridership in west berlin significantly drops as west berliners boycotts east berlin controlled s-bahn')
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('s-bahn opens service from Blankenburg to Hohen Neuendorf replace connection lost from the wall')
}
if(d=='1995'){
clickYear = 1970
d3.selectAll('path.outlines').remove()
d3.selectAll('path.stops').remove()
d3.selectAll('text.layersText').remove()
g.selectAll("path2")
.data(Line7.features)
.enter()
.append("path")
.attr('class','outlines')
.attr("d", path2)
.style("fill", "none")
.style('stroke-opacity','1')
.style("stroke-width", '1.5')
.style("stroke", "rgb(0,0,0)")
svg.append('text')
.attr('class','layersText')
.attr('x', '110')
.attr('y','70')
.attr('font-family','Helvetica')
.attr('font-size', '.65em')
.attr('text.anchor','start')
.attr('font-weight', 'Bold')
.text('With German reunification closed railways begin restoration')
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('')
}
if(d=='Current'){
clickYear = Current
d3.selectAll('path.outlines').remove()
d3.selectAll('text.layersText').remove()
g.selectAll("path2")
.data(Current.features)
.enter()
.append("path")
.attr('class','outlines')
.attr("d", path2)
.style("fill", "none")
.style('stroke-opacity','1')
.style("stroke-width", '.5')
.style("stroke", "black")
svg.append('text')
.attr('class','layersText')
.attr('x', '110')
.attr('y','70')
.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('')
}
}
svg
.append('rect')
.attr('fill', "white")
.attr('opacity','.8')
.attr('stroke',"rgb(0,0,0)")
.attr('stroke-width',"1px")
.attr('x', 67)
.attr('y', 60)
.attr('width', 600)
.attr('height', 40)
function removespotText(event,d)
{d3.select(this).attr('fill','green')
d3.selectAll('text.spots').remove()
d3.selectAll('line.spotLine').remove()
}
return svg.node();
}