Revert "Revert "Drag around all selected nodes, not just one - implements #79""

This reverts commit 0a1b5d51d8.
This commit is contained in:
Devin Howard 2013-03-11 22:25:22 -04:00
parent 0a1b5d51d8
commit 88a230dccf
4 changed files with 44 additions and 22 deletions

View file

@ -73,24 +73,6 @@ function nodeWasDoubleClicked() {
} }
}//nodeWasDoubleClicked; }//nodeWasDoubleClicked;
function selectNode(node) {
node.selected = true;
node.setData('dim', 30, 'current');
node.setData('onCanvas',true);
node.eachAdjacency(function (adj) {
selectEdge(adj);
});
}
function deselectNode(node) {
delete node.selected;
node.setData('onCanvas', false);
node.eachAdjacency(function(adj) {
deselectEdge(adj);
});
node.setData('dim', 25, 'current');
}
function selectNodeOnClickHandler(node, e) { function selectNodeOnClickHandler(node, e) {
if (Mconsole.busy) return; if (Mconsole.busy) return;
@ -157,10 +139,25 @@ function onDragMoveTopicHandler(node, eventInfo, e) {
var pos = eventInfo.getPos(); var pos = eventInfo.getPos();
// if it's a left click, move the node // if it's a left click, move the node
if (e.button == 0 && !e.altKey && (e.buttons == 0 || e.buttons == 1 || e.buttons == undefined)) { if (e.button == 0 && !e.altKey && (e.buttons == 0 || e.buttons == 1 || e.buttons == undefined)) {
var len = MetamapsModel.selectedNodes.length;
//first define offset for each node
var xOffset = new Array();
var yOffset = new Array();
for (var i = 0; i < len; i += 1) {
n = MetamapsModel.selectedNodes[i];
xOffset[i] = n.getData('xloc') - node.getData('xloc');
yOffset[i] = n.getData('yloc') - node.getData('yloc');
}
for (var i = 0; i < len; i += 1) {
n = MetamapsModel.selectedNodes[i];
n.pos.setc(pos.x + xOffset[i], pos.y + yOffset[i]);
n.setData('xloc', pos.x + xOffset[i]);
n.setData('yloc', pos.y + yOffset[i]);
}
dragged = node.id; dragged = node.id;
node.pos.setc(pos.x, pos.y);
node.data.$xloc = pos.x;
node.data.$yloc = pos.y;
Mconsole.plot(); Mconsole.plot();
} }
// if it's a right click or holding down alt, start synapse creation ->third option is for firefox // if it's a right click or holding down alt, start synapse creation ->third option is for firefox

View file

@ -9,8 +9,9 @@ var MetamapsModel = new Object();
MetamapsModel.embed = false; MetamapsModel.embed = false;
//array of all selected edges //array of all selected edges, same for nodes
MetamapsModel.selectedEdges = new Array(); MetamapsModel.selectedEdges = new Array();
MetamapsModel.selectedNodes = new Array();
//is any showcard open right now? which one? //is any showcard open right now? which one?
MetamapsModel.showcardInUse = null; MetamapsModel.showcardInUse = null;

View file

@ -480,6 +480,7 @@ function onDragEndTopicHandler(node, eventInfo, e, allowRealtime) {
tempNode2 = null; tempNode2 = null;
tempInit = false; tempInit = false;
} else if (dragged != 0 && goRealtime) { } else if (dragged != 0 && goRealtime) {
//TODO: dragged is invalid if multiple nodes were dragged
saveLayout(dragged); saveLayout(dragged);
} }
}//onDragEndTopicHandler }//onDragEndTopicHandler

View file

@ -287,6 +287,29 @@ function deleteSelectedEdges() {
MetamapsModel.selectedEdges = new Array(); MetamapsModel.selectedEdges = new Array();
} }
function selectNode(node) {
node.selected = true;
node.setData('dim', 30, 'current');
node.setData('onCanvas',true);
node.eachAdjacency(function (adj) {
selectEdge(adj);
});
MetamapsModel.selectedNodes.push(node);
}
function deselectNode(node) {
delete node.selected;
node.setData('onCanvas', false);
node.eachAdjacency(function(adj) {
deselectEdge(adj);
});
node.setData('dim', 25, 'current');
//remove the node
MetamapsModel.selectedNodes.splice(
MetamapsModel.selectedNodes.indexOf(node), 1);
}
function selectEdge(edge) { function selectEdge(edge) {
var showDesc = edge.getData("showDesc"); var showDesc = edge.getData("showDesc");
if (! showDesc) { if (! showDesc) {