Browse Source

added physics:enabled field. Updated docs

flowchartTest
Alex de Mulder 9 years ago
parent
commit
42596ab053
7 changed files with 7584 additions and 7490 deletions
  1. +1
    -0
      HISTORY.md
  2. +7455
    -7442
      dist/vis.js
  3. +6
    -6
      docs/network/manipulation.html
  4. +2
    -0
      docs/network/physics.html
  5. +13
    -2
      lib/network/modules/PhysicsEngine.js
  6. +2
    -0
      lib/network/options.js
  7. +105
    -40
      test/networkTest.html

+ 1
- 0
HISTORY.md View File

@ -29,6 +29,7 @@ http://visjs.org
- Second click on node is no longer unselect.
- Added releaseFunction to openCluster.
- Fixed bug where the network could flicker when the pixelRatio is not integer.
- Added enabled property to physics.
## 2015-05-28, version 4.1.0

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


+ 6
- 6
docs/network/manipulation.html View File

@ -108,14 +108,14 @@ network.setOptions(options);
</pre>
<table class="options" id="optionTable">
<tr><th>Name</th><th>Type</th><th>Default</th><td>Description</td></tr>
<tr><td>enabled</td> <td>Boolean</td> <td><code>false</code></td> <td>Toggle the manipulation system on or off. This property is optional. If you define any of the options below and enabled is undefined, this will be set to true.</td></tr>
<tr><td>enabled</td> <td>Boolean</td> <td><code>false</code></td> <td>Toggle the manipulation system on or off. Even when false, the manipulation API through the methods will still work. This property is optional. If you define any of the options below and enabled is undefined, this will be set to true.</td></tr>
<tr><td>initiallyActive</td> <td>Boolean</td> <td><code>true</code></td> <td>Toggle whether the toolbar is visible initially or if only the edit button is visible initially.</td></tr>
<tr><td>addNode</td> <td>Boolean or Function</td> <td><code>true</code></td> <td>You can use these options to switch certain functionalities on or off of attach
a handler function to them. These functions are called before the action is performed. If a node is going to be added through the manipulation system,
the addNode function will be called first. With this, you can provide a gui for your users, abort the process or anything else you want to do. For all except the editNode functionality, these handler functions are optional.
<br><br>
When you supply a boolean, you only toggle the adding of nodes.
When you supply a boolean, you only toggle the 'add node' button on the GUI of the manipulation system. The lack of handling function could effect the API when using the methods.
When a function is supplied, it will be called when the user clicks the canvas in 'addNode' mode. This function will receive two variables: the properties of the node that can be created and a callback function. If you call the callback function with the properties of the new node, the node will be added. <br><br> Example:
<pre class="code">
var options = {
@ -128,7 +128,7 @@ var options = {
}
</pre>
This function changes the label of the new node into 'hello world'. If you do not want the node created, do not call the callback function or call the callback function <code>null</code> or no argument.</td></tr>
<tr><td>addEdge</td> <td>Boolean or Function</td> <td><code>true</code></td> <td>If boolean, toggle the adding of edges.
<tr><td>addEdge</td> <td>Boolean or Function</td> <td><code>true</code></td> <td>If boolean, toggle the availability of the 'addEdge' button in the GUI, the API through the methods will still work except (obviously) there will be no handler function.
When a function is supplied, it will be called when the user drags the new edge from one node to the next in 'addEdge' mode. This function will receive two variables: the properties of the edge that can be created and a callback function. If you call the callback function with the properties of the new edge, the edge will be added. <br><br> Example:
<pre class="code">
var options = {
@ -149,9 +149,9 @@ var options = {
</pre>
This example code will show a popup if you connect a node to itself to ask you if that was what you wanted. If you do not want the edge created, do not call the callback function or call the callback function <code>null</code> or no argument.</td></tr></td></tr>
<tr><td>editNode</td> <td>Function</td> <td><code>undefined</code></td> <td>Editing of nodes is only possible when a handling function is supplied. If this is not the case, editing of nodes will be disabled. The function will be called when a node is selected and the 'Edit Node' button on the toolbar is pressed. This function will be called like the <code>addNode</code> function with the node's data and a callback function.</td></tr>
<tr><td>editEdge</td> <td>Boolean or Function</td> <td><code>true</code></td> <td>If boolean, toggle the editing of edges. When a function is supplied, it will be called when an edge is selcted and the 'Edit Edge' button on the toolbar is pressed. This function will be called in the same way the <code>addEdge</code> function was called. If the callback is not performed, the edge will remain hanging where it was released. <b>To cancel, call the callback function with <code>null</code> as argument or without arguments</b>.</td></tr>
<tr><td>deleteNode</td> <td>Boolean or Function</td> <td><code>true</code></td> <td>If boolean, toggle the deletion of nodes. If function, it will be called when a node is selected and the 'Delete selected' button is pressed.</td></tr>
<tr><td>deleteEdge</td> <td>Boolean or Function</td> <td><code>true</code></td> <td>If boolean, toggle the deletion of edges. If function, it will be called when an edge is selected and the 'Delete selected' button is pressed.</td></tr>
<tr><td>editEdge</td> <td>Boolean or Function</td> <td><code>true</code></td> <td>If boolean, toggle the editing of edges in the GUI. When a function is supplied, it will be called when an edge is selcted and the 'Edit Edge' button on the toolbar is pressed. This function will be called in the same way the <code>addEdge</code> function was called. If the callback is not performed, the edge will remain hanging where it was released. <b>To cancel, call the callback function with <code>null</code> as argument or without arguments</b>.</td></tr>
<tr><td>deleteNode</td> <td>Boolean or Function</td> <td><code>true</code></td> <td>If boolean, toggle the deletion of nodes in the GUI. If function, it will be called when a node is selected and the 'Delete selected' button is pressed. When using a function, it will receive a callback and an object with an array of selected nodeIds and an array of selected edges Ids. These are the items that will be deleted if the callback is performed.</td></tr>
<tr><td>deleteEdge</td> <td>Boolean or Function</td> <td><code>true</code></td> <td>If boolean, toggle the deletion of edges in the GUI. If function, it will be called when an edge is selected and the 'Delete selected' button is pressed. When using a function, it will receive a callback and an object with an array of selected nodeIds (empty) and an array of selected edges Ids. These are the items that will be deleted if the callback is performed.</td></tr>
<tr><td>controlNodeStyle</td> <td>Object</td> <td>Object</td><td>You can supply any styling information you'd like here. All fields described in <a href="./nodes.html">the nodes module</a> are allowed except obviously for id, x, y and fixed. <br><br>Default:
<pre class="code">
{

+ 2
- 0
docs/network/physics.html View File

@ -82,6 +82,7 @@
// these are all options in full.
var options = {
physics:{
enabled: true,
barnesHut: {
gravitationalConstant: -2000,
centralGravity: 0.3,
@ -141,6 +142,7 @@ network.setOptions(options);
<p>All of the individual options are explained here:</p>
<table class="options" id="optionTable">
<tr><th>Name</th><th>Type</th><th>Default</th><th>Description</th></tr>
<tr><td>enabled</td> <td>Boolean</td> <td><code>true</code></td> <td>Toggle the physics system on or off. This property is optional. If you define any of the options below and enabled is undefined, this will be set to true.</td></tr>
<tr class='toggle collapsible' onclick="toggleTable('optionTable','barnesHut', this);"><td><span parent="barnesHut" class="right-caret"></span> barnesHut</td> <td>Object</td> <td><code>Object</code></td> <td>BarnesHut is a quadtree based gravity model. This is the fastest, default and recommended solver for non-hierarchical layouts.</td></tr>
<tr parent="barnesHut" class="hidden"><td class="indent">barnesHut.gravitationalConstant</td> <td>Number</td> <td><code>-2000</code></td> <td>Gravity attracts. We like repulsion. So the value is negative. If you want the repulsion to be stronger, decrease the value (so -10000, -50000).</td></tr>
<tr parent="barnesHut" class="hidden"><td class="indent">barnesHut.centralGravity</td> <td>Number</td> <td><code>0.3</code></td> <td>There is a central gravity attractor to pull the entire network back to the center.</td></tr>

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

@ -31,6 +31,7 @@ class PhysicsEngine {
// default options
this.options = {};
this.defaultOptions = {
enabled: true,
barnesHut: {
theta: 0.5,
gravitationalConstant: -2000,
@ -106,6 +107,7 @@ class PhysicsEngine {
setOptions(options) {
if (options !== undefined) {
if (options === false) {
this.options.enabled = false;
this.physicsEnabled = false;
this.stopSimulation();
}
@ -113,6 +115,15 @@ class PhysicsEngine {
this.physicsEnabled = true;
util.selectiveNotDeepExtend(['stabilization'], this.options, options);
util.mergeOptions(this.options, options, 'stabilization')
if (options.enabled === undefined) {
this.options.enabled = true;
}
if (this.options.enabled === false) {
this.physicsEnabled = false;
this.stopSimulation();
}
}
}
this.init();
@ -150,7 +161,7 @@ class PhysicsEngine {
}
initPhysics() {
if (this.physicsEnabled === true) {
if (this.physicsEnabled === true && this.options.enabled === true) {
if (this.options.stabilization.enabled === true) {
this.stabilize();
}
@ -171,7 +182,7 @@ class PhysicsEngine {
* Start the simulation
*/
startSimulation() {
if (this.physicsEnabled === true) {
if (this.physicsEnabled === true && this.options.enabled === true) {
this.stabilized = false;
// this sets the width of all nodes initially which could be required for the avoidOverlap

+ 2
- 0
lib/network/options.js View File

@ -214,6 +214,7 @@ let allOptions = {
__type__: {object}
},
physics: {
enabled:{boolean},
barnesHut: {
gravitationalConstant: {number},
centralGravity: {number},
@ -423,6 +424,7 @@ let configureOptions = {
initiallyActive: false
},
physics: {
enabled: true,
barnesHut: {
//theta: [0.5, 0.1, 1, 0.05],
gravitationalConstant: [-2000, -30000, 0, 50],

+ 105
- 40
test/networkTest.html
File diff suppressed because it is too large
View File


Loading…
Cancel
Save