{
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 g = enter
.append("g")
.attr("opacity", 0)
.attr("transform", (d) => `translate(${d.translate})`);
g.selectAll("path")
.data((d) =>
_.times(d.numPetals, (i) => {
return { 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("stroke", (d) => d.color)
.attr("fill-opacity", 0.5)
.attr("stroke-width", 2);
g.append("text")
.attr("text-anchor", "middle")
.attr("dy", ".35em")
.style("font-size", ".7em")
.text((d) => _.truncate(d.title, { length: 18 }));
return g;
},
(update) => update,
exit => {
exit.transition(t)
.attr('opacity', 0)
.remove()
}
)
.transition(t)
.attr("opcaity", 1)
.attr("transform", (d) => `translate(${d.translate})`);
return element;
}