chart = {
const svg = d3.create('svg')
.attr('width', width)
.attr('height', height)
const rects = d3.range( Math.ceil(height/rectWidth) * Math.ceil(width/rectWidth) )
svg.selectAll('rect')
.data( rects )
.join('rect')
.attr('class', d => 'rect-' + d)
.attr('width', rectWidth)
.attr('height', rectWidth)
.attr('x', (d,i) => rectWidth * (i % (width/rectWidth)))
.attr('y', (d,i) => Math.floor( i/(width/rectWidth) ) * rectWidth)
.style('stroke', 'white')
.style('cursor', 'pointer')
.style('fill', (d,i) => {
const x = rectWidth * (i % (width/rectWidth)),
y = Math.floor( i/(width/rectWidth) ) * rectWidth,
dist = Math.hypot( x, y )
return d3.interpolateSpectral( dist / Math.hypot( width, height ) )
})
return svg.node()
}