svg = {
const rectangles = generateRectangles();
const svg = d3.create("svg").attr("viewBox", [0, 0, 400, 200]);
const g = svg.append("g");
g.selectAll("rect")
.data(rectangles)
.join("rect")
.attr("x", d => d.p1.x + 20)
.attr("y", d => d.p1.y + 0.5)
.attr('width', d => d.p2.x - d.p1.x - 1)
.attr('height', d => d.p2.y - d.p1.y - 1)
.style('fill', (d, i) => getRandomColor());
svg.call(
d3
.zoom()
.extent([[0, 0], [400, 200]])
.scaleExtent([1, 10])
.on("zoom", zoomed)
);
function zoomed({ transform }) {
g.attr("transform", transform);
}
return svg.node();
}