Public
Edited
May 1, 2023
Insert cell
Insert cell
Insert cell
viz = d3.select(svgContainer) // the usual d3 select of the main SVG container
Insert cell
circles = viz.select("#circlesLayer").selectAll("circle") // randomly placed circles to have something to zoom
.data(d3.range(10))
.join("circle")
.attr("cx", () => 50 + Math.random() * 400)
.attr("cy", () => 50 + Math.random() * 200)
.attr("r", 20)
.style("fill", d => d3.schemeCategory10[d])
.style("stroke", "#777")
Insert cell
Insert cell
viz.call(d3.zoom() // the viz svg does the call (could also be a sub group)
.extent([[0,0],[500,300]])
.scaleExtent([1,20])
.on("zoom", zoomed));
Insert cell
function zoomed({transform}) {viz.select("#circlesLayer").attr("transform", transform).style("stroke-width", 1/transform.k);}
// the circlesLayer <g> gets the zoomed transform
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