Browse Source

Some more fixes regarding custom id fields. Still broken!

codeClimate
jos 8 years ago
parent
commit
dc70824f4b
6 changed files with 26 additions and 31 deletions
  1. +10
    -11
      lib/network/modules/Clustering.js
  2. +3
    -5
      lib/network/modules/EdgesHandler.js
  3. +4
    -5
      lib/network/modules/ManipulationSystem.js
  4. +5
    -7
      lib/network/modules/NodesHandler.js
  5. +1
    -3
      lib/network/modules/components/edges/BezierEdgeDynamic.js
  6. +3
    -0
      lib/network/modules/components/edges/util/EdgeBase.js

+ 10
- 11
lib/network/modules/Clustering.js View File

@ -259,7 +259,6 @@ class ClusterEngine {
_createClusterEdges (childNodesObj, childEdgesObj, clusterNodeProperties, clusterEdgeProperties) { _createClusterEdges (childNodesObj, childEdgesObj, clusterNodeProperties, clusterEdgeProperties) {
let edge, childNodeId, childNode, toId, fromId, otherNodeId; let edge, childNodeId, childNode, toId, fromId, otherNodeId;
let nodeIdField = this.body.data.nodes._fieldId; 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 // loop over all child nodes and their edges to find edges going out of the cluster
// these edges will be replaced by clusterEdges. // these edges will be replaced by clusterEdges.
@ -294,7 +293,7 @@ class ClusterEngine {
// Only edges from the cluster outwards are being replaced. // Only edges from the cluster outwards are being replaced.
if (childNodesObj[otherNodeId] === undefined) { 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 // set up the edge
clonedOptions.from = createEdges[j].fromId; clonedOptions.from = createEdges[j].fromId;
clonedOptions.to = createEdges[j].toId; clonedOptions.to = createEdges[j].toId;
clonedOptions[edgeIdField] = 'clusterEdge:' + util.randomUUID();
//clonedOptions.id = '(cf: ' + createEdges[j].fromId + " to: " + createEdges[j].toId + ")" + Math.random(); //clonedOptions.id = '(cf: ' + createEdges[j].fromId + " to: " + createEdges[j].toId + ")" + Math.random();
// create the edge and give a reference to the one it replaced. // 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. // connect the edge.
this.body.edges[newEdge.id] = newEdge; this.body.edges[newEdge.id] = newEdge;
@ -418,11 +417,9 @@ class ClusterEngine {
clusterNodeProperties.y = pos.y; clusterNodeProperties.y = pos.y;
} }
// force the ID to remain the same
clusterNodeProperties[nodeIdField] = clusterId;
// create the clusterNode // 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.isCluster = true;
clusterNode.containedNodes = childNodesObj; clusterNode.containedNodes = childNodesObj;
clusterNode.containedEdges = childEdgesObj; clusterNode.containedEdges = childEdgesObj;
@ -536,6 +533,7 @@ class ClusterEngine {
return return
} }
let clusterNode = this.body.nodes[clusterNodeId]; let clusterNode = this.body.nodes[clusterNodeId];
let edgeIdField = this.body.data.edges._fieldId;
let containedNodes = clusterNode.containedNodes; let containedNodes = clusterNode.containedNodes;
let containedEdges = clusterNode.containedEdges; let containedEdges = clusterNode.containedEdges;
@ -629,10 +627,11 @@ class ClusterEngine {
// apply the edge specific options to it. // apply the edge specific options to it.
let id = 'clusterEdge:' + util.randomUUID(); 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 // create it
let newEdge = this.body.functions.createEdge(clonedOptions);
let newEdge = this.body.functions.createEdge(transferEdge.id, clonedOptions);
newEdge.clusteringEdgeReplacingId = transferEdge.id; newEdge.clusteringEdgeReplacingId = transferEdge.id;
this.body.edges[id] = newEdge; this.body.edges[id] = newEdge;
this.body.edges[id].connect(); this.body.edges[id].connect();

+ 3
- 5
lib/network/modules/EdgesHandler.js View File

@ -259,7 +259,7 @@ class EdgesHandler {
} }
var data = edgesData.get(id, {"showInternalIds" : true}); var data = edgesData.get(id, {"showInternalIds" : true});
edges[id] = this.create(data);
edges[id] = this.create(id, data);
} }
if (doNotEmit === false) { if (doNotEmit === false) {
@ -290,7 +290,7 @@ class EdgesHandler {
} }
else { else {
// create edge // create edge
this.body.edges[id] = this.create(data);
this.body.edges[id] = this.create(id, data);
dataChanged = true; 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) return new Edge(id, properties, this.body, this.options)
} }

+ 4
- 5
lib/network/modules/ManipulationSystem.js View File

@ -541,16 +541,15 @@ class ManipulationSystem {
*/ */
_getNewTargetNode(x,y) { _getNewTargetNode(x,y) {
let controlNodeStyle = util.deepExtend({}, this.options.controlNodeStyle); 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.hidden = false;
controlNodeStyle.physics = false; controlNodeStyle.physics = false;
controlNodeStyle.x = x; controlNodeStyle.x = x;
controlNodeStyle.y = y; controlNodeStyle.y = y;
// we have to define the bounding box in order for the nodes to be drawn immediately // 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}; node.shape.boundingBox = {left: x, right:x, top:y, bottom:y};
return node; return node;
@ -957,8 +956,8 @@ class ManipulationSystem {
this.body.nodeIndices.push(targetNode.id); this.body.nodeIndices.push(targetNode.id);
// create a temporary edge // 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, from: node.id,
to: targetNode.id, to: targetNode.id,
physics: false, physics: false,

+ 5
- 7
lib/network/modules/NodesHandler.js View File

@ -224,12 +224,11 @@ class NodesHandler {
* @private * @private
*/ */
add(ids, doNotEmit = false) { add(ids, doNotEmit = false) {
let id;
let newNodes = []; let newNodes = [];
for (let i = 0; i < ids.length; i++) { for (let i = 0; i < ids.length; i++) {
id = ids[i];
let id = ids[i];
let properties = this.body.data.nodes.get(id); let properties = this.body.data.nodes.get(id);
let node = this.create(properties);
let node = this.create(id, properties);
newNodes.push(node); newNodes.push(node);
this.body.nodes[id] = node; // note: this may replace an existing node this.body.nodes[id] = node; // note: this may replace an existing node
} }
@ -260,7 +259,7 @@ class NodesHandler {
else { else {
dataChanged = true; dataChanged = true;
// create node // create node
node = this.create(data);
node = this.create(id, data);
nodes[id] = node; nodes[id] = node;
} }
} }
@ -291,12 +290,11 @@ class NodesHandler {
/** /**
* create a node * create a node
* @param {string} id
* @param properties * @param properties
* @param constructorClass * @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) return new constructorClass(id, properties, this.body, this.images, this.groups, this.options)
} }

+ 1
- 3
lib/network/modules/components/edges/BezierEdgeDynamic.js View File

@ -77,9 +77,7 @@ class BezierEdgeDynamic extends BezierEdgeBase {
physics: true, physics: true,
hidden: 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.body.nodes[nodeId] = node;
this.via = node; this.via = node;
this.via.parentEdgeId = this.id; this.via.parentEdgeId = this.id;

+ 3
- 0
lib/network/modules/components/edges/util/EdgeBase.js View File

@ -2,6 +2,9 @@ let util = require("../../../../../util");
class EdgeBase { class EdgeBase {
constructor(id, options, body, labelModule) { constructor(id, options, body, labelModule) {
if (id === undefined) {
throw new Error('edge id is undefined')
}
this.id = id; this.id = id;
this.body = body; this.body = body;
this.labelModule = labelModule; this.labelModule = labelModule;

Loading…
Cancel
Save