# Network - physics

Handles the physics simulation, moving the nodes and edges to show them clearly.

### Options

The options for the physics have to be contained in an object titled 'physics'.

Click on the full options or shorthand options to show how these options are supposed to be used.

    // these are all options in full.
    var options = {
      physics:{
        enabled: true,
        barnesHut: {
          gravitationalConstant: -2000,
          centralGravity: 0.3,
          springLength: 95,
          springConstant: 0.04,
          damping: 0.09,
          avoidOverlap: 0
        },
        forceAtlas2Based: {
          gravitationalConstant: -50,
          centralGravity: 0.01,
          springConstant: 0.08,
          springLength: 100,
          damping: 0.4,
          avoidOverlap: 0
        },
        repulsion: {
          centralGravity: 0.2,
          springLength: 200,
          springConstant: 0.05,
          nodeDistance: 100,
          damping: 0.09
        },
        hierarchicalRepulsion: {
          centralGravity: 0.0,
          springLength: 100,
          springConstant: 0.01,
          nodeDistance: 120,
          damping: 0.09
        },
        maxVelocity: 50,
        minVelocity: 0.1,
        solver: 'barnesHut',
        stabilization: {
          enabled: true,
          iterations: 1000,
          updateInterval: 100,
          onlyDynamicEdges: false,
          fit: true
        },
        timestep: 0.5
      }
    }

    network.setOptions(options);

    // only the options that have shorthand notations are shown.
    var options = {
      physics:{
        stabilization: false
      }
    }
    network.setOptions(options);

All of the individual options are explained here:

