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.

101 lines
2.0 KiB

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