Browse Source

prevent physics update messages before nodes are constructed

additional debugging in PhysicsWorker
made assumption in createPhysicsEdge
bug fix for filtered data sets in NodesHandler
webworkersNetwork^2^2
Eric VanDever 9 years ago
parent
commit
387f7aa96e
4 changed files with 15 additions and 9 deletions
  1. +2
    -2
      lib/network/modules/NodesHandler.js
  2. +6
    -3
      lib/network/modules/PhysicsEngine.js
  3. +3
    -3
      lib/network/modules/PhysicsWorker.js
  4. +4
    -1
      lib/network/modules/components/Node.js

+ 2
- 2
lib/network/modules/NodesHandler.js View File

@ -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)});
}
}
}

+ 6
- 3
lib/network/modules/PhysicsEngine.js View File

@ -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

+ 3
- 3
lib/network/modules/PhysicsWorker.js View File

@ -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);
}
}

+ 4
- 1
lib/network/modules/components/Node.js View File

@ -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});
}

Loading…
Cancel
Save