{
const svg = d3
.create('svg')
.attr('width', width)
.attr('height', height);
const realWidth = width - margin * 2;
const realHeight = height - margin * 2;
while (true) {
const realDataset = createData(dataLength, dataMax, Math.random());
const gEnter = enter =>
enter
.append('rect')
.classed('bargraph', true)
.attr('fill', 'black')
.attr(
'transform',
(d, i) => `translate(${(i / dataLength) * realWidth},${realHeight})`
)
.attr('width', realWidth / dataLength)
.attr('height', 0)
.call(enter =>
enter
.transition(d3.easeLinear)
.duration(duration)
.attr(
'transform',
(d, i) =>
`translate(${(i / dataLength) * realWidth},${(d / dataMax) *
realHeight})`
)
.attr('height', (d, i) => (dataMax / d) * realHeight)
);
const gUpdate = update =>
update.call(update =>
update
.transition(d3.easeLinear)
.duration(duration)
.attr(
'transform',
(d, i) =>
`translate(${(i / dataLength) * realWidth},${(d / dataMax) *
realHeight})`
)
.attr('height', (d, i) => (dataMax / d) * realHeight)
);
const gExit = exit => exit.call(exit => exit.transition(duration).remove());
svg
.selectAll('.bargraph')
.data(realDataset)
.join(gEnter, gUpdate, gExit);
yield svg.node();
await Promises.tick(duration);
}
}