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.5 KiB

  1. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
  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. // specify options
  27. var options = {
  28. width: '400px',
  29. height: '400px'
  30. };
  31. // create a graph
  32. var graph = new vis.Graph(document.getElementById('mygraph'));
  33. // draw the graph with the created data and options
  34. graph.draw(nodes, edges, options);
  35. // add event listener
  36. function onSelect() {
  37. var selection = graph.getSelection();
  38. var info = 'selection: ';
  39. selection.forEach(function (s) {
  40. info += s.row + ' ';
  41. });
  42. document.getElementById('info').innerHTML += info + '<br>';
  43. }
  44. vis.events.addListener(graph, 'select', onSelect);
  45. // set initial selection (row based, zero-based)
  46. var selection = [
  47. {'row': 2},
  48. {'row': 3},
  49. {'row': 4}
  50. ];
  51. graph.setSelection(selection);
  52. </script>
  53. </body>
  54. </html>