I'm roughly familiar with how dragging works in d3. But I found something that flummoxed me recently.
Following through the code to create a force directed graph I can't follow the code to deal with dragging the nodes around:
function dragstarted(d) {
if (!d3.event.active) simulation.alphaTarget(0.3).restart();
d.fx = d.x;
d.fy = d.y;
}
function dragged(d) {
d.fx = d3.event.x;
d.fy = d3.event.y;
}
function dragended(d) {
if (!d3.event.active) simulation.alphaTarget(0);
d.fx = null;
d.fy = null;
}
Any idea why we're checking the if statement here in dragstarted and dragended?
I tried removing the if-condition and didn't really see much of a difference with the force directed graph. That is, instead of
if (!d3.event.active) simulation.alphaTarget(0.3).restart();
I put
simulation.alphaTarget(0.3).restart();
and didn't see much of a difference.