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.

154 lines
6.1 KiB

11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
  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 LENGTH_MAIN = 350,
  24. LENGTH_SERVER = 150,
  25. LENGTH_SUB = 50,
  26. WIDTH_SCALE = 2,
  27. GREEN = 'green',
  28. RED = '#C5000B',
  29. ORANGE = 'orange',
  30. //GRAY = '#666666',
  31. GRAY = 'gray',
  32. BLACK = '#2B1B17';
  33. // Called when the Visualization API is loaded.
  34. function draw() {
  35. // Create a data table with nodes.
  36. nodes = [];
  37. // Create a data table with links.
  38. edges = [];
  39. nodes.push({id: 1, label: '192.168.0.1', group: 'switch', value: 10});
  40. nodes.push({id: 2, label: '192.168.0.2', group: 'switch', value: 8});
  41. nodes.push({id: 3, label: '192.168.0.3', group: 'switch', value: 6});
  42. edges.push({from: 1, to: 2, length: LENGTH_MAIN, width: WIDTH_SCALE * 6, label: '0.71 mbps'});
  43. edges.push({from: 1, to: 3, length: LENGTH_MAIN, width: WIDTH_SCALE * 4, label: '0.55 mbps'});
  44. // group around 2
  45. for (var i = 100; i <= 104; i++) {
  46. var value = 1;
  47. var width = WIDTH_SCALE * 2;
  48. var color = GRAY;
  49. var label = null;
  50. if (i === 103) {
  51. value = 5;
  52. width = 3;
  53. }
  54. if (i === 102) {
  55. color = RED;
  56. label = 'error';
  57. }
  58. nodes.push({id: i, label: '192.168.0.' + i, group: 'desktop', value: value});
  59. edges.push({from: 2, to: i, length: LENGTH_SUB, color: color, fontColor: color, width: width, label: label});
  60. }
  61. nodes.push({id: 201, label: '192.168.0.201', group: 'desktop', value: 1});
  62. edges.push({from: 2, to: 201, length: LENGTH_SUB, color: GRAY, width: WIDTH_SCALE});
  63. // group around 3
  64. nodes.push({id: 202, label: '192.168.0.202', group: 'desktop', value: 4});
  65. edges.push({from: 3, to: 202, length: LENGTH_SUB, color: GRAY, width: WIDTH_SCALE * 2});
  66. for (var i = 230; i <= 231; i++ ) {
  67. nodes.push({id: i, label: '192.168.0.' + i, group: 'mobile', value: 2});
  68. edges.push({from: 3, to: i, length: LENGTH_SUB, color: GRAY, fontColor: GRAY, width: WIDTH_SCALE});
  69. }
  70. // group around 1
  71. nodes.push({id: 10, label: '192.168.0.10', group: 'server', value: 10});
  72. edges.push({from: 1, to: 10, length: LENGTH_SERVER, color: GRAY, width: WIDTH_SCALE * 6, label: '0.92 mbps'});
  73. nodes.push({id: 11, label: '192.168.0.11', group: 'server', value: 7});
  74. edges.push({from: 1, to: 11, length: LENGTH_SERVER, color: GRAY, width: WIDTH_SCALE * 3, label: '0.68 mbps'});
  75. nodes.push({id: 12, label: '192.168.0.12', group: 'server', value: 3});
  76. edges.push({from: 1, to: 12, length: LENGTH_SERVER, color: GRAY, width: WIDTH_SCALE, label: '0.3 mbps'});
  77. nodes.push({id: 204, label: 'Internet', group: 'internet', value: 10});
  78. edges.push({from: 1, to: 204, length: 200, width: WIDTH_SCALE * 3, label: '0.63 mbps'});
  79. // legend
  80. var mygraph = document.getElementById('mygraph');
  81. var x = - mygraph.clientWidth / 2 + 50;
  82. var y = - mygraph.clientHeight / 2 + 50;
  83. var step = 70;
  84. nodes.push({id: 1000, x: x, y: y, label: 'Internet', group: 'internet', value: 1});
  85. nodes.push({id: 1001, x: x, y: y + step, label: 'Switch', group: 'switch', value: 1});
  86. nodes.push({id: 1002, x: x, y: y + 2 * step, label: 'Server', group: 'server', value: 1});
  87. nodes.push({id: 1003, x: x, y: y + 3 * step, label: 'Computer', group: 'desktop', value: 1});
  88. nodes.push({id: 1004, x: x, y: y + 4 * step, label: 'Smartphone', group: 'mobile', value: 1});
  89. // create a graph
  90. var container = document.getElementById('mygraph');
  91. var data = {
  92. nodes: nodes,
  93. edges: edges
  94. };
  95. var options = {
  96. stabilize: false, // stabilize positions before displaying
  97. nodes: {
  98. radiusMin: 16,
  99. radiusMax: 32,
  100. fontColor: BLACK
  101. },
  102. edges: {
  103. color: GRAY
  104. },
  105. groups: {
  106. 'switch': {
  107. shape: 'triangle',
  108. color: '#FF9900' // orange
  109. },
  110. desktop: {
  111. shape: 'dot',
  112. color: "#2B7CE9" // blue
  113. },
  114. mobile: {
  115. shape: 'dot',
  116. color: "#5A1E5C" // purple
  117. },
  118. server: {
  119. shape: 'square',
  120. color: "#C5000B" // red
  121. },
  122. internet: {
  123. shape: 'square',
  124. color: "#109618" // green
  125. }
  126. }
  127. };
  128. graph = new vis.Graph(container, data, options);
  129. }
  130. </script>
  131. </head>
  132. <body onload="draw()">
  133. <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>
  134. </body></html>