chart = {
const svg = d3.create("svg")
.attr("viewBox", [0, 0, width, height]);
const g = svg.append('g')
.attr("transform", `translate(80, 30)`)
const cellSize = 45;
const cells = g.selectAll('rects')
.data(data).enter()
.append('rect')
.attr('width', cellSize - 1)
.attr('height', cellSize - 1)
.attr("transform", (d) => {
const [i, j] = position.get(d.statecode);
return `translate(${i * cellSize},${j * cellSize})`;
})
.attr('fill', (d) => getColor(type, d[type]) );
const texts = g.selectAll('texts')
.data(data).enter()
.append('text')
.attr("x", cellSize / 2)
.attr("y", cellSize / 2 + 5)
.attr("transform", (d) => {
const [i, j] = position.get(d.statecode);
return `translate(${i * cellSize},${j * cellSize})`;
})
.attr("text-anchor", "middle")
.attr("font-family", "sans-serif")
.attr("font-size", 15)
.attr('fill', d => getTextColor(d[type]))
.text(d => d.statecode);
return svg.node();
}