From dc70824f4b681f1f643cf7b0130a6ef097ce53a5 Mon Sep 17 00:00:00 2001 From: jos Date: Fri, 18 Mar 2016 14:55:31 +0100 Subject: [PATCH] Some more fixes regarding custom id fields. Still broken! --- lib/network/modules/Clustering.js | 21 +++++++++---------- lib/network/modules/EdgesHandler.js | 8 +++---- lib/network/modules/ManipulationSystem.js | 9 ++++---- lib/network/modules/NodesHandler.js | 12 +++++------ .../components/edges/BezierEdgeDynamic.js | 4 +--- .../modules/components/edges/util/EdgeBase.js | 3 +++ 6 files changed, 26 insertions(+), 31 deletions(-) diff --git a/lib/network/modules/Clustering.js b/lib/network/modules/Clustering.js index d6c96a02..cfad1683 100644 --- a/lib/network/modules/Clustering.js +++ b/lib/network/modules/Clustering.js @@ -259,7 +259,6 @@ class ClusterEngine { _createClusterEdges (childNodesObj, childEdgesObj, clusterNodeProperties, clusterEdgeProperties) { let edge, childNodeId, childNode, toId, fromId, otherNodeId; let nodeIdField = this.body.data.nodes._fieldId; - let edgeIdField = this.body.data.edges._fieldId; // loop over all child nodes and their edges to find edges going out of the cluster // these edges will be replaced by clusterEdges. @@ -294,7 +293,7 @@ class ClusterEngine { // Only edges from the cluster outwards are being replaced. if (childNodesObj[otherNodeId] === undefined) { - createEdges.push({edge: edge, fromId: fromId, toId: toId}); + createEdges.push({edge, fromId, toId}); } } } @@ -312,12 +311,12 @@ class ClusterEngine { // set up the edge clonedOptions.from = createEdges[j].fromId; clonedOptions.to = createEdges[j].toId; - clonedOptions[edgeIdField] = 'clusterEdge:' + util.randomUUID(); //clonedOptions.id = '(cf: ' + createEdges[j].fromId + " to: " + createEdges[j].toId + ")" + Math.random(); // create the edge and give a reference to the one it replaced. - let newEdge = this.body.functions.createEdge(clonedOptions); - newEdge.clusteringEdgeReplacingId = edge.id; + let edgeId = 'clusterEdge:' + util.randomUUID(); + let newEdge = this.body.functions.createEdge(edgeId, clonedOptions); + newEdge.clusteringEdgeReplacingId = edgeId; // connect the edge. this.body.edges[newEdge.id] = newEdge; @@ -418,11 +417,9 @@ class ClusterEngine { clusterNodeProperties.y = pos.y; } - // force the ID to remain the same - clusterNodeProperties[nodeIdField] = clusterId; - // create the clusterNode - let clusterNode = this.body.functions.createNode(clusterNodeProperties, Cluster); + // force the ID to remain the same + let clusterNode = this.body.functions.createNode(clusterId, clusterNodeProperties, Cluster); clusterNode.isCluster = true; clusterNode.containedNodes = childNodesObj; clusterNode.containedEdges = childEdgesObj; @@ -536,6 +533,7 @@ class ClusterEngine { return } let clusterNode = this.body.nodes[clusterNodeId]; + let edgeIdField = this.body.data.edges._fieldId; let containedNodes = clusterNode.containedNodes; let containedEdges = clusterNode.containedEdges; @@ -629,10 +627,11 @@ class ClusterEngine { // apply the edge specific options to it. let id = 'clusterEdge:' + util.randomUUID(); - util.deepExtend(clonedOptions, {from: fromId, to: toId, hidden: false, physics: true, id: id}); + util.deepExtend(clonedOptions, {from: fromId, to: toId, hidden: false, physics: true}); + clonedOptions[edgeIdField] = id; // create it - let newEdge = this.body.functions.createEdge(clonedOptions); + let newEdge = this.body.functions.createEdge(transferEdge.id, clonedOptions); newEdge.clusteringEdgeReplacingId = transferEdge.id; this.body.edges[id] = newEdge; this.body.edges[id].connect(); diff --git a/lib/network/modules/EdgesHandler.js b/lib/network/modules/EdgesHandler.js index ba6b573c..cba4e0a3 100644 --- a/lib/network/modules/EdgesHandler.js +++ b/lib/network/modules/EdgesHandler.js @@ -259,7 +259,7 @@ class EdgesHandler { } var data = edgesData.get(id, {"showInternalIds" : true}); - edges[id] = this.create(data); + edges[id] = this.create(id, data); } if (doNotEmit === false) { @@ -290,7 +290,7 @@ class EdgesHandler { } else { // create edge - this.body.edges[id] = this.create(data); + this.body.edges[id] = this.create(id, data); dataChanged = true; } } @@ -339,9 +339,7 @@ class EdgesHandler { } } - create(properties) { - var idField = this.body.data.edges._fieldId; - var id = properties[idField]; + create(id, properties) { return new Edge(id, properties, this.body, this.options) } diff --git a/lib/network/modules/ManipulationSystem.js b/lib/network/modules/ManipulationSystem.js index 72b6778d..5d5d4cf0 100644 --- a/lib/network/modules/ManipulationSystem.js +++ b/lib/network/modules/ManipulationSystem.js @@ -541,16 +541,15 @@ class ManipulationSystem { */ _getNewTargetNode(x,y) { let controlNodeStyle = util.deepExtend({}, this.options.controlNodeStyle); - let idField = this.body.data.nodes._fieldId; - controlNodeStyle[idField] = 'targetNode' + util.randomUUID(); + let id = 'targetNode' + util.randomUUID(); controlNodeStyle.hidden = false; controlNodeStyle.physics = false; controlNodeStyle.x = x; controlNodeStyle.y = y; // we have to define the bounding box in order for the nodes to be drawn immediately - let node = this.body.functions.createNode(controlNodeStyle); + let node = this.body.functions.createNode(id, controlNodeStyle); node.shape.boundingBox = {left: x, right:x, top:y, bottom:y}; return node; @@ -957,8 +956,8 @@ class ManipulationSystem { this.body.nodeIndices.push(targetNode.id); // create a temporary edge - let connectionEdge = this.body.functions.createEdge({ - id: 'connectionEdge' + util.randomUUID(), + let id = 'connectionEdge' + util.randomUUID(); + let connectionEdge = this.body.functions.createEdge(id, { from: node.id, to: targetNode.id, physics: false, diff --git a/lib/network/modules/NodesHandler.js b/lib/network/modules/NodesHandler.js index fe5798bb..81184c78 100644 --- a/lib/network/modules/NodesHandler.js +++ b/lib/network/modules/NodesHandler.js @@ -224,12 +224,11 @@ class NodesHandler { * @private */ add(ids, doNotEmit = false) { - let id; let newNodes = []; for (let i = 0; i < ids.length; i++) { - id = ids[i]; + let id = ids[i]; let properties = this.body.data.nodes.get(id); - let node = this.create(properties); + let node = this.create(id, properties); newNodes.push(node); this.body.nodes[id] = node; // note: this may replace an existing node } @@ -260,7 +259,7 @@ class NodesHandler { else { dataChanged = true; // create node - node = this.create(data); + node = this.create(id, data); nodes[id] = node; } } @@ -291,12 +290,11 @@ class NodesHandler { /** * create a node + * @param {string} id * @param properties * @param constructorClass */ - create(properties, constructorClass = Node) { - var idField = this.body.data.nodes._fieldId; - var id = properties[idField]; + create(id, properties, constructorClass = Node) { return new constructorClass(id, properties, this.body, this.images, this.groups, this.options) } diff --git a/lib/network/modules/components/edges/BezierEdgeDynamic.js b/lib/network/modules/components/edges/BezierEdgeDynamic.js index 440ba2e3..92f58a01 100644 --- a/lib/network/modules/components/edges/BezierEdgeDynamic.js +++ b/lib/network/modules/components/edges/BezierEdgeDynamic.js @@ -77,9 +77,7 @@ class BezierEdgeDynamic extends BezierEdgeBase { physics: true, hidden: true }; - var idField = this.body.data.nodes._fieldId; - properties[idField] = nodeId; - var node = this.body.functions.createNode(properties); + var node = this.body.functions.createNode(nodeId, properties); this.body.nodes[nodeId] = node; this.via = node; this.via.parentEdgeId = this.id; diff --git a/lib/network/modules/components/edges/util/EdgeBase.js b/lib/network/modules/components/edges/util/EdgeBase.js index aa0741fe..7758afa7 100644 --- a/lib/network/modules/components/edges/util/EdgeBase.js +++ b/lib/network/modules/components/edges/util/EdgeBase.js @@ -2,6 +2,9 @@ let util = require("../../../../../util"); class EdgeBase { constructor(id, options, body, labelModule) { + if (id === undefined) { + throw new Error('edge id is undefined') + } this.id = id; this.body = body; this.labelModule = labelModule;