moveNodeDrag method
Moves nodes during a drag operation.
Call this from NodeWidget's GestureDetector.onPanUpdate. The delta is already in graph coordinates since GestureDetector is inside InteractiveViewer's transformed space - no conversion needed.
Parameters:
graphDelta: The movement delta in graph coordinates
Implementation
void moveNodeDrag(Offset graphDelta) {
final draggedNodeId = interaction.draggedNodeId.value;
if (draggedNodeId == null) return;
// Collect nodes that will be moved for event firing
final movedNodes = <Node<T>>[];
// Get nodes to move
final nodeIdsToMove = selectedNodeIds.contains(draggedNodeId)
? selectedNodeIds.toList()
: [draggedNodeId];
final context = _createDragContext();
runInAction(() {
// Update node positions and visual positions
for (final nodeId in nodeIdsToMove) {
final node = _nodes[nodeId];
if (node != null) {
final newPosition = node.position.value + graphDelta;
node.position.value = newPosition;
// Update visual position with snapping
node.setVisualPosition(_config.snapToGridIfEnabled(newPosition));
movedNodes.add(node);
// Notify the node of its own drag move
node.onDragMove(graphDelta, context);
}
}
});
// Mark moved nodes dirty for spatial index
internalMarkNodesDirty(movedNodes.map((n) => n.id));
// Fire drag event for all moved nodes
for (final node in movedNodes) {
events.node?.onDrag?.call(node);
}
}