3

How can I set options in my network using Vis.js library ?

I can't find any answer. Everyone say :

network.setOptions(options);

But I do not understand. How can I edit these options ?

I want to toggle the zoomView in the network.

$("#zoom-network").click(function(e) { 
    // what to do here ? 
    network.setOptions(options); 
});

EDIT Thanks to AlexP, I found the answer :

$("#zoom-network").click(function(e) {
    var options = {
        interaction : {
            zoomView : true
        }
    };
    network.setOptions(options);
});
Mourad Qqch
  • 373
  • 1
  • 5
  • 16

3 Answers3

2

For animations like zooming you have to use .moveTo

$("#zoom-network").click(function(e) { 
    var options = { 
      scale: 1.5,
      animation: {      
        duration: 1000,
        easingFunction: "easeInOutQuad"
      }
    }
    network.moveTo(options); 
});
alexP
  • 3,672
  • 7
  • 27
  • 36
0
<!doctype html>
<html>
<head>
  <title>Network | Basic usage</title>

  <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>
</head>
<body>

<p>
  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);
  network.setOptions(options);
</script>
</body>
</html>
anshuVersatile
  • 2,030
  • 1
  • 11
  • 18
  • I know that. But how can I do to (un)set the zoomView **without** resetting previous options after the creation of the network ? (based on an event for exemple) – Mourad Qqch Apr 18 '16 at 13:04
  • `$("#zoom-network").click(function(e) { // what to do here ? network.setOptions(options); });` – Mourad Qqch Apr 18 '16 at 13:05
0

You can set individual options (for example, you may wish to only set the "end" option if you have a valid date to supply). So assuming you have a previously set options object, as in the answers above, WITHOUT the "end" option set, you would use code like:

 if (this.end != null) {
       this.options["end"] = this.end;
 }
davaus
  • 1,145
  • 13
  • 16