Created
August 13, 2022 00:36
-
-
Save jgoodie/5f64de3b5e9690f329d9754c7fb8de35 to your computer and use it in GitHub Desktop.
Drag functions for simulation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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