chart = {
const svg = d3
.create("svg")
.attr("viewBox", [0, 0, width, height])
.call((svg) =>
svg.append("defs").html(`<style>
@import url("https://fonts.googleapis.com/css2?family=DM+Sans&family=Space+Mono&display=swap");
:root {
--trase-mono: "Space Mono", --mono_fonts;
--trase-sans-serif: "DM Sans", --sans-serif;
}
</style>`)
);
svg
.append("g")
.datum(d3.geoGraticule10())
.append("path")
.attr("stroke", "#e3ebe8")
.attr("stroke-width", 0.5)
.attr("fill", "none")
.attr("d", path);
svg
.append("g")
.selectAll("path")
.data(topojson.feature(world, world.objects.land).features)
.join("path")
.attr("fill", "#e3ebe8")
.attr("d", path);
svg
.append("g")
.selectAll("path")
.data(boundaries)
.join("path")
.attr("stroke", (d) => (data.has(d.id) ? "white" : "none"))
.attr("stroke-width", 0.4)
.attr("fill", (d) => colour(data.get(d.id)) || "none")
.attr("d", path);
if (!palm) {
svg
.append("g")
.datum(
topojson.mesh(
biomes_ecoregions,
biomes_ecoregions.objects.biomes_ecoregions
)
)
.append("path")
.attr("stroke", "#748f7e")
.attr("stroke-width", 0.75)
.attr("fill", "none")
.attr("d", path);
svg
.append("g")
.selectAll("text")
.data(
topojson.feature(
biomes_ecoregions,
biomes_ecoregions.objects.biomes_ecoregions
).features
)
.join("text")
.style("font", "bold 14px var(--trase-sans-serif), sans-serif")
.style("letter-spacing", "0.03em")
.style("text-anchor", "middle")
.attr("transform", (d) => {
let [x, y] = path.centroid(d);
if (d.properties.name === "Atlantic Forest") (x -= 50), (y += 60);
return `translate(${x}, ${y})`;
})
.text((d) => d.properties.name);
}
svg
.append("g")
.selectAll("path")
.data(boundaries.filter((d) => d.id.includes("PY")))
.join("path")
.attr("fill", "none")
.attr("stroke", "red")
.attr("stroke-width", 1)
.attr("d", path);
svg
.append("g")
.attr("transform", `translate(20, ${height - 60})`)
.append(() =>
legend({
colour: colour,
title: indicatorLabel,
tickFormat: d3.format("~s"),
titleFont: "bold 14px var(--trase-sans-serif), sans-serif",
upperCase: false,
width: 380,
marginRight: 120
})
);
return svg.node();
}