I've noticed that when I use d3.drag().on('drag',...)
, it fires even when the mouse is not moved. Using the code snippet below (which I pulled from this question), if I simply click and release I still see drag event 1
in the console.
This is an issue because I want to be able to differentiate between a dblclick
and a drag. I've looked at this post and this one, but have been unable to get those solutions to work (it could be because those are old answers and I'm using D3 v4). I did notice that in the fiddle in one of the answers, it's displaying the same issue: both a click event a drag event.
I figured that the drag
event would only be fired if the mouse moved and then I could use it to set a flag that would mark it as dragging, not a doubleclick. However, this doesn't work if drag gets triggered on mouse press.
Very open to suggestions on this one as well as explanations as to why drag
is behaving in this way. I realize this is browser dependent, so I am running Chrome 64.
var count = 0;
d3.select("svg").call(d3.drag().on("start", function() {
console.log("drag started")
}).on("drag", function() {
++count;
console.log("drag event " + count)
}).on("end", function() {
count = 0;
console.log("drag ended")
}))
.as-console-wrapper { max-height: 20% !important;}
svg {
border: 1px solid black;
}
<script src="https://d3js.org/d3.v4.min.js"></script>
<svg></svg>