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.

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