diff --git a/dist/vis.js b/dist/vis.js index 279127f1..b1a268b6 100644 --- a/dist/vis.js +++ b/dist/vis.js @@ -10953,7 +10953,7 @@ var physicsMixin = { * * @private */ - _initializeForceCalculation : function() { + _initializeForceCalculation : function(useBarnesHut) { // stop calculation if there is only one node if (this.nodeIndices.length == 1) { this.nodes[this.nodeIndices[0]]._setForce(0,0); @@ -10964,9 +10964,15 @@ var physicsMixin = { this.clusterToFit(this.constants.clustering.reduceToNodes, false); } - // we now start the force calculation - this._calculateForcesBarnesHut(); -// this._calculateForcesRepulsion(); + this._calculateForcesRepulsion(); + +// // we now start the force calculation +// if (useBarnesHut == true) { +// this._calculateForcesBarnesHut(); +// } +// else { +// this._calculateForcesRepulsion(); +// } } }, @@ -11142,7 +11148,7 @@ var physicsMixin = { fx = Math.cos(angle) * springForce; fy = Math.sin(angle) * springForce; - + //console.log(edge.length,dx,dy,edge.springConstant,angle) edge.from._addForce(-fx, -fy); edge.to._addForce(fx, fy); } @@ -11251,6 +11257,7 @@ var physicsMixin = { range:{minX:minX,maxX:maxX,minY:minY,maxY:maxY}, size: Math.abs(maxX - minX), children: {data:null}, + level: 0, childrenCount: 4 }}; this._splitBranch(barnesHutTree.root); @@ -11265,7 +11272,6 @@ var physicsMixin = { this.barnesHutTree = barnesHutTree }, - _updateBranchMass : function(parentBranch, node) { var totalMass = parentBranch.mass + node.mass; var totalMassInv = 1/totalMass; @@ -11377,12 +11383,14 @@ var physicsMixin = { break; } + parentBranch.children[region] = { CenterOfMass:{x:0,y:0}, mass:0, range:{minX:minX,maxX:maxX,minY:minY,maxY:maxY}, size: 0.5 * parentBranch.size, children: {data:null}, + level: parentBranch.level +1, childrenCount: 0 }; }, @@ -12763,6 +12771,7 @@ var ClusterMixin = { } } } + }, /** @@ -12808,9 +12817,9 @@ var ClusterMixin = { parentNode.dynamicEdgesLength = parentNode.dynamicEdges.length; // place the child node near the parent, not at the exact same location to avoid chaos in the system - childNode.x = parentNode.x + this.constants.edges.length * (0.1 + 0.3 * (0.5 - Math.random()) * parentNode.clusterSize); - childNode.y = parentNode.y + this.constants.edges.length * (0.1 + 0.3 * (0.5 - Math.random()) * parentNode.clusterSize); - + childNode.x = parentNode.x + this.constants.physics.springLength * (0.1 * (0.5 - Math.random()) * parentNode.clusterSize); + childNode.y = parentNode.y + this.constants.physics.springLength * (0.1 * (0.5 - Math.random()) * parentNode.clusterSize); + console.log(childNode.x,childNode.y,parentNode.x,parentNode.y); // remove node from the list delete parentNode.containedNodes[containedNodeId]; @@ -16135,6 +16144,7 @@ Graph.prototype.start = function() { graph._zoom(graph.scale*(1 + graph.zoomIncrement), center); } + graph.start(); graph.start(); graph._redraw(); @@ -16157,7 +16167,7 @@ Graph.prototype.start = function() { */ Graph.prototype.singleStep = function() { if (this.moving) { - this._initializeForceCalculation(); + this._initializeForceCalculation(true); this._discreteStepNodes(); var vmin = this.constants.minVelocity; diff --git a/examples/graph/02_random_nodes.html b/examples/graph/02_random_nodes.html index a900ccbd..57ea0714 100755 --- a/examples/graph/02_random_nodes.html +++ b/examples/graph/02_random_nodes.html @@ -90,7 +90,8 @@ edges: { length: 50 }, - stabilize: false + stabilize: false, + clustering : true }; graph = new vis.Graph(container, data, options); diff --git a/src/graph/ClusterMixin.js b/src/graph/ClusterMixin.js index 8045ccee..740f618f 100644 --- a/src/graph/ClusterMixin.js +++ b/src/graph/ClusterMixin.js @@ -313,6 +313,7 @@ var ClusterMixin = { } } } + }, /** @@ -358,9 +359,9 @@ var ClusterMixin = { parentNode.dynamicEdgesLength = parentNode.dynamicEdges.length; // place the child node near the parent, not at the exact same location to avoid chaos in the system - childNode.x = parentNode.x + this.constants.edges.length * (0.1 + 0.3 * (0.5 - Math.random()) * parentNode.clusterSize); - childNode.y = parentNode.y + this.constants.edges.length * (0.1 + 0.3 * (0.5 - Math.random()) * parentNode.clusterSize); - + childNode.x = parentNode.x + this.constants.physics.springLength * (0.1 * (0.5 - Math.random()) * parentNode.clusterSize); + childNode.y = parentNode.y + this.constants.physics.springLength * (0.1 * (0.5 - Math.random()) * parentNode.clusterSize); + console.log(childNode.x,childNode.y,parentNode.x,parentNode.y); // remove node from the list delete parentNode.containedNodes[containedNodeId]; diff --git a/src/graph/Graph.js b/src/graph/Graph.js index 2e238baa..0dbc111a 100644 --- a/src/graph/Graph.js +++ b/src/graph/Graph.js @@ -1769,6 +1769,7 @@ Graph.prototype.start = function() { graph._zoom(graph.scale*(1 + graph.zoomIncrement), center); } + graph.start(); graph.start(); graph._redraw(); @@ -1791,7 +1792,7 @@ Graph.prototype.start = function() { */ Graph.prototype.singleStep = function() { if (this.moving) { - this._initializeForceCalculation(); + this._initializeForceCalculation(true); this._discreteStepNodes(); var vmin = this.constants.minVelocity; diff --git a/src/graph/physicsMixin.js b/src/graph/physicsMixin.js index b49e86dd..b52d32c7 100644 --- a/src/graph/physicsMixin.js +++ b/src/graph/physicsMixin.js @@ -11,7 +11,7 @@ var physicsMixin = { * * @private */ - _initializeForceCalculation : function() { + _initializeForceCalculation : function(useBarnesHut) { // stop calculation if there is only one node if (this.nodeIndices.length == 1) { this.nodes[this.nodeIndices[0]]._setForce(0,0); @@ -22,9 +22,15 @@ var physicsMixin = { this.clusterToFit(this.constants.clustering.reduceToNodes, false); } - // we now start the force calculation - this._calculateForcesBarnesHut(); -// this._calculateForcesRepulsion(); + this._calculateForcesRepulsion(); + +// // we now start the force calculation +// if (useBarnesHut == true) { +// this._calculateForcesBarnesHut(); +// } +// else { +// this._calculateForcesRepulsion(); +// } } }, @@ -200,7 +206,7 @@ var physicsMixin = { fx = Math.cos(angle) * springForce; fy = Math.sin(angle) * springForce; - + //console.log(edge.length,dx,dy,edge.springConstant,angle) edge.from._addForce(-fx, -fy); edge.to._addForce(fx, fy); } @@ -309,6 +315,7 @@ var physicsMixin = { range:{minX:minX,maxX:maxX,minY:minY,maxY:maxY}, size: Math.abs(maxX - minX), children: {data:null}, + level: 0, childrenCount: 4 }}; this._splitBranch(barnesHutTree.root); @@ -323,7 +330,6 @@ var physicsMixin = { this.barnesHutTree = barnesHutTree }, - _updateBranchMass : function(parentBranch, node) { var totalMass = parentBranch.mass + node.mass; var totalMassInv = 1/totalMass; @@ -435,12 +441,14 @@ var physicsMixin = { break; } + parentBranch.children[region] = { CenterOfMass:{x:0,y:0}, mass:0, range:{minX:minX,maxX:maxX,minY:minY,maxY:maxY}, size: 0.5 * parentBranch.size, children: {data:null}, + level: parentBranch.level +1, childrenCount: 0 }; },