ditheredHeatmap = (values, { width, px = 1, ...options }) => {
const [lo, hi] = d3.extent(values);
const r = 1 / (hi - lo);
return heatmap(
values.map((d, i) => {
const x = Math.floor((i % width) / px);
const y = Math.floor(Math.floor(i / width) / px);
if (px > 1) d = values[(x + y * width) * px];
return interleavedGradientNoise(x, y) < (d - lo) * r;
}),
{ width, ...options }
);
}