Browse Source

Fixed physics stopping conditions, updated history #255

v3_develop
Alex de Mulder 10 years ago
parent
commit
2abfcd8261
7 changed files with 24085 additions and 23950 deletions
  1. +7
    -0
      HISTORY.md
  2. +23931
    -23931
      dist/vis.js
  3. +1
    -1
      dist/vis.map
  4. +11
    -11
      dist/vis.min.js
  5. +128
    -0
      examples/network/ex.html
  6. +4
    -5
      lib/network/Network.js
  7. +3
    -2
      lib/network/Node.js

+ 7
- 0
HISTORY.md View File

@ -13,6 +13,13 @@ http://visjs.org
### Network ### Network
- A fix in reading group properties for a node. - A fix in reading group properties for a node.
- Fixed physics solving stopping when a support node was not moving.
### Graph2D
- Added 'slots' for groups when using barCharts.
- Added 'allowOverlap' option for barCharts.
- Added two examples showing the two additions above.
## 2014-08-14, version 3.2.0 ## 2014-08-14, version 3.2.0

+ 23931
- 23931
dist/vis.js
File diff suppressed because it is too large
View File


+ 1
- 1
dist/vis.map
File diff suppressed because it is too large
View File


+ 11
- 11
dist/vis.min.js
File diff suppressed because it is too large
View File


+ 128
- 0
examples/network/ex.html View File

@ -0,0 +1,128 @@
<!doctype html>
<html>
<head>
<title>Network | Basic usage</title>
<script type="text/javascript" src="../../dist/vis.js"></script>
<style type="text/css">
#mynetwork {
width: 400px;
height: 400px;
border: 1px solid lightgray;
}
</style>
</head>
<body>
<div id="tabs-2"></div>
<script type="text/javascript">
function drawNetwork() {
var nodes = null;
var edges = null;
var network = null;
var LENGTH_MAIN = 350,
WIDTH_SCALE = 2,
GRAY = 'gray',
BLACK = '#2B1B17';
function draw() {
nodes = [];
edges = [];
var parentDeviceName = "Windows Host";
var parentName = "john";
var parentId = 1;
if (parentDeviceName == "Windows Host") {
group = 'windowsHost';
} else if (parentDeviceName == "Sun Host") {
group = 'sunHost';
} else if (parentDeviceName == "Net-SNMP Linux") {
group = 'linuxHost';
} else if (parentDeviceName == "Cisco 2901 K9") {
group = 'router';
} else {
group = 'switch';
}
nodes.push({id: parentId, label: parentName + "\n" + parentDeviceName, group: group, value: 10});
nodes.push({id: 2, label: "bob\nbobby", group: group, value: 10});
edges.push({from: parentId, to: 2, length: LENGTH_MAIN, width: WIDTH_SCALE * 2, label: ''});
var container = document.getElementById('tabs-2');
var data = {
nodes: nodes,
edges: edges
};
var options = {
stabilize: false, // stabilize positions before displaying
nodes: {
radiusMin: 16,
radiusMax: 32,
fontColor: BLACK
},
edges: {
color: GRAY
},
groups: {
'switch': {
shape: 'image',
image: '/vis.js/examples/network/img/refresh-cl/Hardware-Laptop-1-icon.png'
},
'router': {
shape: 'image',
image: '/vis.js/examples/network/img/refresh-cl/Hardware-Laptop-1-icon.png'
},
'firewall': {
shape: 'image',
image: '/vis.js/examples/network/img/refresh-cl/Hardware-Laptop-1-icon.png'
},
desktop: {
shape: 'dot',
color: "#2B7CE9" // blue
},
mobile: {
shape: 'dot',
color: "#5A1E5C" // purple
},
sunHost: {
shape: 'image',
image: '/vis.js/examples/network/img/refresh-cl/Hardware-Laptop-1-icon.png'
},
windowsHost: {
shape: 'image',
image: '/vis.js/examples/network/img/refresh-cl/Hardware-Laptop-1-icon.png'
},
linuxHost: {
shape: 'image',
image: '/vis.js/examples/network/img/refresh-cl/Hardware-Laptop-1-icon.png'
},
server: {
shape: 'square',
color: "#C5000B" // red
},
internet: {
shape: 'square',
color: "#109618" // green
}
},
physics: {
barnesHut: {
enabled: true
}
}
};
network = new vis.Network(container, data, options);
}
draw();
}
drawNetwork();
</script>
</body>
</html>

