Published
Edited
Mar 25, 2021
36 forks
Comments locked
22 stars
Insert cell
Insert cell
Insert cell
Insert cell
g = svg.selectAll('g')
.data(flowers).enter().append('g')
Insert cell
Insert cell
text = g.append('text')
Insert cell
Insert cell
path = g.selectAll('path')
.data(d => {
return _.times(d.numPetals, i => {
// create a copy of the parent data, and add in calculated rotation
return Object.assign({}, d, {rotate: i * (360 / d.numPetals)})
})
}).enter().append('path')
Insert cell
Insert cell
Insert cell
{
g.attr('transform', (d, i) => `translate(${d.translate})`)
text.attr('text-anchor', 'middle')
.attr('dy', '.35em')
.style('font-size', '.7em')
.style('font-style', 'italic')
.text(d => _.truncate(d.title, {length: 20}))
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', d => d.color)
}
Insert cell
Insert cell
{
const svg = html`<svg width=${width} height=${svgHeight}></svg>`
// ✨ OUR CODE HERE
return scrollSVG(svg)
}
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell

One platform to build and deploy the best data apps

Experiment and prototype by building visualizations in live JavaScript notebooks. Collaborate with your team and decide which concepts to build out.
Use Observable Framework to build data apps locally. Use data loaders to build in any language or library, including Python, SQL, and R.
Seamlessly deploy to Observable. Test before you ship, use automatic deploy-on-commit, and ensure your projects are always up-to-date.
Learn more