Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Dragging an unselected node while another node is selected drags both
  • Loading branch information
sheymann committed May 19, 2015
1 parent efbc454 commit d415df4
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 26 deletions.
14 changes: 9 additions & 5 deletions examples/drag-nodes.html
Original file line number Diff line number Diff line change
Expand Up @@ -135,21 +135,25 @@
outerBorderSize: 3,
defaultNodeBorderColor: '#fff',
defaultNodeOuterBorderColor: 'rgb(236, 81, 72)',
enableEdgeHovering: true,
enableEdgeHovering: false,
edgeHoverHighlightNodes: 'circle',
}
});

// Instanciate the ActiveState plugin:
var activeState = sigma.plugins.activeState(s);
var keyboard = sigma.plugins.keyboard(s, s.renderers[0]);

// Initialize the dragNodes plugin:
var dragListener = sigma.plugins.dragNodes(s, s.renderers[0], activeState);

// Initialize the Select plugin:
var select = sigma.plugins.select(s, activeState);
select.bindKeyboard(keyboard);

// Initialize the dragNodes plugin:
var dragListener = sigma.plugins.dragNodes(s, s.renderers[0], activeState);
// Initialize the Keyboard plugin:
var keyboard = sigma.plugins.keyboard(s, s.renderers[0]);

// Bind the Keyboard and DragNodes plugins to the Select plugin:
select.bindKeyboard(keyboard).bindDragNodes(dragListener);

dragListener.bind('startdrag', function(event) {
console.log(event);
Expand Down
48 changes: 27 additions & 21 deletions plugins/sigma.plugins.dragNodes/sigma.plugins.dragNodes.js
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,6 @@
_renderer.settings({mouseEnabled: false, enableHovering: false});

_self.dispatchEvent('startdrag', {
node: _node,
captor: event,
renderer: _renderer
});
Expand All @@ -181,7 +180,6 @@

if (_drag) {
_self.dispatchEvent('drop', {
node: _node,
captor: event,
renderer: _renderer
});
Expand All @@ -197,7 +195,6 @@
_s.refresh();
}
_self.dispatchEvent('dragend', {
node: _node,
captor: event,
renderer: _renderer
});
Expand Down Expand Up @@ -248,28 +245,38 @@
// Drag multiple nodes, Keep distance
var x2, y2;
if(_a) {
var activeNodes = _a.nodes();
for(var i = 0; i < activeNodes.length; i++) {
var activeNodes = _a.nodes(),
isHoveredNodeActive;

// Delete old reference
if(_draggingNode != _node) {
delete activeNodes[i].alphaX;
delete activeNodes[i].alphaY;
}
// If hovered node is active, drag active nodes nodes
isHoveredNodeActive = (-1 < activeNodes.map(function(node) {
return node.id;
}).indexOf(_node.id));

// Calcul first position of activeNodes
if(!activeNodes[i].alphaX || !activeNodes[i].alphaY) {
if (isHoveredNodeActive) {
for(var i = 0; i < activeNodes.length; i++) {

activeNodes[i].alphaX = activeNodes[i].x - x;
activeNodes[i].alphaY = activeNodes[i].y - y;
}
// Delete old reference
if(_draggingNode != _node) {
delete activeNodes[i].alphaX;
delete activeNodes[i].alphaY;
}

// Move activeNodes to keep same distance between dragged nodes and active nodes
x2 = _node.x + activeNodes[i].alphaX;
y2 = _node.y + activeNodes[i].alphaY;
// Calcul first position of activeNodes
if(!activeNodes[i].alphaX || !activeNodes[i].alphaY) {

activeNodes[i].x = x2;
activeNodes[i].y = y2;
activeNodes[i].alphaX = activeNodes[i].x - x;
activeNodes[i].alphaY = activeNodes[i].y - y;
}

// Move activeNodes to keep same distance between dragged nodes
// and active nodes
x2 = _node.x + activeNodes[i].alphaX;
y2 = _node.y + activeNodes[i].alphaY;

activeNodes[i].x = x2;
activeNodes[i].y = y2;
}
}
}

Expand All @@ -281,7 +288,6 @@

_drag = true;
_self.dispatchEvent('drag', {
node: _node,
captor: event,
renderer: _renderer
});
Expand Down

0 comments on commit d415df4

Please sign in to comment.