function updateNested(svg, counter) {
const data = alphabet.filter((d,i) => (i) < counter % (alphabet.length + 1))
const groups = svg.selectAll('g')
.data(data, d => d.letter)
.join(
enter => {
const g = enter.append('g')
g.append('text')
.attr('fill','white');
g.append('circle')
.attr('r', 0)
.attr('fill','grey');
return g;
},
update => update,
exit => {
exit.select('text').transition()
.duration(500)
.attr('fill','red')
.attr('y', -5)
exit.select('circle').transition()
.duration(500)
.attr('r',0)
return exit.transition().delay(500).remove()
}
)
groups.select('text')
.text(d => d.letter)
.attr('x', (d, i) => (alphabet.findIndex(x => d.letter === x.letter) + 0.5) * width / 26)
.attr('y', width / 26)
.attr('text-anchor','middle')
.transition()
.duration(500)
.attr('fill','grey')
groups.select('circle')
.attr('cx', (d, i) => (alphabet.findIndex(x => d.letter === x.letter) + 0.5 )* width / 26 )
.attr('cy', width / 26 + 40)
.transition()
.ease(d3.easeBounce)
.duration(500)
.attr('r', (d) => d.frequency * width / 26 * 4)
}