patterns = {
const svg = d3
.create("svg")
.attr("width", 0)
.attr("height", 0);
const defs = svg.append("defs");
const patterns = defs
.selectAll("pattern")
.data(fillColorScale)
.join("pattern")
.attr("id", (_d, i) => `${patternIds[i].id}`)
.attr("x", 0)
.attr("y", 0)
.attr("width", 8)
.attr("height", 8)
.attr("patternUnits", "userSpaceOnUse")
.attr("patternContentUnits", "userSpaceOnUse")
.attr("patternTransform", "rotate(45)");
patterns.each(function(d) {
d3.select(this).call(path, d);
d3.select(this).call(path, "#fff");
});
function path(selection, fillColor) {
selection
.append("path")
.attr("stroke", fillColor)
.attr("stroke-opacity", fillColor === "#fff" ? 0 : 1)
.attr("stroke-width", 4)
.attr("stroke-linecap", "round")
.attr("stroke-linejoin", "round")
.attr("fill", "none")
.attr("pointer-events", "none")
.attr("d", "M0 2 H 8");
}
return svg.node();
}