As you've surmised, you need to track whether a mousemove occurs
between mousedown and mouseup. If a mousemove occurs, you then need to
prevent the click event from firing. The psuedo code is something like
this:
function mousedown() {
dragging = true;
}
function mousemove() {
if (dragging) preventClick = true;
}
function mouseup() {
dragging = false;
}
function click() {
if (preventClick) {
d3.event.stopPropagation();
preventClick = false;
}
}
The other requirement is that your click event listener is capturing,
which means that it takes priority and receives the event before your
normal click listener. (Otherwise, you'd stop propagation after the
popup is triggered, which won't be very helpful.) You can specify a
capturing listener by using the third argument `true` to the `on`
operator: on("click", click, true).
Mike