vis.js is a dynamic, browser-based visualization library
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

98 lines
2.0 KiB

  1. <!doctype html>
  2. <html>
  3. <head>
  4. <title>Network | Basic usage</title>
  5. <script type="text/javascript" src="http://www.visjs.org/dist/vis.js"></script>
  6. <link href="http://www.visjs.org/dist/vis.css" rel="stylesheet" type="text/css" />
  7. <style type="text/css">
  8. #div_graph {
  9. width: 1400px;
  10. height: 1000px;
  11. border: 1px solid lightgray;
  12. }
  13. </style>
  14. </head>
  15. <body>
  16. <p>
  17. Create a simple network with some nodes and edges.
  18. </p>
  19. <div id="visualization"></div>
  20. <script type="text/javascript">
  21. var nodes = new vis.DataSet([
  22. {id: '1', label: 'Test1', step : 1},
  23. {id: '2', label: 'Test2', step : 2},
  24. {id: '3', label: 'Test3', step : 3}
  25. ]);
  26. var edges = new vis.DataSet([
  27. {from: '1', to: '2', label: '1'},
  28. {from: '3', to: '2'}
  29. ]);
  30. var currentStep = 1;
  31. var maxStep = nodes.length;
  32. var nodesView = new vis.DataView(nodes, {
  33. filter: function(node)
  34. {
  35. if(node.hasOwnProperty('step'))
  36. return node.step <= currentStep;
  37. else
  38. return false;
  39. }
  40. });
  41. var options = {
  42. width : '100%',
  43. height : '100%',
  44. };
  45. console.log(nodesView, edges)
  46. // create a network
  47. var container = document.getElementById('visualization');
  48. var data = {
  49. nodes: nodesView,
  50. edges: edges
  51. };
  52. var network = new vis.Network(container, data, options);
  53. // nodesView.refresh();
  54. function StepNext()
  55. {
  56. currentStep = currentStep + 1;
  57. if(currentStep > maxStep)
  58. currentStep = maxStep;
  59. nodesView.refresh();
  60. }
  61. function StepBack()
  62. {
  63. currentStep = currentStep - 1;
  64. if(currentStep < 1)
  65. currentStep = 1;
  66. nodesView.refresh();
  67. }
  68. </script>
  69. <button id="btnPrevious" type="button" onclick="StepBack();"><<</button>
  70. <button id="btnNext" type="button" onclick="StepNext();">>></button>
  71. </body>
  72. </html>