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.

80 lines
1.9 KiB

  1. <!doctype html>
  2. <html>
  3. <head>
  4. <title>Network | Random nodes</title>
  5. <style type="text/css">
  6. body {
  7. font: 10pt sans;
  8. }
  9. #mynetwork {
  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. <link href="../../dist/vis.css" rel="stylesheet" type="text/css" />
  17. <script type="text/javascript">
  18. var nodes = null;
  19. var edges = null;
  20. var network = null;
  21. function draw() {
  22. nodes = new vis.DataSet([
  23. {id: '1001', value: '1'},
  24. {id: '1009', value: '2'},
  25. {id: '1061', value: '3'},
  26. {id: '1226', value: '4'}
  27. ]);
  28. edges = new vis.DataSet([
  29. {id: '1001_1061', from: '1001', to: '1061'},
  30. {id: '1001_1226', from: '1001', to: '1226'},
  31. {id: '1009_1061', from: '1009', to: '1061'},
  32. {id: '1009_1226', from: '1009', to: '1226'},
  33. {id: '1061_1226', from: '1061', to: '1226'}
  34. ]);
  35. var container = document.getElementById('mynetwork');
  36. var data = {
  37. nodes: nodes,
  38. edges: edges
  39. };
  40. var options = {
  41. nodes: {
  42. shape: 'dot'
  43. },
  44. edges: {
  45. inheritColor: false
  46. },
  47. physics: {
  48. 'barnesHut': {
  49. centralGravity: 0.5,
  50. springLength: 150,
  51. springConstant: 0.03,
  52. damping: 0.2
  53. }
  54. }
  55. };
  56. network = new vis.Network(container, data, options);
  57. // add event listeners
  58. network.on('select', function(params) {
  59. document.getElementById('selection').innerHTML = 'Selection: ' + params.nodes;
  60. console.log(params.edges)
  61. console.log(network.getSelection())
  62. });
  63. }
  64. </script>
  65. </head>
  66. <body onload="draw();">
  67. <br>
  68. <div id="mynetwork"></div>
  69. <p id="selection"></p>
  70. </body>
  71. </html>