diff --git a/lib/network/modules/NodesHandler.js b/lib/network/modules/NodesHandler.js index a35cfce1..6d639a18 100644 --- a/lib/network/modules/NodesHandler.js +++ b/lib/network/modules/NodesHandler.js @@ -353,10 +353,10 @@ class NodesHandler { var dataset = this.body.data.nodes.getDataSet(); for (let nodeId in dataset._data) { - if (dataset._data.hasOwnProperty(nodeId)) { + if (dataset._data.hasOwnProperty(nodeId) && this.body.nodes.hasOwnProperty(nodeId)) { let node = this.body.nodes[nodeId]; if (dataset._data[nodeId].x != Math.round(node.x) || dataset._data[nodeId].y != Math.round(node.y)) { - dataArray.push({ id: nodeId, x: Math.round(node.x), y: Math.round(node.y) }); + dataArray.push({id: nodeId, x: Math.round(node.x), y: Math.round(node.y)}); } } } diff --git a/lib/network/modules/PhysicsEngine.js b/lib/network/modules/PhysicsEngine.js index 5c18d42b..b8f0a6ee 100644 --- a/lib/network/modules/PhysicsEngine.js +++ b/lib/network/modules/PhysicsEngine.js @@ -517,7 +517,7 @@ class PhysicsEngine { createPhysicsEdge(edgeId) { let edge = this.body.edges[edgeId]; - if (edge && edge.options.physics === true && edge.connected === true) { + if (edge && edge.options.physics === true) { let physicsEdge = { id: edge.id, connected: edge.connected, @@ -528,10 +528,13 @@ class PhysicsEngine { // can we rewrite SpringSolver to only use toId and not to.id // and remove these parameters to: { - id: edge.to.id + // if assumption above is not valid TODO update to.id and from.id when updating connected + // id: edge.to.id + id: edge.toId }, from: { - id: edge.from.id + // id: edge.from.id + id: edge.fromId }, options: { length: edge.length diff --git a/lib/network/modules/PhysicsWorker.js b/lib/network/modules/PhysicsWorker.js index 99586d71..dc8fd72a 100644 --- a/lib/network/modules/PhysicsWorker.js +++ b/lib/network/modules/PhysicsWorker.js @@ -132,7 +132,7 @@ class PhysicsWorker { optionsNode.options.mass = opts.mass; } } else { - console.warn('sending properties to unknown node'); + console.warn('sending properties to unknown node', data.id, data.options); } } else if (data.type === 'edge') { let edge = this.body.edges[data.id]; @@ -142,10 +142,10 @@ class PhysicsWorker { edge.connected = opts.connected; } } else { - console.warn('sending properties to unknown edge'); + console.warn('sending properties to unknown edge', data.id, data.options); } } else { - console.warn('sending properties to unknown element'); + console.warn('sending properties to unknown element', data.id, data.options); } } diff --git a/lib/network/modules/components/Node.js b/lib/network/modules/components/Node.js index b4aaee8e..825508cd 100644 --- a/lib/network/modules/components/Node.js +++ b/lib/network/modules/components/Node.js @@ -68,7 +68,10 @@ class Node { this.hover = false; this.labelModule = new Label(this.body, this.options); + // prevents sending connected messages on initial creation as it should be handled by added element + this.sendPhysicsUpdates = false; this.setOptions(options); + this.sendPhysicsUpdates = true; } get x() { @@ -206,7 +209,7 @@ class Node { physOpts.physics = options.physics; } - if (Object.keys(physOpts).length > 0) { + if (this.sendPhysicsUpdates && Object.keys(physOpts).length > 0) { this.body.emitter.emit('_physicsUpdate', {type: 'node', id: this.id, options: physOpts}); }