Browse Source

added stochastic option check to the testing. Fixed few bugs

flowchartTest
Alex de Mulder 9 years ago
parent
commit
ab112d8a40
7 changed files with 21872 additions and 21720 deletions
  1. +21677
    -21667
      dist/vis.js
  2. +80
    -36
      examples/network/basicUsage.html
  3. +0
    -1
      lib/network/Network.js
  4. +1
    -2
      lib/network/modules/PhysicsEngine.js
  5. +16
    -8
      lib/network/modules/components/physics/HierarchicalSpringSolver.js
  6. +4
    -0
      lib/shared/Configurator.js
  7. +94
    -6
      test/network_unittests.html

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


+ 80
- 36
examples/network/basicUsage.html View File

@ -1,53 +1,97 @@
<!doctype html>
<html>
<head>
<title>Network | Basic usage</title>
<title>Network | Basic usage</title>
<script type="text/javascript" src="../../dist/vis.js"></script>
<link href="../../dist/vis.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="../../dist/vis.js"></script>
<link href="../../dist/vis.css" rel="stylesheet" type="text/css"/>
<style type="text/css">
#mynetwork {
width: 600px;
height: 400px;
border: 1px solid lightgray;
}
</style>
<style type="text/css">
#mynetwork {
width: 600px;
height: 400px;
border: 1px solid lightgray;
}
</style>
</head>
<body>
<p>
Create a simple network with some nodes and edges.
Create a simple network with some nodes and edges.
</p>
<div id="mynetwork"></div>
<script type="text/javascript">
// create an array with nodes
var nodes = new vis.DataSet([
{id: 1, label: 'Node 1'},
{id: 2, label: 'Node 2'},
{id: 3, label: 'Node 3'},
{id: 4, label: 'Node 4'},
{id: 5, label: 'Node 5'}
]);
// create an array with edges
var edges = new vis.DataSet([
{from: 1, to: 3},
{from: 1, to: 2},
{from: 2, to: 4},
{from: 2, to: 5}
]);
// create a network
var container = document.getElementById('mynetwork');
var data = {
nodes: nodes,
edges: edges
};
var options = {};
var network = new vis.Network(container, data, options);
// create an array with nodes
var nodes = new vis.DataSet([
{id: 1, label: 'Node 1'},
{id: 2, label: 'Node 2'},
{id: 3, label: 'Node 3'},
{id: 4, label: 'Node 4'},
{id: 5, label: 'Node 5'}
]);
// create an array with edges
var edges = new vis.DataSet([
{from: 1, to: 3},
{from: 1, to: 2},
{from: 2, to: 4},
{from: 2, to: 5}
]);
// create a network
var container = document.getElementById('mynetwork');
var data = {
nodes: nodes,
edges: edges
};
var options = {
"configure": {"filter": false},
"groups": {"useDefaultGroups": true},
"interaction": {
"dragNodes": false,
"hideEdgesOnDrag": true,
"keyboard": {},
"multiselect": true,
"selectConnectedEdges": false,
"hoverConnectedEdges": false,
"tooltipDelay": 0.7989967758767307
},
"layout": {"hierarchical": {"enabled": true, "levelSeparation": 0.9179429337382317}},
"nodes": {
"borderWidthSelected": 0.7435446435119957,
"color": {"highlight": {}},
"icon": {},
"physics": false,
"scaling": {"max": 0.7851112282369286},
"shape": "database",
"size": 0.48270674562081695,
"value": 0.008877722779288888,
"y": 0.3715104619041085
},
"physics": {
"repulsion": {
"centralGravity": 0.5645577218383551,
"springConstant": 0.5461068388540298,
"nodeDistance": 0.4722384719643742,
"damping": 0.5188916651532054
},
"hierarchicalRepulsion": {
"centralGravity": 0.5891720526851714,
"nodeDistance": 0.9401708527002484,
"damping": 0.7773354148957878
},
"minVelocity": 0.6082209222950041,
"solver": "hierarchicalRepulsion"
},
"edges": {"smooth": false}
}
var network = new vis.Network(container, data, {physics:{stabilization:false}});
network.on("stabilized",function() {
console.log("s")
})
network.setOptions(options)
</script>
<script src="../googleAnalytics.js"></script>

+ 0
- 1
lib/network/Network.js View File

@ -221,7 +221,6 @@ Network.prototype.setOptions = function (options) {
}
this.canvas.setSize();
// start the physics simulation. Can be safely called multiple times.
this.body.emitter.emit("startSimulation");
}

+ 1
- 2
lib/network/modules/PhysicsEngine.js View File

