chart = {
const svg = d3
.create("svg")
.attr("viewBox", [0, 0, width, height])
.attr("stroke-width", 2);
const squares = d3.range(10).map((i) => ({
x: Math.random() * (width - side),
y: Math.random() * (height - side),
index: i
}));
svg
.selectAll("rect")
.data(squares)
.join("rect")
.attr("x", (d) => d.x)
.attr("y", (d) => d.y)
.attr("width", side)
.attr("height", side)
.attr("fill", (d) => d3.schemeCategory10[d.index % 10])
.call(drag)
.on("click", clicked);
function clicked(event, d) {
if (event.defaultPrevented) return;
d3.select(this)
.transition()
.attr("fill", "black")
.attr("width", side * 1.5)
.attr("height", side * 1.5)
.attr("x", d.x - side / 4)
.attr("y", d.y - side / 4)
.transition()
.attr("width", side)
.attr("height", side)
.attr("x", d.x)
.attr("y", d.y)
.attr("fill", d3.schemeCategory10[d.index % 10]);
}
return svg.node();
}