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.

155 lines
6.1 KiB

  1. <!DOCTYPE html>
  2. <!-- saved from url=(0046)http://visjs.org/examples/graph/03_images.html -->
  3. <html><head><meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
  4. <title>Graph | Images</title>
  5. <style type="text/css">
  6. body {
  7. font: 10pt arial;
  8. padding: 0;
  9. margin: 0;
  10. overflow: hidden;
  11. }
  12. #mygraph {
  13. width: 100%;
  14. height: 100%;
  15. box-sizing: border-box;
  16. }
  17. </style>
  18. <script type="text/javascript" src="../../vis.min.js"></script>
  19. <script type="text/javascript">
  20. var nodes = null;
  21. var edges = null;
  22. var graph = null;
  23. var DIR = 'img/refresh-cl/',
  24. SWITCH = DIR + 'Network-Pipe-icon.png',
  25. COMPUTER = DIR + 'Hardware-My-Computer-3-icon.png',
  26. PRINTER = DIR + 'Hardware-Printer-Blue-icon.png',
  27. LENGTH_MAIN = 350,
  28. LENGTH_SERVER = 150,
  29. LENGTH_SUB = 50,
  30. GREEN = 'green',
  31. RED = '#FA0A10',
  32. ORANGE = 'orange',
  33. GRAY = 'gray',
  34. BLACK = '#2B1B17';
  35. // Called when the Visualization API is loaded.
  36. function draw() {
  37. // Create a data table with nodes.
  38. nodes = [];
  39. // Create a data table with links.
  40. edges = [];
  41. nodes.push({id: 1, label: '192.168.0.1', group: 'switch', value: 10});
  42. nodes.push({id: 2, label: '192.168.0.2', group: 'switch', value: 8});
  43. nodes.push({id: 3, label: '192.168.0.3', group: 'switch', value: 6});
  44. edges.push({from: 1, to: 2, length: LENGTH_MAIN, width: 6, label: '0.71 mbps'});
  45. edges.push({from: 1, to: 3, length: LENGTH_MAIN, width: 4, label: '0.55 mbps'});
  46. // group around 2
  47. for (var i = 100; i <= 104; i++) {
  48. var value = 1;
  49. var width = 1;
  50. var color = GRAY;
  51. var label = null;
  52. if (i === 103) {
  53. value = 5;
  54. width = 3;
  55. }
  56. if (i === 102) {
  57. color = RED;
  58. label = 'error';
  59. }
  60. nodes.push({id: i, label: '192.168.0.' + i, group: 'desktop', value: value});
  61. edges.push({from: 2, to: i, length: LENGTH_SUB, color: color, fontColor: color, width: width, label: label});
  62. }
  63. nodes.push({id: 201, label: '192.168.0.201', group: 'desktop', value: 1});
  64. edges.push({from: 2, to: 201, length: LENGTH_SUB, color: GRAY});
  65. // group around 3
  66. nodes.push({id: 202, label: '192.168.0.202', group: 'desktop', value: 4});
  67. edges.push({from: 3, to: 202, length: LENGTH_SUB, color: GRAY, width: 2});
  68. for (var i = 230; i <= 231; i++ ) {
  69. nodes.push({id: i, label: '192.168.0.' + i, group: 'mobile', value: 2});
  70. edges.push({from: 3, to: i, length: LENGTH_SUB, color: GRAY, fontColor: GRAY, width: 1});
  71. }
  72. // group around 1
  73. nodes.push({id: 10, label: '192.168.0.10', group: 'server', value: 10});
  74. edges.push({from: 1, to: 10, length: LENGTH_SERVER, color: GRAY, width: 6, label: '0.92 mbps'});
  75. nodes.push({id: 11, label: '192.168.0.11', group: 'server', value: 7});
  76. edges.push({from: 1, to: 11, length: LENGTH_SERVER, color: GRAY, width: 3, label: '0.68 mbps'});
  77. nodes.push({id: 12, label: '192.168.0.12', group: 'server', value: 3});
  78. edges.push({from: 1, to: 12, length: LENGTH_SERVER, color: GRAY, label: '0.3 mbps'});
  79. nodes.push({id: 204, label: 'Internet', group: 'internet', value: 10});
  80. edges.push({from: 1, to: 204, length: 200, width: 3, label: '0.63 mbps'});
  81. // legend
  82. var mygraph = document.getElementById('mygraph');
  83. var x = - mygraph.clientWidth / 2 + 50;
  84. var y = - mygraph.clientHeight / 2 + 20;
  85. nodes.push({id: 1000, x: x, y: y + 0, label: 'Internet', group: 'internet'});
  86. nodes.push({id: 1001, x: x, y: y + 50, label: 'Switch', group: 'switch'});
  87. nodes.push({id: 1002, x: x, y: y + 100, label: 'Server', group: 'server'});
  88. nodes.push({id: 1003, x: x, y: y + 150, label: 'Computer', group: 'desktop'});
  89. nodes.push({id: 1004, x: x, y: y + 200, label: 'Smartphone', group: 'mobile'});
  90. // create a graph
  91. var container = document.getElementById('mygraph');
  92. var data = {
  93. nodes: nodes,
  94. edges: edges
  95. };
  96. var options = {
  97. stabilize: false, // stabilize positions before displaying
  98. nodes: {
  99. widthMin: 24,
  100. maxWidth: 64,
  101. fontColor: BLACK
  102. },
  103. edges: {
  104. color: GRAY
  105. },
  106. groups: {
  107. 'switch': {
  108. shape: 'triangle',
  109. color: vis.graph.Groups.DEFAULT[1] // yellow
  110. },
  111. desktop: {
  112. shape: 'dot',
  113. color: vis.graph.Groups.DEFAULT[0] // blue
  114. },
  115. mobile: {
  116. shape: 'dot',
  117. color: vis.graph.Groups.DEFAULT[4] // purple
  118. },
  119. server: {
  120. shape: 'square',
  121. color: vis.graph.Groups.DEFAULT[2] // red
  122. },
  123. internet: {
  124. shape: 'square',
  125. color: vis.graph.Groups.DEFAULT[3] // green
  126. }
  127. }
  128. };
  129. graph = new vis.Graph(container, data, options);
  130. }
  131. </script>
  132. </head>
  133. <body onload="draw()">
  134. <div id="mygraph"><div class="graph-frame" style="position: relative; overflow: hidden; width: 100%; height: 100%;"><canvas style="position: relative; width: 100%; height: 100%;"></canvas></div></div>
  135. </body></html>