Public
Edited
Jan 23, 2023
Fork of Zoom (SVG)
19 forks
14 stars
Insert cell
Insert cell
chart = {
const context = DOM.context2d(width, height);
const r = 1.5;

d3.select(context.canvas).call(d3.zoom()
.scaleExtent([1, 8])
.on("zoom", ({transform}) => zoomed(transform)));

function zoomed(transform) {
context.save();
context.clearRect(0, 0, width, height);
context.translate(transform.x, transform.y);
context.scale(transform.k, transform.k);
context.beginPath();
for (const [x, y] of data) {
context.moveTo(x + r, y);
context.arc(x, y, r, 0, 2 * Math.PI);
}
context.fill();
context.restore();
}

zoomed(d3.zoomIdentity);

return context.canvas;
}
Insert cell
height = 600
Insert cell
data = {
const randomX = d3.randomNormal(width / 2, 80);
const randomY = d3.randomNormal(height / 2, 80);
return Array.from({length: 2000}, () => [randomX(), randomY()]);
}
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