Working from day 13. This week I needed to make a legend, and I always muck about with this, and for some reason I had a look at Elijah Meek's book (which I need to do more of as every time I do this I pick something new up, and saw a refernce about using d3 SVG legend developed by Susie Lu. I had used their annotation tool before on a project (which I need to add in here on a day or two or three...). So Isued it on a project, and what I would normally spend time messing about on, it juts worked - BAM - like that.
const legend = svg
.append("g")
.attr("class", "legendLinear")
.attr("transform", "translate(10,220)")
const legendLinear = d3.legendColor()
.shapeWidth(10)
.shapeHeight(10)
.shapePadding(5)
.orient('vertical')
.scale(scale_color)
.title("Number of SDA dwellings")
legend
.select(".legendLinear")
.call(legendLinear)
As ever code can be found here