Here .clickDistance()
is used together with some manual checking to do certain stuff like calling .raise()
only outside the distance otherwise the click
event might not get triggered (because the element got removed from the DOM before release of the mouse button).
Related to https://bl.ocks.org/mbostock/22994cc97fefaeede0d861e6815a847e (this one it is based on), https://bl.ocks.org/mbostock/a84aeb78fea81e1ad806 (unlike that example this here allows for a tiny bit of movement → unstable clicks). See also the discussion at https://github.com/d3/d3-drag/issues/48 to make the need for additional manual checking go away.
https://d3js.org/d3.v4.min.js