box2 = (data) => {
const svg = d3
.create("svg")
.attr("width", width)
.attr("height", height)
.attr("viewBox", [0, 0, width, height])
.attr("style", "max-width: 100%; height: auto; height: intrinsic;");
const circles = svg
.selectAll("circle")
.data(data)
.enter()
.append("circle")
.attr("cx", (d) => attMap.cx.scale(d[attMap.cx.name]))
.attr("cy", (d) => attMap.cy.scale(d[attMap.cy.name]))
.attr("r", 20)
.attr("fill", (d) => attMap.fill.scale(d[attMap.fill.name]))
.attr("id", (d) => "circle-" + d.id)
.text((d) => "Circle " + d.id)
.call(d3.drag().on("drag", dragged));
function dragged(event, d) {
const newX = event.x;
const newY = event.y;
d3.select(this).attr("cx", newX).attr("cy", newY);
d[attMap.cy.name] = attMap.cy.scale.invert(newY);
d[attMap.cx.name] = attMap.cx.scale.invert(newX);
data.selected = d;
svg.property("value", data);
svg.dispatch("input");
}
svg.append("g").call(xAxis, attMap.cx.scale, height);
svg.append("g").call(yAxis, attMap.cy.scale);
return svg.node();
}