Published
Edited
Sep 15, 2021
2 forks
1 star
Insert cell
md`# D3 circle animation`
Insert cell
chart = {
const width = 1000
const height = 500
const svg = d3.select(DOM.svg(width, height));
const circle = svg.append('circle')
.attr('cx', Math.random() * 900)
.attr('cy', Math.random() * 400)
.attr('r', Math.random() * 80)
.attr('fill', `#${randomColour()}`)
.call(animate)
return svg.node();
}


Insert cell
function animate(circle) {
circle
.transition()
.duration(2000)
.attr('cx', Math.random() * 900)
.attr('cy', Math.random() * 400)
.attr('r', Math.random() * 80)
.attr('fill', `#${randomColour()}`)
.on('end', () => circle.call(animate))
}
Insert cell
function randomColour() {
return Math.floor(Math.random()*16777215).toString(16)
}
Insert cell
d3 = require("d3@5")
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