chart = {
const width = 960,
height = 900;
const svg = d3
.create("svg")
.attr("viewBox", [0, 0, width, height])
.attr("viewBox", [-15, -10, width, height])
.style("background", "#284270");
var projection = d3.geoMercator().fitSize([width - 50, height - 50], zips);
var path = d3.geoPath().projection(projection);
var path2 = d3.geoPath().projection(projection);
svg
.selectAll("line")
.data(eva_cent.features)
.enter()
.append("line")
.attr("x1", function (d) {
return path.centroid(d)[0];
})
.attr("y1", function (d) {
return path.centroid(d)[1];
})
.attr("x2", 100)
.attr("y2", function (d, i) {
return i * 10 + 10;
})
.attr("stroke-width", ".8")
.attr("stroke-opacity", ".15")
.style("stroke", "white");
var g = svg.append("g").attr("id", "paths");
g.selectAll("path")
.data(zips.features)
.enter()
.append("path")
.attr("class", "outlines")
.attr("d", path)
.attr("fill", (d) => color(d.properties.POPULATION))
.style("fill-opacity", ".5")
.style("stroke-width", ".35")
.style("stroke", "#ccc");
g.selectAll("path2")
.data(nycStreets.features)
.enter()
.append("path")
.attr("class", "outlines")
.attr("d", path)
.style("fill-opacity", "0")
.style("stroke-width", ".05")
.style("stroke", "black");
g.selectAll("path")
.data(shoreline.features)
.enter()
.append("path")
.attr("class", "outlines")
.attr("d", path)
.style("fill-opacity", "0")
.style("stroke-width", ".15")
.style("stroke", "black");
g.selectAll("path2")
.data(nycsub.features)
.enter()
.append("path")
.attr("class", "outlines")
.attr("d", path)
.style("fill-opacity", "0")
.style("stroke-width", ".35")
.style("stroke", "red");
g.selectAll("path2")
.data(eva_cent.features)
.enter()
.append("circle")
.attr("cx", function (d) {
return path.centroid(d)[0];
})
.attr("cy", function (d) {
return path.centroid(d)[1];
})
.attr("r", 42)
.style("stroke-width", ".05")
.style("stroke", "grey")
.attr("fill", "purple")
.style("fill-opacity", ".1");
g.selectAll("path2")
.data(eva_cent.features)
.enter()
.append("circle")
.attr("cx", function (d) {
return path.centroid(d)[0];
})
.attr("cy", function (d) {
return path.centroid(d)[1];
})
.attr("r", 3)
.attr("fill", "purple")
.style("fill-opacity", ".5")
.on("mouseover", addBox)
.on("mouseout", removeBox);
svg
.selectAll("text")
.data(eva_cent.features)
.enter()
.append("text")
.attr("x", "0")
.attr("y", function (d, i) {
return i * 10 + 10;
})
.style("font", "8px roboto")
.style("fill", "white")
.attr("font-size", ".55em")
.attr("text-anchor", "start")
.text(function (d) {
return d.properties.bldg_name;
});
g.selectAll("path2")
.data(slr_10ft.features)
.enter()
.append("path")
.attr("class", "outlines")
.attr("d", path)
.style("fill", "blue")
.style("fill-opacity", ".5")
.style("stroke-width", "0")
.on("mouseover", addFill)
.on("mouseleave", removeFill);
function addFill(event, d) {
d3.select(this).style("fill", "red");
d3.select(this).style("fill-opacity", ".5");
svg
.append("text")
.attr("class", "labels")
.attr("x", "830")
.attr("y", "10")
.style("font", "12px roboto")
.style("fill", "white")
.attr("font-size", ".85em")
.text("sea level rise 10ft");
}
function removeFill(event, d) {
d3.selectAll("text.labels").remove();
d3.select(this).style("fill", "blue");
d3.select(this).style("fill-opacity", ".2");
}
var tooltip = svg.append("g");
function addBox(event, d) {
var centroid = path.centroid(d);
tooltip.call(
callout,
`${d.properties.bldg_name}
${d.properties.bldg_add}, ${d.properties.city}, ${d.properties.state}`
);
tooltip.attr("transform", "translate(" + centroid + ")");
}
function removeBox(event, d) {
tooltip.call(callout, null);
}
svg
.append("text")
.attr("x", "520")
.attr("y", "830")
.attr("font-size", "1.35em")
.style("font", "24px roboto")
.attr("font-weight", "bold")
.style("fill", "#ef5454")
.text("NYC Sea Level Threats");
svg
.append("text")
.attr("x", "520")
.attr("y", "847")
.attr("font-size", ".6em")
.style("font", "10px roboto")
.style("fill", "#ef5454")
.text(
"the map indicates the predicted situation of 10ft sea level rising"
);
svg
.append("text")
.attr("x", "520")
.attr("y", "856")
.attr("font-size", ".6em")
.style("font", "10px roboto")
.style("fill", "#ef5454")
.text(
"with the present location of the evacuation center, public transportation system, and population."
);
return svg.node();
}