I have a set of D3 elements (they are text nodes, but I think it doesn't matter what type) to which I have attached drag and drop behavior:
paragraphs.enter().append("text")
.text(function (d, i) { return d })
.attr("x", function (d, i) { return (i + 1) * 32 })
.attr("y", function (d, i) { return (i + 1) * 16 })
.attr("fill", color)
.call(d3.drag()
.on("start", dragstarted)
.on("drag", dragged)
.on("end", dragended))
I would like the drag and drop behavior to be aware of how far the user dragged it using dragstart. Currently, I add attrin dragstarted, which marks the starting position, then draggedchecks the current position during and calculates it this way.
Is there a way to find the distance traveled since the drag startand drop without calculating it, simply from the drag events directly? I watched dx/ dy, but they seem to be calculated only from the moment of the last drag event, so the value is always in the lower digits.
source
share