From 88a230dccfef0bce1c514044040401ba42405a5a Mon Sep 17 00:00:00 2001 From: Devin Howard Date: Mon, 11 Mar 2013 22:25:22 -0400 Subject: [PATCH] Revert "Revert "Drag around all selected nodes, not just one - implements #79"" This reverts commit 0a1b5d51d873851a9bf79b823e71b0f1f08e464c. --- .../Jit/graphsettings-event-handlers.js | 39 +++++++++---------- .../javascripts/Jit/graphsettings-model.js | 3 +- app/assets/javascripts/Jit/graphsettings.js | 1 + .../Jit/select-edit-delete-nodes-and-edges.js | 23 +++++++++++ 4 files changed, 44 insertions(+), 22 deletions(-) diff --git a/app/assets/javascripts/Jit/graphsettings-event-handlers.js b/app/assets/javascripts/Jit/graphsettings-event-handlers.js index 72e1fc8a..5c5659f3 100644 --- a/app/assets/javascripts/Jit/graphsettings-event-handlers.js +++ b/app/assets/javascripts/Jit/graphsettings-event-handlers.js @@ -73,24 +73,6 @@ function 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) { if (Mconsole.busy) return; @@ -157,10 +139,25 @@ function onDragMoveTopicHandler(node, eventInfo, e) { var pos = eventInfo.getPos(); // if it's a left click, move the node 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; - node.pos.setc(pos.x, pos.y); - node.data.$xloc = pos.x; - node.data.$yloc = pos.y; Mconsole.plot(); } // if it's a right click or holding down alt, start synapse creation ->third option is for firefox diff --git a/app/assets/javascripts/Jit/graphsettings-model.js b/app/assets/javascripts/Jit/graphsettings-model.js index 61ba0981..d9cd00c1 100644 --- a/app/assets/javascripts/Jit/graphsettings-model.js +++ b/app/assets/javascripts/Jit/graphsettings-model.js @@ -9,8 +9,9 @@ var MetamapsModel = new Object(); MetamapsModel.embed = false; -//array of all selected edges +//array of all selected edges, same for nodes MetamapsModel.selectedEdges = new Array(); +MetamapsModel.selectedNodes = new Array(); //is any showcard open right now? which one? MetamapsModel.showcardInUse = null; diff --git a/app/assets/javascripts/Jit/graphsettings.js b/app/assets/javascripts/Jit/graphsettings.js index 4d8eef7c..c69e52d8 100644 --- a/app/assets/javascripts/Jit/graphsettings.js +++ b/app/assets/javascripts/Jit/graphsettings.js @@ -480,6 +480,7 @@ function onDragEndTopicHandler(node, eventInfo, e, allowRealtime) { tempNode2 = null; tempInit = false; } else if (dragged != 0 && goRealtime) { + //TODO: dragged is invalid if multiple nodes were dragged saveLayout(dragged); } }//onDragEndTopicHandler diff --git a/app/assets/javascripts/Jit/select-edit-delete-nodes-and-edges.js b/app/assets/javascripts/Jit/select-edit-delete-nodes-and-edges.js index 47a845c8..dbd5c4ee 100644 --- a/app/assets/javascripts/Jit/select-edit-delete-nodes-and-edges.js +++ b/app/assets/javascripts/Jit/select-edit-delete-nodes-and-edges.js @@ -287,6 +287,29 @@ function deleteSelectedEdges() { 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) { var showDesc = edge.getData("showDesc"); if (! showDesc) {