sunburst = () => {
const svg = d3.create("svg")
.attr('width', dimensions.width)
.attr('height', dimensions.height)
.attr('x', 0)
.attr('y', 0)
.attr('class', 'sunburst-wrapper')
.attr('id', 'root')
.attr(
'viewBox',
`-${dimensions.width / 2} -${dimensions.height / 2} ${
dimensions.width
} ${dimensions.height}`
)
.append('g')
svg.selectAll('path')
.each((node, i) => {
oldNodes[i] = node;
})
.data(data_2.descendants())
.join(
(enter) =>
enter
.append('path')
.attr('id', (d, i) => `segment-${i}`)
.attr('fill', (d) => 'white')
.attr('fill-opacity', 0)
.call(
async (enter) =>
enter
.transition()
.attr('d', (d) => {
console.log('d')
console.log(arc(d.current))
return arc(d.current);
})
.attr('fill-opacity', 1)
.attr('fill', 'slategrey')
),
(update) =>
update.call(
async (update) =>
await update
.transition()
.tween('data', (d) => {
const oldNode = oldNodes.find(
(node) => node.data.id === d.data.id
);
d.previous = oldNode ? oldNode.current : defaultNode;
const i = d3.interpolate(d.previous, d.current);
return (t) => (d.previous = i(t));
})
.attrTween('d', (d) => () => arc(d.previous))
.end(),
update
.attr('fill', 'red')
.attr('fill-opacity', 1)
),
(exit) =>
exit.call(async (exit) =>
await exit
.transition()
.attr('fill-opacity', 0)
.remove()
.end()
)
)
return svg.node();
}