Published
Edited
Dec 22, 2020
Insert cell
md`# V5 Zooming Visual`
Insert cell
chart = {
const svg = d3.create("svg")
.attr("width",width)
.attr("height",height);

const g = svg.append("g");

const circle = g.selectAll("circle")
.data(data)
.enter().append("circle")
.attr("cx", ([x]) => x)
.attr("cy", ([, y]) => y)
.attr("r", radius)
.attr("fill", (d, i) => d3.interpolateRainbow(i / 360));

svg.call(d3.zoom()
.scaleExtent([1, 10])
.on("zoom", zoom));
function zoom() {
g.attr("transform", d3.event.transform);
}
return svg.node();
}
Insert cell
data = Array.from({length: 2000}, (_, i) => {
const radius = step * Math.sqrt(i += 0.5), a = theta * i;
return [
width / 2 + radius * Math.cos(a),
height / 2 + radius * Math.sin(a)
];
})
Insert cell
step=radius*2
Insert cell
radius = 3
Insert cell
theta = Math.PI * (3 - Math.sqrt(5))
Insert cell
width=1000
Insert cell
height=700
Insert cell
d3=require("d3@5");
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