From 0285d3139f451a7b2d1e4747d473db2445e002f3 Mon Sep 17 00:00:00 2001 From: Gregor Weber Date: Mon, 1 Sep 2014 15:01:18 +0200 Subject: [PATCH] Refactored data manipulation connect handling --- lib/network/mixins/ManipulationMixin.js | 43 ++++++++++++++----------- 1 file changed, 24 insertions(+), 19 deletions(-) diff --git a/lib/network/mixins/ManipulationMixin.js b/lib/network/mixins/ManipulationMixin.js index 54e0498d..233f5f55 100644 --- a/lib/network/mixins/ManipulationMixin.js +++ b/lib/network/mixins/ManipulationMixin.js @@ -337,6 +337,7 @@ exports._releaseControlNode = function(pointer) { exports._handleConnect = function(pointer) { if (this._getSelectedNodeCount() == 0) { var node = this._getNodeAt(pointer); + var supportNodes, targetNode, targetViaNode, connectionEdge; if (node != null) { if (node.clusterSize > 1) { @@ -344,31 +345,35 @@ exports._handleConnect = function(pointer) { } else { this._selectObject(node,false); - // create a node the temporary line can look at - this.sectors['support']['nodes']['targetNode'] = new Node({id:'targetNode'},{},{},this.constants); - this.sectors['support']['nodes']['targetNode'].x = node.x; - this.sectors['support']['nodes']['targetNode'].y = node.y; - this.sectors['support']['nodes']['targetViaNode'] = new Node({id:'targetViaNode'},{},{},this.constants); - this.sectors['support']['nodes']['targetViaNode'].x = node.x; - this.sectors['support']['nodes']['targetViaNode'].y = node.y; - this.sectors['support']['nodes']['targetViaNode'].parentEdgeId = "connectionEdge"; + supportNodes = this.sectors['support']['nodes']; + + // create a node the temporary line can look at + supportNodes['targetNode'] = targetNode = new Node({id:'targetNode'},{},{},this.constants); + targetNode.x = node.x; + targetNode.y = node.y; + + supportNodes['targetViaNode'] = targetViaNode = new Node({id:'targetViaNode'},{},{},this.constants); + targetViaNode.x = node.x; + targetViaNode.y = node.y; + targetViaNode.parentEdgeId = "connectionEdge"; // create a temporary edge - this.edges['connectionEdge'] = new Edge({id:"connectionEdge",from:node.id,to:this.sectors['support']['nodes']['targetNode'].id}, this, this.constants); - this.edges['connectionEdge'].from = node; - this.edges['connectionEdge'].connected = true; - this.edges['connectionEdge'].smooth = true; - this.edges['connectionEdge'].selected = true; - this.edges['connectionEdge'].to = this.sectors['support']['nodes']['targetNode']; - this.edges['connectionEdge'].via = this.sectors['support']['nodes']['targetViaNode']; + this.edges['connectionEdge'] = connectionEdge = new Edge({id:"connectionEdge",from:node.id,to:targetNode.id}, this, this.constants); + connectionEdge.from = node; + connectionEdge.connected = true; + connectionEdge.smooth = true; + connectionEdge.selected = true; + connectionEdge.to = targetNode; + connectionEdge.via = targetViaNode; this.cachedFunctions["_handleOnDrag"] = this._handleOnDrag; this._handleOnDrag = function(event) { var pointer = this._getPointer(event.gesture.center); - this.sectors['support']['nodes']['targetNode'].x = this._XconvertDOMtoCanvas(pointer.x); - this.sectors['support']['nodes']['targetNode'].y = this._YconvertDOMtoCanvas(pointer.y); - this.sectors['support']['nodes']['targetViaNode'].x = 0.5 * (this._XconvertDOMtoCanvas(pointer.x) + this.edges['connectionEdge'].from.x); - this.sectors['support']['nodes']['targetViaNode'].y = this._YconvertDOMtoCanvas(pointer.y); + var supportNodes = this.sectors['support']['nodes']; + supportNodes['targetNode'].x = this._XconvertDOMtoCanvas(pointer.x); + supportNodes['targetNode'].y = this._YconvertDOMtoCanvas(pointer.y); + supportNodes['targetViaNode'].x = 0.5 * (this._XconvertDOMtoCanvas(pointer.x) + this.edges['connectionEdge'].from.x); + supportNodes['targetViaNode'].y = this._YconvertDOMtoCanvas(pointer.y); }; this.moving = true;