Skip to content

Instantly share code, notes, and snippets.

@jgoodie
Created August 13, 2022 00:36
Show Gist options
  • Save jgoodie/5f64de3b5e9690f329d9754c7fb8de35 to your computer and use it in GitHub Desktop.
Save jgoodie/5f64de3b5e9690f329d9754c7fb8de35 to your computer and use it in GitHub Desktop.
Drag functions for simulation
drag = (simulation) => {
function dragstarted(event, d) {
d.fx = event.x;
d.fy = event.y;
simulation.alphaTarget(0.3).restart();
}
function dragged(event, d) {
d.fx = event.x;
d.fy = event.y;
}
function dragended(event, d) {
d.fx = null;
d.fy = null;
simulation.alphaTarget(0);
}
return d3.drag()
.on("start", dragstarted)
.on("drag", dragged)
.on("end", dragended);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment