How to get the selection which is being dragged in d3.js? -
How to get the selection which is being dragged in d3.js? -
i'm using d3 behavior api implement drag , drop functionality on chart. there're circles on chart, want create circles able move around when user dragging them.
but don't know how reference of circle beingness dragged user. in below code, , how reference of selection , current mouse position?
var drag = d3.behavior.drag() .on("dragstart", function(){ //do drag start stuff... console.log('drag start'); }) .on("drag", function(){ //hey we're dragging, let's update stuff }) .on("dragend", function(){ //we're done, end stuff console.log('drag end'); });
somebody please help!
you current selection from
d3.selection(this)
if want current mouse position, utilize code
d3.mouse(this)
that returns array, [0] returns x position of mouse, , [1] returns y position.
d3.js
Comments
Post a Comment