Search code examples
cytoscape.jscytoscape

Drag event for nodes in Cytoscape.js


I'm looking for an event that fires as a node is being dragged. I thought that tapdrag looked like what I wanted, but tapdrag fires whenever the mouse moves over the node only when the mouse button is not down (so the node's not being dragged, basically mouseover). I've tried several other events, but none seem to do what I need.

How can I fire an event as a node is being dragged? Specifically, I want to move another node while the first is being dragged, which I'd rather do without using a compound node.


Solution

  • Use the drag event.

    The events are all listed and documented: http://js.cytoscape.org/#events/collection-events

    You can manually .position() on the second node when the drag happens on the first node.

    To set rules for node placement, like moving two nodes in lockstep, use the automove extension: https://github.com/cytoscape/cytoscape.js-automove