legend = svg => {
const r = 6;
const g = svg
.attr("font-family", "sans-serif")
.attr("font-size", 10)
.selectAll("g")
.data(colour.domain())
.join("g")
.attr("transform", (d, i) => `translate(${i * 100}, 0)`);
g.append("circle")
.attr("fill", colour)
.attr("r", r)
.attr("x", 0)
.attr("y", 0);
g.append("text")
.attr("x", r * 2)
.attr("y", r / 2)
.text(d => d);
const padding = 10;
g.attr(
"transform",
(d, i) =>
`translate(${d3.sum(colour.domain(), (e, j) =>
j < i ? g.nodes()[j].getBBox().width : 0
) +
padding * i} ,0)`
);
}