Name | Type | Default | Description
--- | --- | --- | ---
enabled | Boolean | `true` | 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.
barnesHut | Object | `Object` | BarnesHut is a quadtree based gravity model. This is the fastest, default and recommended solver for non-hierarchical layouts.
barnesHut.gravitationalConstant | Number | `-2000` | Gravity attracts. We like repulsion. So the value is negative. If you want the repulsion to be stronger, decrease the value (so -10000, -50000).
barnesHut.centralGravity | Number | `0.3` | There is a central gravity attractor to pull the entire network back to the center.
barnesHut.springLength | Number | `95` | The edges are modelled as springs. This springLength here is the the rest length of the spring.
barnesHut.springConstant | Number | `0.04` | This is how 'sturdy' the springs are. Higher values mean stronger springs.
barnesHut.damping | Number | `0.09` | Accepted range: `[0 .. 1]`. The damping factor is how much of the velocity from the previous physics simulation iteration carries over to the next iteration.
barnesHut.avoidOverlap | Number | `0` | Accepted range: `[0 .. 1]`. When larger than 0, the size of the node is taken into account. The distance will be calculated from the radius of the encompassing circle of the node for both the gravity model. Value 1 is maximum overlap avoidance.
forceAtlas2Based | Object | `Object` | Force Atlas 2 has been developed by Jacomi et al (2014) for use with Gephi. The forceAtlas2Based solver makes use of some of the equations provided by them and makes use of the barnesHut implementation in vis. The main differences are the central gravity model, which is here distance independent, and the repulsion being linear instead of quadratic. Finally, all node masses have a multiplier based on the amount of connected edges plus one.
forceAtlas2Based.gravitationalConstant | Number | `-50` | This is similar to the barnesHut method except that the falloff is linear instead of quadratic. The connectivity is also taken into account as a factor of the mass. If you want the repulsion to be stronger, decrease the value (so -1000, -2000).
forceAtlas2Based.centralGravity | Number | `0.01` | There is a central gravity attractor to pull the entire network back to the center. This is not dependent on distance.
forceAtlas2Based.springLength | Number | `100` | The edges are modelled as springs. This springLength here is the the rest length of the spring.
forceAtlas2Based.springConstant | Number | `0.08` | This is how 'sturdy' the springs are. Higher values mean stronger springs.
forceAtlas2Based.damping | Number | `0.4` | Accepted range: `[0 .. 1]`. The damping factor is how much of the velocity from the previous physics simulation iteration carries over to the next iteration.
forceAtlas2Based.avoidOverlap | Number | `0` | Accepted range: `[0 .. 1]`. When larger than 0, the size of the node is taken into account. The distance will be calculated from the radius of the encompassing circle of the node for both the gravity model. Value 1 is maximum overlap avoidance.
repulsion | Object | `Object` | The repulsion model assumes nodes have a simplified repulsion field around them. It's force linearly decreases from 1 (at 0.5*nodeDistance and smaller) to 0 (at 2*nodeDistance).
repulsion.nodeDistance | Number | `100` | This is the range of influence for the repulsion.
repulsion.centralGravity | Number | `0.2` | There is a central gravity attractor to pull the entire network back to the center.
repulsion.springLength | Number | `200` | The edges are modelled as springs. This springLength here is the the rest length of the spring.
repulsion.springConstant | Number | `0.05` | This is how 'sturdy' the springs are. Higher values mean stronger springs.
repulsion.damping | Number | `0.09` | Accepted range: `[0 .. 1]`. The damping factor is how much of the velocity from the previous physics simulation iteration carries over to the next iteration.
hierarchicalRepulsion | Object | `Object` | This model is based on the repulsion solver but the levels are taken into account and the forces are normalized.
hierarchicalRepulsion.nodeDistance | Number | `120` | This is the range of influence for the repulsion.
hierarchicalRepulsion.centralGravity | Number | `0.0'` | There is a central gravity attractor to pull the entire network back to the center.
hierarchicalRepulsion.springLength | Number | `100` | The edges are modelled as springs. This springLength here is the the rest length of the spring.
hierarchicalRepulsion.springConstant | Number | `0.01` | This is how 'sturdy' the springs are. Higher values mean stronger springs.
hierarchicalRepulsion.damping | Number | `0.09` | Accepted range: `[0 .. 1]`. The damping factor is how much of the velocity from the previous physics simulation iteration carries over to the next iteration.
maxVelocity | Number | `50` | The physics module limits the maximum velocity of the nodes to increase the time to stabilization. This is the maximium value.
minVelocity | Number | `0.1` | Once the minimum velocity is reached for all nodes, we assume the network has been stabilized and the simulation stops.
solver | String | `'barnesHut'` | You can select your own solver. Possible options: `'barnesHut', 'repulsion', 'hierarchicalRepulsion', 'forceAtlas2Based'`. When setting the hierarchical layout, the hierarchical repulsion solver is automaticaly selected, regardless of what you fill in here.
stabilization | Object | Boolean | `Object` | When true, the network is stabilized on load using default settings. If false, stabilization is disabled. To further customize this, you can supply an object.
stabilization.enabled | Boolean | `true` | Toggle the stabilization. This is an optional property. If undefined, it is automatically set to true when any of the properties of this object are defined.
stabilization.iterations | Number | `1000` | The physics module tries to stabilize the network on load up til a maximum number of iterations defined here. If the network stabilized with less, you are finished before the maximum number.
stabilization.updateInterval | Number | `50` | When stabilizing, the DOM can freeze. You can chop the stabilization up into pieces to show a loading bar for instance. The interval determines after how many iterations the `stabilizationProgress` event is triggered.
stabilization.onlyDynamicEdges | Boolean | `false` | If you have predefined the position of all nodes and only want to stabilize the dynamic smooth edges, set this to true. It freezes all nodes except the invisible dynamic smooth curve support nodes. If you want the visible nodes to move and stabilize, do not use this.
stabilization.fit | Boolean | `true` | Toggle whether or not you want the view to zoom to fit all nodes when the stabilization is finished.
timestep | Number | `0.5` | The physics simulation is discrete. This means we take a step in time, calculate the forces, move the nodes and take another step. If you increase this number the steps will be too large and the network can get unstable. If you see a lot of jittery movement in the network, you may want to reduce this value a little.