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.

110 lines
2.8 KiB

  1. <!doctype html>
  2. <html>
  3. <head>
  4. <title>Graph | Playing with Physics</title>
  5. <style type="text/css">
  6. body {
  7. font: 10pt sans;
  8. }
  9. #mygraph {
  10. width: 600px;
  11. height: 600px;
  12. border: 1px solid lightgray;
  13. }
  14. </style>
  15. <script type="text/javascript" src="../../dist/vis.js"></script>
  16. <script type="text/javascript">
  17. var nodes = null;
  18. var edges = null;
  19. var graph = null;
  20. function draw() {
  21. nodes = [];
  22. edges = [];
  23. var connectionCount = [];
  24. // randomly create some nodes and edges
  25. var nodeCount = 60;
  26. for (var i = 0; i < nodeCount; i++) {
  27. nodes.push({
  28. id: i,
  29. label: String(i)
  30. });
  31. connectionCount[i] = 0;
  32. // create edges in a scale-free-graph way
  33. if (i == 1) {
  34. var from = i;
  35. var to = 0;
  36. edges.push({
  37. from: from,
  38. to: to
  39. });
  40. connectionCount[from]++;
  41. connectionCount[to]++;
  42. }
  43. else if (i > 1) {
  44. var conn = edges.length * 2;
  45. var rand = Math.floor(Math.random() * conn);
  46. var cum = 0;
  47. var j = 0;
  48. while (j < connectionCount.length && cum < rand) {
  49. cum += connectionCount[j];
  50. j++;
  51. }
  52. var from = i;
  53. var to = j;
  54. edges.push({
  55. from: from,
  56. to: to
  57. });
  58. connectionCount[from]++;
  59. connectionCount[to]++;
  60. }
  61. }
  62. // create a graph
  63. var container = document.getElementById('mygraph');
  64. var data = {
  65. nodes: nodes,
  66. edges: edges
  67. };
  68. var options = {
  69. edges: {
  70. },
  71. stabilize: false,
  72. configurePhysics:true
  73. };
  74. graph = new vis.Graph(container, data, options);
  75. // add event listeners
  76. graph.on('select', function(params) {
  77. document.getElementById('selection').innerHTML = 'Selection: ' + params.nodes;
  78. });
  79. }
  80. </script>
  81. </head>
  82. <body onload="draw();">
  83. <h2>Playing with Physics</h2>
  84. <div style="width: 700px; font-size:14px;">
  85. Every dataset is different. Nodes can have different sizes based on content, interconnectivity can be high or low etc. Because of this, graph has a special option
  86. that the user can use to explore which settings may be good for him or her. This is ment to be used during the development phase when you are implementing vis.js. Once you have found
  87. settings you are happy with, you can supply them to graph using the documented physics options.
  88. On start, the default settings will be loaded. Keep in mind that selecting the hierarchical simulation mode <b>disables</b> smooth curves. These will not be enabled again afterwards.
  89. </div>
  90. <br />
  91. <div id="mygraph"></div>
  92. <p id="selection"></p>
  93. </body>
  94. </html>