chart = {
const svg = d3.create("svg")
.attr("viewBox", [0, 0, width, height]);
svg.style('border', '1px solid black')
let offset = { x: 0, y: 0 };
function dragstarted(event) {
d3.select(this).raise().attr("stroke", "black");
offset.x = event.x - d3.select(this).attr('x');
offset.y = event.y - d3.select(this).attr('y');
}
function dragged(event) {
d3.select(this)
.attr('x', event.x - offset.x)
}
function dragended(event) {
d3.select(this).attr("stroke", null);
}
const rect = svg.append('rect')
.attr('width', '100')
.attr('height', '100')
.attr('x', 10)
.attr('y', 100)
.attr('fill', 'red')
.style('border', '1px solid black')
.call(d3.drag()
.on("start", dragstarted)
.on("drag", dragged)
.on("end", dragended))
return svg.node();
}