Спасибо, Мута. Это то, что я в итоге сделал, и, кажется, работает нормально:
Данные:
data = d3.json('data.json')
.then(data => {data
.forEach(d => {
d.country = d.country;
d.population = +d.population * 1000;
d.flagurl = `../images/countryflags/`+d.country+`.png`;
});
console.log(data);
render(data);
});
const yPos = d => yScale(yValues(d));
Изображение
svg.append('g')
.selectAll('image')
.data(data)
.enter()
.append('image')
.attr('class', 'countryflag')
.attr('href', d => (d.flagurl))
.attr('width', 50)
.attr('height', 0.8*barHeight)
.attr('x', 0)
.attr('y', yPos)
.attr('opacity', 0)
.attr('transform', `translate(`+0.05*barHeight+`,`+0.1*barHeight+`)`)
// transition and delay
.transition()
//.attr ('y', yPos)
.attr ('opacity', 1)
//.attr('height', yScale.bandwidth())
.duration(animateDuration-625)
.delay(delay+animateDuration+375)
;