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.

88 lines
2.6 KiB

  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta charset="utf-8">
  5. <title>JS Bin</title>
  6. <script type="text/javascript" src="../dist/vis.js"></script>
  7. <style>
  8. #mynetwork {
  9. width: 700px;
  10. height: 450px;
  11. border: 1px solid lightgray;
  12. }
  13. </style>
  14. <script>
  15. var network = null;
  16. function destroy() {
  17. if (network !== null) {
  18. network.destroy();
  19. network = null;
  20. }
  21. }
  22. function draw() {
  23. destroy();
  24. var container = document.getElementById('mynetwork');
  25. var nodes = new vis.DataSet();
  26. var edges = new vis.DataSet();
  27. data = {
  28. nodes: nodes,
  29. edges:edges
  30. }
  31. options = {
  32. edges: {
  33. arrows:{
  34. to: true
  35. },
  36. smooth:{
  37. enabled: true
  38. }
  39. },
  40. layout:{
  41. hierarchical: {
  42. enabled: true
  43. }
  44. },
  45. physics:{
  46. enabled: true,
  47. stabilization: true
  48. },
  49. manipulation:{
  50. enabled:false,
  51. addEdge: function (data, callback) {
  52. setTimeout(function () {network.addEdgeMode();},0);
  53. callback(data);
  54. }
  55. }
  56. };
  57. network = new vis.Network(container, data, options);
  58. var layer1Cnt = 0;
  59. var layer2Cnt = 0;
  60. var layer3Cnt = 0;
  61. document.getElementById("addNodeLayer1").onclick = function(e){
  62. nodes.add({id: "layer1_"+layer1Cnt++, label: 'Layer1-'+layer1Cnt, level: 0});
  63. network.addEdgeMode();
  64. }
  65. document.getElementById("addNodeLayer2").onclick = function(e){
  66. nodes.add({id: "layer2_"+layer2Cnt++, label: 'Layer2-'+layer2Cnt, level:1});
  67. network.addEdgeMode();
  68. }
  69. document.getElementById("addNodeLayer3").onclick = function(e){
  70. nodes.add({id: "layer3_"+layer3Cnt++, label: 'Layer3-'+layer3Cnt, level:2});
  71. network.addEdgeMode();
  72. }
  73. }
  74. </script>
  75. </head>
  76. <body onLoad="draw()">
  77. <button id="addNodeLayer1">Layer 1</button>
  78. <button id="addNodeLayer2">Layer 2</button>
  79. <button id="addNodeLayer3">Layer 3</button>
  80. <div id="mynetwork"></div>
  81. </body>
  82. </html>