chart = {
const svgHTML = html `<svg width="900" height="500" />`
const svg = d3.select(svgHTML)
svg.append('g')
.attr('class', 'donut-container')
.attr('transform', `translate(${ width / 2 },${ height / 2 })`)
.selectAll('path')
.data( pieArcs )
.join('path')
.style('stroke', 'white')
.style('stroke-width', 2)
.style('fill', d => colorScale( d.data.type ))
.attr('d', arc)
const text = svg.append('g')
.attr('class', 'labels-container')
.attr('transform', `translate(${ width / 2 },${ height / 2 })`)
.selectAll('text')
.data( pieArcs )
.join('text')
.attr('transform', d => `translate(${ labelArcs.centroid(d) })`)
.attr('text-anchor', 'middle')
text.selectAll('tspan')
.data( d => [
d.data.type,
d.data.value.toFixed(1) + ' kg'
])
.join('tspan')
.attr('x', 0)
.style('font-family', 'sans-serif')
.style('font-size', 12)
.style('font-weight', (d,i) => i ? undefined : 'bold')
.style('fill', '#222')
.attr('dy', (d,i) => i ? '1.2em' : 0 )
.text(d => d)
return svgHTML
}