+ 4
- 5
lib/network/Network.js View File

@ -1349,9 +1349,8 @@ Network.prototype._addNodes = function(ids) {
var data = this.nodesData.get(id); var data = this.nodesData.get(id);
var node = new Node(data, this.images, this.groups, this.constants); var node = new Node(data, this.images, this.groups, this.constants);
this.nodes[id] = node; // note: this may replace an existing node this.nodes[id] = node; // note: this may replace an existing node
if ((node.xFixed == false || node.yFixed == false) && (node.x === null || node.y === null)) { if ((node.xFixed == false || node.yFixed == false) && (node.x === null || node.y === null)) {
var radius = 10 * 0.1*ids.length;
var radius = 10 * 0.1*ids.length + 10;
var angle = 2 * Math.PI * Math.random(); var angle = 2 * Math.PI * Math.random();
if (node.xFixed == false) {node.x = radius * Math.cos(angle);} if (node.xFixed == false) {node.x = radius * Math.cos(angle);}
if (node.yFixed == false) {node.y = radius * Math.sin(angle);} if (node.yFixed == false) {node.y = radius * Math.sin(angle);}
@ -1952,7 +1951,7 @@ Network.prototype._isMoving = function(vmin) {
* *
* @private * @private
*/ */
Network.prototype._discreteStepNodes = function() {
Network.prototype._discreteStepNodes = function(checkMovement) {
var interval = this.physicsDiscreteStepsize; var interval = this.physicsDiscreteStepsize;
var nodes = this.nodes; var nodes = this.nodes;
var nodeId; var nodeId;
@ -1975,7 +1974,7 @@ Network.prototype._discreteStepNodes = function() {
} }
} }
if (nodesPresent == true) {
if (nodesPresent == true && (checkMovement === undefined || checkMovement == true)) {
var vminCorrected = this.constants.minVelocity / Math.max(this.scale,0.05); var vminCorrected = this.constants.minVelocity / Math.max(this.scale,0.05);
if (vminCorrected > 0.5*this.constants.maxVelocity) { if (vminCorrected > 0.5*this.constants.maxVelocity) {
this.moving = true; this.moving = true;
@ -2002,7 +2001,7 @@ Network.prototype._physicsTick = function() {
this._doInAllActiveSectors("_initializeForceCalculation"); this._doInAllActiveSectors("_initializeForceCalculation");
this._doInAllActiveSectors("_discreteStepNodes"); this._doInAllActiveSectors("_discreteStepNodes");
if (this.constants.smoothCurves.enabled == true && this.constants.smoothCurves.dynamic == true) { if (this.constants.smoothCurves.enabled == true && this.constants.smoothCurves.dynamic == true) {
this._doInSupportSector("_discreteStepNodes");
this._doInSupportSector("_discreteStepNodes", false);
} }
this._findCenter(this._getRange()) this._findCenter(this._getRange())
} }

+ 3
- 2
lib/network/Node.js View File

@ -386,9 +386,10 @@ Node.prototype.isFixed = function() {
* @param {number} vmin the minimum velocity considered as "moving" * @param {number} vmin the minimum velocity considered as "moving"
* @return {boolean} true if moving, false if it has no velocity * @return {boolean} true if moving, false if it has no velocity
*/ */
// TODO: replace this method with calculating the kinetic energy
Node.prototype.isMoving = function(vmin) { Node.prototype.isMoving = function(vmin) {
return (Math.abs(this.vx) > vmin || Math.abs(this.vy) > vmin);
var velocity = Math.sqrt(Math.pow(this.vx,2) + Math.pow(this.vy,2));
// this.velocity = Math.sqrt(Math.pow(this.vx,2) + Math.pow(this.vy,2))
return (velocity > vmin);
}; };
/** /**

Loading…
Cancel
Save