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.

88 lines
3.0 KiB

  1. <!doctype html>
  2. <html>
  3. <head>
  4. <title>Network | Interaction events</title>
  5. <script type="text/javascript" src="../../../dist/vis.js"></script>
  6. <link href="../../../dist/vis.css" rel="stylesheet" type="text/css"/>
  7. <style type="text/css">
  8. #mynetwork {
  9. margin-top:1000px;
  10. width: 600px;
  11. height: 400px;
  12. border: 1px solid lightgray;
  13. }
  14. </style>
  15. </head>
  16. <body>
  17. <p>
  18. Create a simple network with some nodes and edges.
  19. </p>
  20. <div id="mynetwork"></div>
  21. <pre id="eventSpan"></pre>
  22. <script type="text/javascript">
  23. // create an array with nodes
  24. var nodes = new vis.DataSet([
  25. {id: 1, label: 'Node 1', title: 'I have a popup!'},
  26. {id: 2, label: 'Node 2', title: 'I have a popup!'},
  27. {id: 3, label: 'Node 3', title: 'I have a popup!'},
  28. {id: 4, label: 'Node 4', title: 'I have a popup!'},
  29. {id: 5, label: 'Node 5', title: 'I have a popup!'}
  30. ]);
  31. // create an array with edges
  32. var edges = new vis.DataSet([
  33. {from: 1, to: 3},
  34. {from: 1, to: 2},
  35. {from: 2, to: 4},
  36. {from: 2, to: 5}
  37. ]);
  38. // create a network
  39. var container = document.getElementById('mynetwork');
  40. var data = {
  41. nodes: nodes,
  42. edges: edges
  43. };
  44. var options = {};
  45. var network = new vis.Network(container, data, options);
  46. network.on("click", function (params) {
  47. params.event = "[original event]";
  48. document.getElementById('eventSpan').innerHTML = '<h2>Click event:</h2>' + JSON.stringify(params, null, 4);
  49. });
  50. network.on("doubleClick", function (params) {
  51. params.event = "[original event]";
  52. document.getElementById('eventSpan').innerHTML = '<h2>doubleClick event:</h2>' + JSON.stringify(params, null, 4);
  53. });
  54. network.on("oncontext", function (params) {
  55. params.event = "[original event]";
  56. document.getElementById('eventSpan').innerHTML = '<h2>oncontext (right click) event:</h2>' + JSON.stringify(params, null, 4);
  57. });
  58. network.on("dragStart", function (params) {
  59. params.event = "[original event]";
  60. document.getElementById('eventSpan').innerHTML = '<h2>dragStart event:</h2>' + JSON.stringify(params, null, 4);
  61. });
  62. network.on("dragging", function (params) {
  63. params.event = "[original event]";
  64. document.getElementById('eventSpan').innerHTML = '<h2>dragging event:</h2>' + JSON.stringify(params, null, 4);
  65. });
  66. network.on("dragEnd", function (params) {
  67. params.event = "[original event]";
  68. document.getElementById('eventSpan').innerHTML = '<h2>dragEnd event:</h2>' + JSON.stringify(params, null, 4);
  69. });
  70. network.on("zoom", function (params) {
  71. document.getElementById('eventSpan').innerHTML = '<h2>zoom event:</h2>' + JSON.stringify(params, null, 4);
  72. });
  73. network.on("showPopup", function (params) {
  74. document.getElementById('eventSpan').innerHTML = '<h2>showPopup event: </h2>' + JSON.stringify(params, null, 4);
  75. });
  76. </script>
  77. <script src="../../googleAnalytics.js"></script>
  78. </body>
  79. </html>