{
const chart = DOM.svg(width, width),
g = d3.select(chart).append("g");
const gray = d3
.scaleLinear()
.domain(d3.extent(binned, d => d.length))
.range(["white", "black"]),
binColor = d3
.scaleOrdinal()
.domain([0, binned.length])
.range([].concat(d3.schemeCategory10, d3.schemePaired)),
x = d3
.scaleLinear()
.domain(d3.extent(data.flat()))
.range([10, width - 10]);
g.selectAll("rect")
.data(binned)
.enter()
.append("rect")
.attr("width", bin => x(bin.x1) - x(bin.x0))
.attr("height", bin => x(bin.x3) - x(bin.x2))
.attr("x", bin => x(bin.x0))
.attr("y", bin => x(bin.x2))
.attr("fill", bin => gray(bin.length))
.attr("stroke", "#555");
g.selectAll("g")
.data(binned)
.enter()
.append("g")
.attr("fill", (bin, i) => binColor(i))
.selectAll("circle")
.data(d => d)
.enter()
.append("circle")
.attr("cx", d => x(d[0]))
.attr("cy", d => x(d[1]))
.attr("r", 4)
.attr("stroke", "white");
return chart;
}