fixed problems with multiple node selection dragging (#79)
This commit is contained in:
parent
88a230dccf
commit
e54c4e24ed
2 changed files with 51 additions and 16 deletions
|
@ -132,6 +132,28 @@ function canvasDoubleClickHandler(canvasLoc,e) {
|
||||||
}
|
}
|
||||||
}//canvasDoubleClickHandler
|
}//canvasDoubleClickHandler
|
||||||
|
|
||||||
|
function handleSelectionBeforeDragging(node, e) {
|
||||||
|
// four cases:
|
||||||
|
// 1 nothing is selected, so pretend you aren't selecting
|
||||||
|
// 2 others are selected only and shift, so additionally select this one
|
||||||
|
// 3 others are selected only, no shift: drag only this one
|
||||||
|
// 4 this node and others were selected, so drag them (just return false)
|
||||||
|
//return value: deselect node again after?
|
||||||
|
if (MetamapsModel.selectedNodes.length == 0) {
|
||||||
|
selectNode(node);
|
||||||
|
return 'deselect';
|
||||||
|
}
|
||||||
|
if (MetamapsModel.selectedNodes.indexOf(node) == -1) {
|
||||||
|
if (e.shiftKey) {
|
||||||
|
selectNode(node);
|
||||||
|
return 'nothing';
|
||||||
|
} else {
|
||||||
|
return 'only-drag-this-one';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return 'nothing'; //case 4?
|
||||||
|
}
|
||||||
|
|
||||||
function onDragMoveTopicHandler(node, eventInfo, e) {
|
function onDragMoveTopicHandler(node, eventInfo, e) {
|
||||||
if (node && !node.nodeFrom) {
|
if (node && !node.nodeFrom) {
|
||||||
$('#new_synapse').fadeOut('fast');
|
$('#new_synapse').fadeOut('fast');
|
||||||
|
@ -139,6 +161,13 @@ 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)) {
|
||||||
|
//if the node dragged isn't already selected, select it
|
||||||
|
var whatToDo = handleSelectionBeforeDragging(node, e);
|
||||||
|
if (whatToDo == 'only-drag-this-one') {
|
||||||
|
node.pos.setc(pos.x, pos.y);
|
||||||
|
node.setData('xloc', pos.x);
|
||||||
|
node.setData('yloc', pos.y);
|
||||||
|
} else {
|
||||||
var len = MetamapsModel.selectedNodes.length;
|
var len = MetamapsModel.selectedNodes.length;
|
||||||
|
|
||||||
//first define offset for each node
|
//first define offset for each node
|
||||||
|
@ -148,15 +177,19 @@ function onDragMoveTopicHandler(node, eventInfo, e) {
|
||||||
n = MetamapsModel.selectedNodes[i];
|
n = MetamapsModel.selectedNodes[i];
|
||||||
xOffset[i] = n.getData('xloc') - node.getData('xloc');
|
xOffset[i] = n.getData('xloc') - node.getData('xloc');
|
||||||
yOffset[i] = n.getData('yloc') - node.getData('yloc');
|
yOffset[i] = n.getData('yloc') - node.getData('yloc');
|
||||||
}
|
}//for
|
||||||
|
|
||||||
for (var i = 0; i < len; i += 1) {
|
for (var i = 0; i < len; i += 1) {
|
||||||
n = MetamapsModel.selectedNodes[i];
|
n = MetamapsModel.selectedNodes[i];
|
||||||
n.pos.setc(pos.x + xOffset[i], pos.y + yOffset[i]);
|
n.pos.setc(pos.x + xOffset[i], pos.y + yOffset[i]);
|
||||||
n.setData('xloc', pos.x + xOffset[i]);
|
n.setData('xloc', pos.x + xOffset[i]);
|
||||||
n.setData('yloc', pos.y + yOffset[i]);
|
n.setData('yloc', pos.y + yOffset[i]);
|
||||||
}
|
}//for
|
||||||
|
}//if
|
||||||
|
|
||||||
|
if (whatToDo == 'deselect') {
|
||||||
|
deselectNode(node);
|
||||||
|
}
|
||||||
dragged = node.id;
|
dragged = node.id;
|
||||||
Mconsole.plot();
|
Mconsole.plot();
|
||||||
}
|
}
|
||||||
|
|
|
@ -288,6 +288,7 @@ function deleteSelectedEdges() {
|
||||||
}
|
}
|
||||||
|
|
||||||
function selectNode(node) {
|
function selectNode(node) {
|
||||||
|
if (MetamapsModel.selectedNodes.indexOf(node) != -1) return;
|
||||||
node.selected = true;
|
node.selected = true;
|
||||||
node.setData('dim', 30, 'current');
|
node.setData('dim', 30, 'current');
|
||||||
node.setData('onCanvas',true);
|
node.setData('onCanvas',true);
|
||||||
|
@ -311,6 +312,7 @@ function deselectNode(node) {
|
||||||
}
|
}
|
||||||
|
|
||||||
function selectEdge(edge) {
|
function selectEdge(edge) {
|
||||||
|
if (MetamapsModel.selectedEdges.indexOf(edge) != -1) return;
|
||||||
var showDesc = edge.getData("showDesc");
|
var showDesc = edge.getData("showDesc");
|
||||||
if (! showDesc) {
|
if (! showDesc) {
|
||||||
edge.setData('showDesc', true, 'current');
|
edge.setData('showDesc', true, 'current');
|
||||||
|
|
Loading…
Reference in a new issue