I am designing a visualization which begins with the user drawing points on the screen as shown here: https://jsfiddle.net/jtr13/j2yrknf3/25/
The relevant part of the code (inspired by this answer) is:
svg.on("mousedown", mousedown)
.on("mouseup", mouseup);
function mousedown() {
const new_x = xScale.invert(d3.pointer(event)[0]);
const new_y = yScale.invert(d3.pointer(event)[1]);
svg.append("circle")
.data([{x: new_x, y: new_y}])
.attr("cx", d => xScale(d.x))
.attr("cy", d => yScale(d.y))
.attr("r", "3");
svg.on("mousemove", mousemove);
}
function mousemove() {
const new_x = xScale.invert(d3.pointer(event)[0]);
const new_y = yScale.invert(d3.pointer(event)[1]);
svg.append("circle")
.data([{x: new_x, y: new_y}])
.attr("cx", d => xScale(d.x))
.attr("cy", d => yScale(d.y))
.attr("r", "3");
}
function mouseup() {
svg.on("mousemove", null);
}
The problem is that too many points are added during mousemove. I would like points to be added at about 1/5 or 1/10 of the current rate. I tried adding delays of various sorts and nothing worked. How can I slow down the drag behavior?