@ -175,7 +175,6 @@ class PhysicsEngine {
// this sets the width of all nodes initially which could be required for the avoidOverlap
this.body.emitter.emit("_resizeNodes");
if (this.viewFunction === undefined) {
this.viewFunction = this.simulationStep.bind(this);
this.body.emitter.on('initRedraw', this.viewFunction);
@ -238,7 +237,7 @@ class PhysicsEngine {
}
_emitStabilized() {
if (this.stabilizationIterations > 1) {
if (this.stabilizationIterations > 0) {
setTimeout(() => {
this.body.emitter.emit('stabilized', {iterations: this.stabilizationIterations});
this.stabilizationIterations = 0;

+ 16
- 8
lib/network/modules/components/physics/HierarchicalSpringSolver.js View File

@ -50,16 +50,24 @@ class HierarchicalSpringSolver {
fy = dy * springForce;
if (edge.to.level != edge.from.level) {
forces[edge.toId].springFx -= fx;
forces[edge.toId].springFy -= fy;
forces[edge.fromId].springFx += fx;
forces[edge.fromId].springFy += fy;
if (forces[edge.toId] !== undefined) {
forces[edge.toId].springFx -= fx;
forces[edge.toId].springFy -= fy;
}
if (forces[edge.fromId] !== undefined) {
forces[edge.fromId].springFx += fx;
forces[edge.fromId].springFy += fy;
}
}
else {
forces[edge.toId].x -= factor*fx;
forces[edge.toId].y -= factor*fy;
forces[edge.fromId].x += factor*fx;
forces[edge.fromId].y += factor*fy;
if (forces[edge.toId] !== undefined) {
forces[edge.toId].x -= factor * fx;
forces[edge.toId].y -= factor * fy;
}
if (forces[edge.fromId] !== undefined) {
forces[edge.fromId].x += factor * fx;
forces[edge.fromId].y += factor * fy;
}
}
}
}

+ 4
- 0
lib/shared/Configurator.js View File

@ -77,6 +77,10 @@ class Configurator {
this.options.filter = options;
enabled = true;
}
if (this.options.filter === false) {
enabled = false;
}
this.options.enabled = enabled;
}
this._clean();

+ 94
- 6
test/network_unittests.html View File

@ -51,12 +51,17 @@
}
function draw(options) {
// clean
if (network !== null) {
network.destroy();
network = null;
try {
// clean
if (network !== null) {
network.destroy();
network = null;
}
network = new vis.Network(container, data, options);
}
catch (err) {
console.log("err")
}
network = new vis.Network(container, data, options);
}
function clusterByCid() {
@ -168,7 +173,90 @@
}
}
checkMethods();
var amountOfOptionChecks = 600;
var optionCheckTime = 150;
var optionsThreshold = 0.8;
function checkOptions(i) {
console.log('checking Options iteration:',i)
var allOptions = vis.network.allOptions.allOptions;
var testOptions = {};
constructOptions(allOptions, testOptions);
var failed = setTimeout(function() {console.error("FAILED",JSON.stringify(testOptions,null,4))}, 0.9*optionCheckTime);
var counter = 0;
drawQuick();
network.on("afterDrawing", function() {
counter++;
if (counter > 2) {
counter = 0;
network.off('afterDrawing');
clearTimeout(failed);
}
})
network.on("stabilized", function() {
clearTimeout(failed);
});
network.on("destroy", function() {
clearTimeout(failed);
})
network.setOptions(testOptions);
}
function constructOptions(allOptions, testOptions) {
for (var option in allOptions) {
if (Math.random() < optionsThreshold) {
if (option !== "__type__" && option !== '__any__' && option !== 'locales' && option !== 'image' && option !== 'id') {
if (allOptions[option].__type__ !== undefined) {
if (testOptions[option] === undefined) {
testOptions[option] = {};
}
constructOptions(allOptions[option], testOptions[option])
if (Object.keys(testOptions).length === 0) {
testOptions[option] = undefined;
delete testOptions[option];
}
}
else {
if (allOptions[option].boolean !== undefined) {
if (testOptions[option] === undefined) {
testOptions[option] = {};
}
testOptions[option] = Math.random() < 0.5;
}
else if(allOptions[option].number !== undefined) {
if (testOptions[option] === undefined) {
testOptions[option] = {};
}
testOptions[option] = 1 * Math.random();
}
else if(allOptions[option].string !== undefined && Array.isArray(allOptions[option].string)) {
var value = allOptions[option].string[Math.floor(Math.random() * allOptions[option].string.length)];
if (value !== 'image' && value !== 'circularImage' && value !== 'icon') {
if (testOptions[option] === undefined) {
testOptions[option] = {};
}
testOptions[option] = value;
}
}
else if(allOptions[option].string !== undefined) {
// if (testOptions[option] === undefined) {
// testOptions[option] = {};
// }
// testOptions[option] = "hello world";
}
}
}
}
}
}
for (var i = 0; i < amountOfOptionChecks; i++) {
setTimeout(checkOptions.bind(this,i), i*optionCheckTime);
}
setTimeout(checkMethods, amountOfOptionChecks*optionCheckTime);
</script>
</body>
</html>

Loading…
Cancel
Save