This can be achieved using a combination of JointJS events and document events. The graph display is encapsulated in a div :
<div id='diagram'></div>
Then add event handlers for JointJS, first the pointerdown event, where we save the initial drag position:
paper.on('blank:pointerdown', function(event, x, y) { dragStartPosition = { x: x, y: y}; } );
Then the end of the drag and drop (pointerup), when we delete the variable, we save the position in (it also acts as a flag, whether active drag and drop):
paper.on('cell:pointerup blank:pointerup', function(cellView, x, y) { delete dragStartPosition; });
Since JointJS does not raise the "move pointer to paper" event, we need to use the mousemove document mousemove . For example, using jQuery:
$("#diagram") .mousemove(function(event) { if (dragStartPosition) paper.translate( event.offsetX - dragStartPosition.x, event.offsetY - dragStartPosition.y); });
We get the coordinates of the start of the drag and the current position of the pointer and update the paper position by calling paper.translate() .
WARNING: if you are scaling paper (using paper.scale() ), you must also scale the initial drag position:
var scale = V(paper.viewport).scale(); dragStartPosition = { x: x * scale.sx, y: y * scale.sy};
After that, paper.translate() calls will be updated to the correct position.