drawLegend = g => {
g.append("text")
.attr("y", -20)
.attr("font-size", "1.5em")
.attr("text-decoration", "underline")
.attr("font-weight", "bold")
.text("Tram");
g.append("text")
.attr("x", 80)
.attr("y", 200)
.attr("font-size", "1.5em")
.attr("text-decoration", "underline")
.attr("font-weight", "bold")
.text("Metro");
const legendEntries = g
.selectAll("line")
.data(colors)
.join("g")
.attr("transform", (d, i) =>
Number(d[0]) < 50
? `translate(0, ${i * 22})`
: `translate(80, ${(i - 5) * 22})`
);
legendEntries
.append("line")
.attr("stroke-width", 3)
.attr("x1", 0)
.attr("x2", 30)
.attr("stroke", d => d[1]);
legendEntries
.append("text")
.text(d => d[0])
.attr("x", 35)
.attr("fill", d => d[1])
.attr("stroke", "gainsboro")
.attr("alignment-baseline", "middle")
.attr("stroke-width", "1px");
}