function imshow(data, pixelSize, color) {
const flat = [].concat.apply([], data);
const [min, max] = d3.extent(flat);
const normalize = d => ((d-min)/(max-min));
const colorScale = d => color(normalize(d));
const shape = {x: data[0].length, y: data.length};
const canvas = DOM.canvas(shape.x, shape.y);
const context = canvas.getContext("2d");
canvas.style.width = `${shape.x * pixelSize}px`
canvas.style.height = `${shape.y * pixelSize}px`;
canvas.style.imageRendering = "pixelated";
const imageData = context.createImageData(shape.x, shape.y);
flat.forEach((d, i) => {
let color = isNaN(d) ? {r: 0, g: 0, b: 0} : d3.color(colorScale(d));
imageData.data[i*4 ] = color.r;
imageData.data[i*4+1] = color.g;
imageData.data[i*4+2] = color.b;
imageData.data[i*4+3] = 255;
});
context.putImageData(imageData, 0, 0);
return canvas;
}