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.

140 lines
4.2 KiB

  1. <!doctype html>
  2. <html>
  3. <head>
  4. <title>Network | Cursor Change</title>
  5. <script type="text/javascript" src="../../../dist/vis.js"></script>
  6. <link href="../../../dist/vis-network.min.css" rel="stylesheet" type="text/css" />
  7. <style type="text/css">
  8. #mynetwork {
  9. width: 600px;
  10. height: 400px;
  11. border: 1px solid lightgray;
  12. }
  13. </style>
  14. </head>
  15. <body>
  16. <p>Here is a simple network with nodes and edges that demonstrates how to change the cursor on hover for nodes and edges.</p>
  17. <p>Use the dropdowns and button below to change the cursor type bound to an event.</p>
  18. <div>
  19. Event Type -
  20. <select id="eventType">
  21. <option value="hoverNode">hoverNode</option>
  22. <option value="blurNode">blurNode</option>
  23. <option value="hoverEdge">hoverEdge</option>
  24. <option value="blurEdge">blurEdge</option>
  25. <option value="dragStart">dragStart</option>
  26. <option value="dragging">dragging</option>
  27. <option value="dragEnd">dragEnd</option>
  28. </select>
  29. &nbsp;
  30. Cursor Type -
  31. <select id="cursorType">
  32. <option value="auto">auto</option>
  33. <option value="default">default</option>
  34. <option value="context-menu">context-menu</option>
  35. <option value="help">help</option>
  36. <option value="pointer">pointer</option>
  37. <option value="progress">progress</option>
  38. <option value="wait">wait</option>
  39. <option value="cell">cell</option>
  40. <option value="crosshair">crosshair</option>
  41. <option value="text">text</option>
  42. <option value="vertical-text">vertical-text</option>
  43. <option value="alias">alias</option>
  44. <option value="copy">copy</option>
  45. <option value="move">move</option>
  46. <option value="no-drop">no-drop</option>
  47. <option value="not-allowed">not-allowed</option>
  48. <option value="all-scroll">all-scroll</option>
  49. <option value="col-resize">col-resize</option>
  50. <option value="row-resize">row-resize</option>
  51. <option value="n-resize">n-resize</option>
  52. <option value="e-resize">e-resize</option>
  53. <option value="w-resize">w-resize</option>
  54. <option value="s-resize">s-resize</option>
  55. <option value="ne-resize">ne-resize</option>
  56. <option value="nw-resize">nw-resize</option>
  57. <option value="se-resize">se-resize</option>
  58. <option value="sw-resize">sw-resize</option>
  59. <option value="ew-resize">ew-resize</option>
  60. <option value="ns-resize">ns-resize</option>
  61. <option value="nesw-resize">nesw-resize</option>
  62. <option value="nwse-resize">nwse-resize</option>
  63. <option value="zoom-in">zoom-in</option>
  64. <option value="zoom-out">zoom-out</option>
  65. <option value="grab">grab</option>
  66. <option value="grabbing">grabbing</option>
  67. </select>
  68. &nbsp;
  69. <button onClick="changeEventCursor(document.getElementById('eventType').value,document.getElementById('cursorType').value);">Change Cursor for Event</button>
  70. </div>
  71. <div id="mynetwork"></div>
  72. <script type="text/javascript">
  73. // create an array with nodes
  74. var nodes = new vis.DataSet([
  75. {id: 1, label: 'Node 1'},
  76. {id: 2, label: 'Node 2'},
  77. {id: 3, label: 'Node 3'},
  78. {id: 4, label: 'Node 4'},
  79. {id: 5, label: 'Node 5'}
  80. ]);
  81. // create an array with edges
  82. var edges = new vis.DataSet([
  83. {from: 1, to: 3},
  84. {from: 1, to: 2},
  85. {from: 2, to: 4},
  86. {from: 2, to: 5}
  87. ]);
  88. // create a network
  89. var container = document.getElementById('mynetwork');
  90. var data = {
  91. nodes: nodes,
  92. edges: edges
  93. };
  94. var options = {interaction:{hover:true}};
  95. var network = new vis.Network(container, data, options);
  96. //Get the canvas HTML element
  97. var networkCanvas = document.getElementById("mynetwork").getElementsByTagName("canvas")[0]
  98. function changeCursor(newCursorStyle){
  99. networkCanvas.style.cursor = newCursorStyle;
  100. }
  101. function changeEventCursor(eventName,cursorType){
  102. network.on(eventName, function() {
  103. changeCursor(cursorType);
  104. });
  105. }
  106. network.on('hoverNode', function () {
  107. changeCursor('grab');
  108. });
  109. network.on('blurNode', function () {
  110. changeCursor('default');
  111. });
  112. network.on('hoverEdge', function () {
  113. changeCursor('grab');
  114. });
  115. network.on('blurEdge', function () {
  116. changeCursor('default');
  117. });
  118. network.on('dragStart', function () {
  119. changeCursor('grabbing');
  120. });
  121. network.on('dragging', function () {
  122. changeCursor('grabbing');
  123. });
  124. network.on('dragEnd', function () {
  125. changeCursor('grab');
  126. });
  127. </script>
  128. </body>
  129. </html>