chart = {
const svg = d3
.create("svg")
.attr('viewBox', [0, 0, width, width]);
const g = svg.append('g')
const polls = g.selectAll('.treemap')
.data(pollData)
.join('g')
.attr('class', 'treemap')
.attr('transform', (d,i) => `translate(${i%7 * width/7}, ${Math.floor(i/7) * width/7})`)
const getLeaves = (d) => {
const data = {name: 'emoji', children: d.polls};
const root = d3.hierarchy(data)
.sum(d => d.voters)
.sort((a, b) => b.voters - a.voters);
return treemap(root).leaves()
}
const leaf = polls.selectAll("g")
.data(d => getLeaves(d))
.join("g")
.attr("transform", d => {
console.log(d)
return `translate(${d.x0},${d.y0})`
});
leaf
.append("rect")
.attr("width", d => d.x1 - d.x0)
.attr("height", d => d.y1 - d.y0)
.attr("fill", (d,i) => colorList[i])
return svg.node();
}