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.

67 lines
1.4 KiB

  1. <!doctype html>
  2. <html>
  3. <head>
  4. <title>Graph | Selections</title>
  5. <script type="text/javascript" src="../../vis.js"></script>
  6. </head>
  7. <body>
  8. <div id="mygraph"></div>
  9. <div id="info"></div>
  10. <script type="text/javascript">
  11. // create an array with nodes
  12. var nodes = [
  13. {id: 1, text: 'Node 1'},
  14. {id: 2, text: 'Node 2'},
  15. {id: 3, text: 'Node 3'},
  16. {id: 4, text: 'Node 4'},
  17. {id: 5, text: 'Node 5'}
  18. ];
  19. // create an array with edges
  20. var edges = [
  21. {from: 1, to: 2},
  22. {from: 1, to: 3},
  23. {from: 2, to: 4},
  24. {from: 2, to: 5}
  25. ];
  26. // create a graph
  27. var container = document.getElementById('mygraph');
  28. var data = {
  29. nodes: nodes,
  30. edges: edges
  31. };
  32. var options = {
  33. width: '400px',
  34. height: '400px'
  35. };
  36. graph = new vis.Graph(container, data, options);
  37. // add event listener
  38. function onSelect() {
  39. var selection = graph.getSelection();
  40. var info = 'selection: ';
  41. selection.forEach(function (s) {
  42. info += s.row + ' ';
  43. });
  44. document.getElementById('info').innerHTML += info + '<br>';
  45. }
  46. vis.events.addListener(graph, 'select', onSelect);
  47. // set initial selection (row based, zero-based)
  48. var selection = [
  49. {'row': 2},
  50. {'row': 3},
  51. {'row': 4}
  52. ];
  53. graph.setSelection(selection);
  54. </script>
  55. </body>
  56. </html>