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(outlines)
.enter()
.append("polyline")
.attr("points", function(d) {return d.pts})
.style("stroke","black")
.style("stroke-width","0.5px")
.style("fill",fillColor)
.on("mouseover",polyHover)
.on("mouseout",polyHoverOut)
function fillColor(d,i){
var color = "rgb(229,235,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="purple"}
if(d.Transportation=="FERRY"){color="pink"}
if(d.Transportation=="R, W"){color="rgb(255,255,0)"}
return color
}
p.enter().append("polyline") //use this line after the first polyline is added
.data(details)
.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(annotation)
.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","black")//style
.style("stroke-width","0.1px")
.style("fill","none")
function polyHover(event,d){
d3.select(this).style("fill","rgb(151,173,222)")
svg
.append("text")
.attr("x","350")
.attr("y","30")
.attr("class","hoverText")
.text(d.Address)
.style ("font-size", "6px")
svg
.append("text")
.attr("x","350")
.attr("y","40")
.attr("class","hoverText")
.text(d.BuildingType)
.style ("font-size", "6px")
svg
.append("text")
.attr("x","350")
.attr("y","50")
.attr("class","hoverText")
.text(d.Occupancy)
.style ("font-size", "6px")
svg
.append("text")
.attr("x","350")
.attr("y","60")
.attr("class","hoverText")
.text(d.Workersnumber)
.style ("font-size", "6px")
svg
.append("text")
.attr("x","305")
.attr("y","40")
.attr("class","hoverText")
.text("Building Types")
.style ("font-size", "6px")
svg
.append("text")
.attr("x","305")
.attr("y","30")
.attr("class","hoverText")
.text("Address")
.style ("font-size", "6px")
svg
.append("text")
.attr("x","305")
.attr("y","50")
.attr("class","hoverText")
.text("Occupancy")
.style ("font-size", "6px")
svg
.append("text")
.attr("x","305")
.attr("y","60")
.attr("class","hoverText")
.text("Workers")
.style ("font-size", "6px")
}
function polyHoverOut(){
d3.select(this).style("fill",fillColor)
svg.selectAll("text.hoverText").remove()
}
svg
.append("text")
.attr("x","10")
.attr("y","10")
// .attr("class","hoverText")
.text('Car emission: '+co2Calc[0]+ ' pounds of CO2')
.style ("font-size", "7px")
svg
.append("text")
.attr("x","10")
.attr("y","20")
// .attr("class","hoverText")
.text('Bus emission: '+co2Calc[1]+ ' pounds of CO2')
.style ("font-size", "7px")
svg
.append("text")
.attr("x","10")
.attr("y","30")
// .attr("class","hoverText")
.text('Subway emission: '+co2Calc[2]+ ' pounds of CO2')
.style ("font-size", "7px")
svg
.append("text")
.attr("x","15")
.attr("y","60")
.text("CO2 Emission: 10371")
.style ("font-size", "6px")
svg
.append("text")
.attr("x","15")
.attr("y","70")
.text("CO2 by bus/sub: 6717")
.style ("font-size", "6px")
svg
.append("text")
.attr("x","15")
.attr("y","80")
.text("CO2 by car: 5420")
.style ("font-size", "6px")
svg
.append("text")
.attr("x","15")
.attr("y","150")
.text("CO2 Emission: 45160")
.style ("font-size", "6px")
svg
.append("text")
.attr("x","15")
.attr("y","160")
.text("CO2 by bus/sub: 6490")
.style ("font-size", "6px")
svg
.append("text")
.attr("x","15")
.attr("y","170")
.text("CO2 by car: 5237")
.style ("font-size", "6px")
svg
.append("text")
.attr("x","15")
.attr("y","210")
.text("CO2 Emission: 159087")
.style ("font-size", "6px")
svg
.append("text")
.attr("x","15")
.attr("y","220")
.text("CO2 by bus/sub: 22878")
.style ("font-size", "6px")
svg
.append("text")
.attr("x","15")
.attr("y","230")
.text("CO2 by car: 18461")
.style ("font-size", "6px")
svg
.append("text")
.attr("x","15")
.attr("y","290")
.text("CO2 Emission: 4680")
.style ("font-size", "6px")
svg
.append("text")
.attr("x","15")
.attr("y","300")
.text("CO2 by bus/sub: 222")
.style ("font-size", "6px")
svg
.append("text")
.attr("x","15")
.attr("y","310")
.text("CO2 by car: 179")
.style ("font-size", "6px")
svg
.append("text")
.attr("x","220")
.attr("y","430")
.text("CO2 Emission: 792")
.style ("font-size", "6px")
svg
.append("text")
.attr("x","220")
.attr("y","440")
.text("CO2 by bus/sub: 670")
.style ("font-size", "6px")
svg
.append("text")
.attr("x","220")
.attr("y","450")
.text("CO2 by car: 541")
.style ("font-size", "6px")
svg
.append("text")
.attr("x","220")
.attr("y","470")
.text("CO2 Emission: 400")
.style ("font-size", "6px")
svg
.append("text")
.attr("x","220")
.attr("y","480")
.text("CO2 by bus/sub: 58")
.style ("font-size", "6px")
svg
.append("text")
.attr("x","220")
.attr("y","490")
.text("CO2 by car: 47")
.style ("font-size", "6px")
svg
.append("text")
.attr("x","350")
.attr("y","90")
.text("CO2 Emission: 5475")
.style ("font-size", "6px")
svg
.append("text")
.attr("x","350")
.attr("y","100")
.text("CO2 by bus/sub: 6434")
.style ("font-size", "6px")
svg
.append("text")
.attr("x","350")
.attr("y","110")
.text("CO2 by car: 5192")
.style ("font-size", "6px")
svg
.append("text")
.attr("x","400")
.attr("y","160")
.text("CO2 Emission: 778")
.style ("font-size", "6px")
svg
.append("text")
.attr("x","400")
.attr("y","170")
.text("CO2 by bus/sub: 623")
.style ("font-size", "6px")
svg
.append("text")
.attr("x","400")
.attr("y","180")
.text("CO2 by car: 503")
.style ("font-size", "6px")
svg
.append("text")
.attr("x","440")
.attr("y","210")
.text("CO2 Emission: 10581")
.style ("font-size", "6px")
svg
.append("text")
.attr("x","440")
.attr("y","220")
.text("CO2 by bus/sub: 4223")
.style ("font-size", "6px")
svg
.append("text")
.attr("x","440")
.attr("y","230")
.text("CO2 by car: 3407")
.style ("font-size", "6px")
return svg.node();
}