{
const element = this || scrollSVG(html`<svg width=${width} height=${svgHeight}></svg>`)
const svg = d3.select(element).select('svg')
const t = svg.transition().duration(1000)
const g = svg.selectAll('g')
.data(filteredFlowers, d => d.title)
.join(
enter => {
const flower = enter.append('g')
flower
.attr('transform', d => `translate(${d.translate})`)
.attr('opacity', 0)
.transition(t)
.attr('opacity', 1)
flower.selectAll('path')
.data(d => _.times(d.numPetals, i => ({rotate: i * (360 / d.numPetals), ...d})))
.join('path')
.attr('transform', d => `rotate(${d.rotate}) scale(${d.scale})`)
.attr('d', d => d.path)
.attr('fill', d => d.color)
.attr('fill-opacity', 0.5)
.attr('stroke-width', 2)
.attr('stroke', d => d.color)
flower.append('text')
.text(d => _.truncate(d.title, {length: 18}))
.style('font-size', '.7em')
.style('font-style', 'italic')
.attr('text-anchor', 'middle')
.attr('dy', '0.35em')
return flower
},
update => {
return update.transition(t)
.attr('transform', d => `translate(${d.translate})`)
},
exit => {
return exit
.transition(t)
.attr('opacity', 0)
.remove()
}
)
return element
}