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.

128 lines
4.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. <style type="text/css">
  7. #mynetwork {
  8. width: 400px;
  9. height: 400px;
  10. border: 1px solid lightgray;
  11. }
  12. </style>
  13. </head>
  14. <body>
  15. <div id="tabs-2"></div>
  16. <script type="text/javascript">
  17. function drawNetwork() {
  18. var nodes = null;
  19. var edges = null;
  20. var network = null;
  21. var LENGTH_MAIN = 350,
  22. WIDTH_SCALE = 2,
  23. GRAY = 'gray',
  24. BLACK = '#2B1B17';
  25. function draw() {
  26. nodes = [];
  27. edges = [];
  28. var parentDeviceName = "Windows Host";
  29. var parentName = "john";
  30. var parentId = 1;
  31. if (parentDeviceName == "Windows Host") {
  32. group = 'windowsHost';
  33. } else if (parentDeviceName == "Sun Host") {
  34. group = 'sunHost';
  35. } else if (parentDeviceName == "Net-SNMP Linux") {
  36. group = 'linuxHost';
  37. } else if (parentDeviceName == "Cisco 2901 K9") {
  38. group = 'router';
  39. } else {
  40. group = 'switch';
  41. }
  42. nodes.push({id: parentId, label: parentName + "\n" + parentDeviceName, group: group, value: 10});
  43. nodes.push({id: 2, label: "bob\nbobby", group: group, value: 10});
  44. edges.push({from: parentId, to: 2, length: LENGTH_MAIN, width: WIDTH_SCALE * 2, label: ''});
  45. var container = document.getElementById('tabs-2');
  46. var data = {
  47. nodes: nodes,
  48. edges: edges
  49. };
  50. var options = {
  51. stabilize: false, // stabilize positions before displaying
  52. nodes: {
  53. radiusMin: 16,
  54. radiusMax: 32,
  55. fontColor: BLACK
  56. },
  57. edges: {
  58. color: GRAY
  59. },
  60. groups: {
  61. 'switch': {
  62. shape: 'image',
  63. image: '/vis.js/examples/network/img/refresh-cl/Hardware-Laptop-1-icon.png'
  64. },
  65. 'router': {
  66. shape: 'image',
  67. image: '/vis.js/examples/network/img/refresh-cl/Hardware-Laptop-1-icon.png'
  68. },
  69. 'firewall': {
  70. shape: 'image',
  71. image: '/vis.js/examples/network/img/refresh-cl/Hardware-Laptop-1-icon.png'
  72. },
  73. desktop: {
  74. shape: 'dot',
  75. color: "#2B7CE9" // blue
  76. },
  77. mobile: {
  78. shape: 'dot',
  79. color: "#5A1E5C" // purple
  80. },
  81. sunHost: {
  82. shape: 'image',
  83. image: '/vis.js/examples/network/img/refresh-cl/Hardware-Laptop-1-icon.png'
  84. },
  85. windowsHost: {
  86. shape: 'image',
  87. image: '/vis.js/examples/network/img/refresh-cl/Hardware-Laptop-1-icon.png'
  88. },
  89. linuxHost: {
  90. shape: 'image',
  91. image: '/vis.js/examples/network/img/refresh-cl/Hardware-Laptop-1-icon.png'
  92. },
  93. server: {
  94. shape: 'square',
  95. color: "#C5000B" // red
  96. },
  97. internet: {
  98. shape: 'square',
  99. color: "#109618" // green
  100. }
  101. },
  102. physics: {
  103. barnesHut: {
  104. enabled: true
  105. }
  106. }
  107. };
  108. network = new vis.Network(container, data, options);
  109. }
  110. draw();
  111. }
  112. drawNetwork();
  113. </script>
  114. </body>
  115. </html>