{const svg = d3.create('svg')
.attr('width', widthDiamond)
.attr('height', heightDiamond);
for (const diamondColor of diamondColors) {
const g = svg.append('g')
.attr('transform', `translate(${groupX(diamondColor)},0)`)
for (const cut of diamondCuts) {
const count = colorToCutToCount.get(diamondColor)?.get(cut) ?? 0
g.append('rect')
.attr('x', barX(cut))
.attr('y', y(count))
.attr('width', barX.bandwidth())
.attr('height', y(0) - y(count))
.attr('fill', color(cut))
}
}
svg.append('g')
.attr('transform', `translate(0,${heightDiamond - marginDiamond.bottom})`)
.call(xAxisDiamond)
.call(g => g.select('.domain').remove())
.append('text')
.attr('x', widthDiamond / 2)
.attr('y', 30)
.attr('dominant-baseline', 'hanging')
.attr('text-align', 'middle')
.attr('fill', 'black')
.text('Diamond Color');
svg.append('g')
.attr('transform', `translate(${marginDiamond.left})`)
.call(yAxisDiamond)
.call(g => g.select('.domain').remove())
.append('text')
.attr('x', -50)
.attr('y', heightDiamond / 2)
.attr('dominant-baseline', 'middle')
.attr('text-align', 'end')
.attr('fill', 'black')
.text('Count');
return svg.node();}