Skip to content Skip to sidebar Skip to footer

I Can Not Move My Nodes, The Force Diagram Does Not Apply In 3.js

In a previous question a user helped me with a problem that consisted in not knowing how to put images where the circles are. this time my problem is that I can not drag the nodes.

Solution 1:

Your event handlers need to be applied to the elements themselves rather than the canvas as a whole.

In this code (only existing in your Plunker project, but not in your question):

var drag_handler = d3.drag()
  .on("start", drag_start)
  .on("drag", drag_drag)
  .on("end", drag_end);

drag_handler(node);

Your variable node is the drawing. You actually want a collection of elements to affect which you get from functions like .enter(). Your variable NodeCircleEnter contains that collection so the particular line should be:

drag_handler(NodeCircleEnter);

This still leaves an issue where dragging on the labels themselves doesn't work. This is because the labels aren't children of the elements you set the handlers on.

Post a Comment for "I Can Not Move My Nodes, The Force Diagram Does Not Apply In 3.js"