The goal: When trying to drag a link, the nodes at both ends will be dragged (along with the link).
Look at this example, which is a copy of the minimal example except that a link is green, thick and selectable. If one would drag a node, the node would move. If you would drag the link between alpha and gamma, both nodes would move (if I could get put it to work).
note: the example incorporates all the work laid out below. Just save it to obtain your copy.
Solution A:
Overriding the method go.DraggingTool.prototype.computeEffectiveCollection and not only returning the link but also the fromNode and toNode.
var tool = myDiagram.toolManager.draggingTool;
tool.computeEffectiveCollection = function(parts) {
var functhis = this;
var map = go.DraggingTool.prototype.computeEffectiveCollection.call(this, parts);
console.log("computeEffective start on parts:");
parts.each(function(p){
console.log("part "+p.toString());
});
map.each(function(n) {
console.log("start map component: "+n.key.toString()+ " : "+n.value.point.toString());
console.assert(n.key.canMove(),"Wooooo is us, cant move "+n.toString());
});
parts.each(function(link) {
if (!link.isTreeLink) return;
console.log("link found to move");
// map.clear();
// var myparts= new go.Set;
// myparts.add(link.fromNode);
// tool.dragsTree=true;
// map = go.DraggingTool.prototype.computeEffectiveCollection.call(functhis, myparts);
map.add(link.fromNode,{point: link.fromNode.location});
map.add(link.toNode,{point: link.toNode.location});
map.add(link,{point: new go.Point(0,0)});
});
map.each(function(n) {
console.log("map component: "+n.key.toString()+ " : "+n.value.point.toString());
console.assert(n.key.canMove(),"Wooooo is us, cant move "+n.toString());
});
return map;
};
Alas, nothing moves. If you set draggingTool.dragsTree to true, then dragging gamma does result in dragging delta and the link as well. Dragging a tree works and standard computeEffectiveCollection function returns the same map as my revised function does. Yet despite the similar returned map, the dragging is not the same. I tried to alter the “parts” variable but you cant alter it anymore in this function.
Mark that simply turning on dragsTree doesnt work as I want to drag each node individually.
As indicated in the extentions page in the api, one could resort to subclassing iso overriding methods. I did do that but the results are identical to overriding.
Solution B:
If changing computeEffectiveCollection is not enough, we ll look at functions that fire there after.
tool.computeMove = function(n, newloc, draggedparts, result) {
console.log("start computeMove on "+n.toString());
draggedparts.each(function(n) {
console.log("start map component: "+n.key.toString()+ " : "+n.value.point.toString());
});
var ret = go.DraggingTool.prototype.computeMove.call(this,n, newloc, draggedparts, result);
// tool.dragsTree=false;
return ret;
};
Utterly useless because this function is not even executed when dragging a link. Only when dragging a node you can see it firing. So something in the draggingtool must be deciding to NOT execute computeMove in this case.
Solution C:
Lets try to “trick” the dragtool before he realises that we are handling a link. When finding what needs dragging, we return not the link but a node related to the link. By turning on temporarly the dragsTree property, the 2 nodes (and the whole subtree) will be dragged, I hope.
tool.findDraggablePart = function() {
console.log("findDraggablePart start");
var diagram = this.diagram;
var obj = diagram.findObjectAt(diagram.lastInput.documentPoint);
if (obj !== null) {
console.log("this "+obj.toString());
console.log(" is from part "+obj.part.toString());
obj=obj.part;
if (obj !== null && obj.isTreeLink) {
console.log("yay! returning "+obj.fromNode.toString());
return obj.fromNode;
} else {
var newobj = go.DraggingTool.prototype.findDraggablePart.call(this);
console.log("trad returns "+newobj.toString());
return newobj;
}
}
return null;
};
The code looks for the object to drag and when it is a link, we simply return the fromNode. This node would then be fed to computeEffectiveCollection I presumed, resulting in behaviour identical to a dragged tree. Alas, this function doesnt really did what I thought it would do because it has no influence on the input of computeEffectiveCollection. Even though returning the node in findDraggablePart , the computeEffectiveCollection function is called with only the link in the parameter parts.
Is there anyone who can shine his or her light as to what I might be misunderstanding or what the way to go could be?