简体   繁体   中英

D3 multiple drag handlers

Is it possible to have more than one element with a .call(drag) on it in a force graph?

In my example I have <circle/> s and <rect/> s. The <circle/> s are part of my force simulation and the <rect/> s are not. I would like to be able to drag both of them, using separate drag handlers of course. The <circle/> s are draggable but the <rect/> s are not. According to some examples I've found it seems totally possible to have a drag event that is not part of a force simulation. But I have no evidence of them working in tandem.

Related fiddle:

The circular nodes are draggable but the squares in the top left of the graph are not. How can I make both of them draggable? I do not want the squares as part of the simulation as I do not want the forces applied to them.

https://jsfiddle.net/jrymer/ftv94rzk/53/

Seems even though the simulation does not use the data , I still need to respect the simulation 's internal timer and use it's tick function to reposition as I drag. I have update the original fiddle to reflect this. The rectangles I added do not effect the nodes force wise, but can still be dragged, which was my goal.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM