diff --git a/examples/network/27_world_cup_network.html b/examples/network/27_world_cup_network.html index 6f4d7844..a081e254 100644 --- a/examples/network/27_world_cup_network.html +++ b/examples/network/27_world_cup_network.html @@ -47,7 +47,7 @@ inheritColor option:
-Roundness (0..1): +Roundness (0..1): (0.5 is max roundness for continuous, 1.0 for the others)
Hide edges on drag:
Hide nodes on drag: diff --git a/examples/network/28_world_cup_network_performance.html b/examples/network/28_world_cup_network_performance.html new file mode 100644 index 00000000..cffc274c --- /dev/null +++ b/examples/network/28_world_cup_network_performance.html @@ -0,0 +1,10053 @@ + + + + Network | Static smooth curves - World Cup Network + + + + + + + + + +

Performance - World Cup Network

+
+ This example shows the performance of vis with a larger network. The edges in particular (~9200) are very computationally intensive + to draw. Drag and hold the graph to see the performance difference if the edges are hidden. +

+ We use the following physics configuration:
+ {barnesHut: {gravitationalConstant: -80000, springConstant: 0.001, springLength: 200}} +

+
+ +
+ + + + + + diff --git a/examples/network/index.html b/examples/network/index.html index c360c653..91741049 100644 --- a/examples/network/index.html +++ b/examples/network/index.html @@ -39,6 +39,7 @@

25_physics_configuration.html

26_staticSmoothCurves.html

27_world_cup_network.html

+

28_world_cup_network_performance.html

graphviz_gallery.html

diff --git a/lib/network/Edge.js b/lib/network/Edge.js index fa723608..9c11c94f 100644 --- a/lib/network/Edge.js +++ b/lib/network/Edge.js @@ -939,42 +939,22 @@ Edge.prototype._getDistanceToEdge = function (x1,y1, x2,y2, x3,y3) { // x3,y3 is yVia = via.y; } var minDistance = 1e9; - var i,t,x,y,dx,dy; + var distance; + var i,t,x,y, lastX, lastY; for (i = 0; i < 10; i++) { t = 0.1*i; x = Math.pow(1-t,2)*x1 + (2*t*(1 - t))*xVia + Math.pow(t,2)*x2; y = Math.pow(1-t,2)*y1 + (2*t*(1 - t))*yVia + Math.pow(t,2)*y2; - dx = Math.abs(x3-x); - dy = Math.abs(y3-y); - minDistance = Math.min(minDistance,Math.sqrt(dx*dx + dy*dy)); + if (i > 0) { + distance = this._getDistanceToLine(lastX,lastY,x,y, x3,y3); + minDistance = distance < minDistance ? distance : minDistance; + } + lastX = x; lastY = y; } return minDistance } else { - var px = x2-x1, - py = y2-y1, - something = px*px + py*py, - u = ((x3 - x1) * px + (y3 - y1) * py) / something; - - if (u > 1) { - u = 1; - } - else if (u < 0) { - u = 0; - } - - var x = x1 + u * px, - y = y1 + u * py, - dx = x - x3, - dy = y - y3; - - //# Note: If the actual distance does not matter, - //# if you only want to compare what this function - //# returns to other results of this function, you - //# can just return the squared distance instead - //# (i.e. remove the sqrt) to gain a little performance - - return Math.sqrt(dx*dx + dy*dy); + return this._getDistanceToLine(x1,y1,x2,y2,x3,y3); } } else { @@ -998,7 +978,32 @@ Edge.prototype._getDistanceToEdge = function (x1,y1, x2,y2, x3,y3) { // x3,y3 is } }; +Edge.prototype._getDistanceToLine = function(x1,y1,x2,y2,x3,y3) { + var px = x2-x1, + py = y2-y1, + something = px*px + py*py, + u = ((x3 - x1) * px + (y3 - y1) * py) / something; + if (u > 1) { + u = 1; + } + else if (u < 0) { + u = 0; + } + + var x = x1 + u * px, + y = y1 + u * py, + dx = x - x3, + dy = y - y3; + + //# Note: If the actual distance does not matter, + //# if you only want to compare what this function + //# returns to other results of this function, you + //# can just return the squared distance instead + //# (i.e. remove the sqrt) to gain a little performance + + return Math.sqrt(dx*dx + dy*dy); +} /** * This allows the zoom level of the network to influence the rendering diff --git a/lib/network/Network.js b/lib/network/Network.js index 1e0283ba..b7875307 100644 --- a/lib/network/Network.js +++ b/lib/network/Network.js @@ -107,7 +107,7 @@ function Network (container, data, options) { gap: 5, altLength: undefined }, - inheritColor: false // to, from, false, true (== from) + inheritColor: "from" // to, from, false, true (== from) }, configurePhysics:false, physics: { @@ -186,7 +186,7 @@ function Network (container, data, options) { roundness: 0.5 }, dynamicSmoothCurves: true, - maxVelocity: 10, + maxVelocity: 30, minVelocity: 0.1, // px/s stabilizationIterations: 1000, // maximum number of iteration to stabilize labels:{ @@ -532,7 +532,6 @@ Network.prototype.setData = function(data, disableStart) { } this._putDataInSector(); - if (!disableStart) { // find a stable position or start animating to a stable position if (this.stabilize) { @@ -1779,7 +1778,7 @@ Network.prototype._redraw = function() { this._doInAllSectors("_drawControlNodes",ctx); } -// this._doInSupportSector("_drawNodes",ctx,true); + this._doInSupportSector("_drawNodes",ctx,true); // this._drawTree(ctx,"#F00F0F"); // restore original scaling and translation @@ -2229,6 +2228,14 @@ Network.prototype._configureSmoothCurves = function(disableStart) { } if (this.constants.smoothCurves.enabled == true && this.constants.smoothCurves.dynamic == true) { this._createBezierNodes(); + // cleanup unused support nodes + for (var nodeId in this.sectors['support']['nodes']) { + if (this.sectors['support']['nodes'].hasOwnProperty(nodeId)) { + if (this.edges[this.sectors['support']['nodes'][nodeId]] === undefined) { + delete this.sectors['support']['nodes'][nodeId]; + } + } + } } else { // delete the support nodes @@ -2240,6 +2247,8 @@ Network.prototype._configureSmoothCurves = function(disableStart) { } } } + + this._updateCalculationNodes(); if (!disableStart) { this.moving = true; diff --git a/lib/network/Node.js b/lib/network/Node.js index 76beec71..ee72aceb 100644 --- a/lib/network/Node.js +++ b/lib/network/Node.js @@ -179,7 +179,7 @@ Node.prototype.setProperties = function(properties, constants) { // individual shape properties if (properties.shape !== undefined) {this.shape = properties.shape;} if (properties.image !== undefined) {this.image = properties.image;} - if (properties.radius !== undefined) {this.radius = properties.radius;} + if (properties.radius !== undefined) {this.radius = properties.radius; this.baseRadiusValue = this.radius;} if (properties.color !== undefined) {this.color = util.parseColor(properties.color);} if (properties.fontColor !== undefined) {this.fontColor = properties.fontColor;} diff --git a/lib/network/mixins/physics/PhysicsMixin.js b/lib/network/mixins/physics/PhysicsMixin.js index 18c4de5e..404dd150 100644 --- a/lib/network/mixins/physics/PhysicsMixin.js +++ b/lib/network/mixins/physics/PhysicsMixin.js @@ -95,7 +95,7 @@ exports._calculateForces = function () { this._calculateGravitationalForces(); this._calculateNodeForces(); - if (this.constants.springConstant > 0) { + if (this.constants.physics.springConstant > 0) { if (this.constants.smoothCurves.enabled == true && this.constants.smoothCurves.dynamic == true) { this._calculateSpringForcesWithSupport(); }