function circleDrag_3(width, height, radius, svg) {
function onDragStart_22(event, d) {
d3.select(this)
.raise()
.attr('fill', 'yellow')
.attr('stroke', 'black');
d.tooltip = svg.append("text")
.attr("x", d.x)
.attr("y", d.y)
.attr("font-size", "15px")
.attr("fill", "black")
.text(`(${Math.round(d.x)}, ${Math.round(d.y)})`);
}
function onDrag_2_22(event, d) {
const x = Math.max(radius, Math.min(width - radius, event.x));
const y = Math.max(radius, Math.min(height - radius, event.y));
d.x = x;
d.y = y;
d3.select(this)
.attr('cx', x)
.attr('cy', y);
if (d.tooltip) {
d.tooltip
.attr("x", x + radius + 5)
.attr("y", y)
.text(`(${Math.round(x)}, ${Math.round(y)})`);
}
}
function onDragEnd_2_22(event, d) {
d3.select(this)
.attr('fill', d.color)
.attr('stroke', 'none');
if (d.tooltip) {
d.tooltip.remove();
d.tooltip = null;
}
}
return d3.drag()
.on('start', onDragStart_22)
.on('drag', onDrag_2_22)
.on('end', onDragEnd_2_22);
}