Public
Edited
Oct 20, 2022
Insert cell
Insert cell
height = 200
Insert cell
circleData = [
{
startSize: 30,
endSize: 60,
startFill: "orange",
endFill: "lime",
x: width / 3,
backgroundColor: "steelblue"
},
{
startSize: 80,
endSize: 40,
startFill: "magenta",
endFill: "cyan",
x: width / 2,
backgroundColor: "#cda"
},
{
startSize: 45,
endSize: 20,
startFill: "yellow",
endFill: "purple",
x: (width * 2) / 3,
backgroundColor: "teal"
}
]
Insert cell
{
//create SVG artboard
const svg = d3.create("svg").attr("width", width).attr("height", height);

//create svg background color
svg
.append("rect")
.attr("x", 0)
.attr("y", 0)
.attr("width", width)
.attr("height", height)
.attr("fill", "#002")
.attr("id", "background");

//create circle visualization
svg
.selectAll(".circles")
.data(circleData)
.enter()
.append("circle")
.attr("cx", (d) => d.x)
.attr("cy", height / 2)
.attr("r", (d) => d.startSize)
//take the line below out to see what happens if a property isn't set before animation
.attr("stroke-width", 0)
.attr("stroke", "white")
.attr("class", "circles")
.attr("fill", (d) => d.startFill)

.on("mouseover", (e, d) => {
d3.select(e.currentTarget)
.transition()
.duration(2000)
.ease(d3.easeBounceOut)
.attr("r", d.endSize)
.attr("fill", d.endFill)
.attr("stroke-width", 10);

d3.select("#background")
.transition()
.duration(1000)
.attr("fill", d.backgroundColor);
})
.on("mouseout", (e, d) => {
d3.select(e.currentTarget)
.transition()
.delay(500)
.duration(1500)
.attr("r", d.startSize)
.attr("stroke-width", "0")
.attr("fill", d.startFill);

d3.select("#background").transition().duration(1000).attr("fill", "#002");
});

return svg.node();
}
Insert cell

Purpose-built for displays of data

Observable is your go-to platform for exploring data and creating expressive data visualizations. Use reactive JavaScript notebooks for prototyping and a collaborative canvas for visual data exploration and dashboard creation.
Learn more