chart = {
const width = 500,
height = 500;
const svg = d3.create("svg")
.attr("viewBox", [0, 0, width, height]);
var g = svg.append("g").attr("id", "paths");
var p = svg.selectAll("polyline")
.data(outline)
.enter()
.append("polyline")
.attr("points", function(d) {return d.pts})
.style("stroke","black")
.style("stroke-width","0.3px")
.style("fill",fillColor)
.on("mouseover",polyHover)
.on("mouseout",polyHoverOut)
function fillColor(d,i){
var color = "rgb(230,230,255)"
if(d.Transportation=="4, 5"){color="rgb(0,102,51)"}
if(d.Transportation=="2, 3"){color="blue"}
if(d.Transportation=="1"){color="rgb(180,0,0)"}
if(d.Transportation=="J, Z"){color="rgb(139,69,19)"}
if(d.TotalYearlyRidership2021== "6,767,364"){color="pink"}
if(d.AvgWeekdayRidership2021== "2112"){color="pink"}
if(d.AvgWeekdayRidership2021== "44"){color="pink"}
if(d.Transportation=="R, W"){color="rgb(255,255,0)"}
if(d.Transportation=="N/A"){color="rgb(255,128,0)"}
return color
}
p.enter().append("polyline") //use this line after the first polyline is added
.data(basedetail)
.enter() //there are more data than elements, this selects them
.append("polyline") //appends path to data
.attr("points", function(d) {return d})//required attributes
.style("stroke","grey")//style
.style("stroke-width","0.1px")
.style("fill","none")
p.enter().append("polyline") //use this line after the first polyline is added
.data(red2)
.enter() //there are more data than elements, this selects them
.append("polyline") //appends path to data
.attr("points", function(d) {return d})//required attributes
.style("stroke","red")//style
.style("stroke-width","1.5px")
.style("fill","none")
p.enter().append("polyline") //use this line after the first polyline is added
.data(blue)
.enter() //there are more data than elements, this selects them
.append("polyline") //appends path to data
.attr("points", function(d) {return d})//required attributes
.style("stroke","blue")//style
.style("stroke-width","1.5px")
.style("fill","none")
p.enter().append("polyline") //use this line after the first polyline is added
.data(green)
.enter() //there are more data than elements, this selects them
.append("polyline") //appends path to data
.attr("points", function(d) {return d})//required attributes
.style("stroke","rgb(0,102,51)")//style
.style("stroke-width","1.5px")
.style("fill","none")
p.enter().append("polyline") //use this line after the first polyline is added
.data(yellow)
.enter() //there are more data than elements, this selects them
.append("polyline") //appends path to data
.attr("points", function(d) {return d})//required attributes
.style("stroke","yellow")//style
.style("stroke-width","1.5px")
.style("fill","none")
p.enter().append("polyline") //use this line after the first polyline is added
.data(darkred)
.enter() //there are more data than elements, this selects them
.append("polyline") //appends path to data
.attr("points", function(d) {return d})//required attributes
.style("stroke","rgb(180,0,0)")//style
.style("stroke-width","1.5px")
.style("fill","none")
p.enter().append("polyline") //use this line after the first polyline is added
.data(brown)
.enter() //there are more data than elements, this selects them
.append("polyline") //appends path to data
.attr("points", function(d) {return d})//required attributes
.style("stroke","rgb(139,69,19)")//style
.style("stroke-width","1.5px")
.style("fill","none")
p.enter().append("polyline") //use this line after the first polyline is added
.data(busline)
.enter() //there are more data than elements, this selects them
.append("polyline") //appends path to data
.attr("points", function(d) {return d})//required attributes
.style("stroke","rgb(128,255,255)")//style
.style("stroke-width","0.5px")
.style("fill","none")
p.enter().append("polyline") //use this line after the first polyline is added
.data(outlinedetail)
.enter() //there are more data than elements, this selects them
.append("polyline") //appends path to data
.attr("points", function(d) {return d})//required attributes
.style("stroke","white")//style
.style("stroke-width","0.5px")
.style("fill","none")
p.enter().append("polyline") //use this line after the first polyline is added
.data(boundary)
.enter() //there are more data than elements, this selects them
.append("polyline") //appends path to data
.attr("points", function(d) {return d})//required attributes
.style("stroke","grey")//style
.style("stroke-width","1.5px")
.style("fill","none")
function polyHover(event,d){
d3.select(this).style("fill","red")
svg
.append("text")
.attr("x","300")
.attr("y","400")
.attr("class","hoverText")
.text(d.Address)
.style ("font-size", "6px")
svg
.append("text")
.attr("x","230")
.attr("y","400")
.attr("class","hoverText")
.text("Address:")
.style ("font-size", "6px")
svg
.append("text")
.attr("x","300")
.attr("y","410")
.attr("class","hoverText")
.text(d.Transportation)
.style ("font-size", "6px")
svg
.append("text")
.attr("x","230")
.attr("y","410")
.attr("class","hoverText")
.text("Mode of Transportation:")
.style ("font-size", "6px")
svg
.append("text")
.attr("x","300")
.attr("y","420")
.attr("class","hoverText")
.text(d.TotalYearlyRidership2021)
.style ("font-size", "6px")
svg
.append("text")
.attr("x","230")
.attr("y","420")
.attr("class","hoverText")
.text("Yearly Ridership:")
.style ("font-size", "6px")
svg
.append("text")
.attr("x","300")
.attr("y","430")
.attr("class","hoverText")
.text(d.AvgWeekdayRidership2021)
.style ("font-size", "6px")
svg
.append("text")
.attr("x","230")
.attr("y","430")
.attr("class","hoverText")
.text("Weekly Ridership:")
.style ("font-size", "6px")
}
function polyHoverOut(){
d3.select(this).style("fill",fillColor)
svg.selectAll("text.hoverText").remove()
}
svg
.append("text")
.attr("x","5")
.attr("y","20")
.text("Transportation in Lower Manhattan")
.style ("font-size", "14px")
return svg.node();
}