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.

83 lines
2.7 KiB

  1. <!DOCTYPE HTML>
  2. <html>
  3. <head>
  4. <title>Timeline | navigation menu</title>
  5. <style type="text/css">
  6. body, html, input {
  7. font-family: sans-serif;
  8. font-size: 12pt;
  9. }
  10. #visualization {
  11. position: relative;
  12. }
  13. .menu {
  14. position: absolute;
  15. top: 0;
  16. right: 0;
  17. margin: 10px;
  18. z-index: 9999;
  19. }
  20. </style>
  21. <script src="../../../dist/vis.js"></script>
  22. <link href="../../../dist/vis-timeline-graph2d.min.css" rel="stylesheet" type="text/css" />
  23. </head>
  24. <body>
  25. <p>
  26. Create your own navigation menu by creating an overlay with buttons to zoom and move.
  27. </p>
  28. <div id="visualization">
  29. <div class="menu">
  30. <input type="button" id="zoomIn" value="Zoom in"/>
  31. <input type="button" id="zoomOut" value="Zoom out"/>
  32. <input type="button" id="moveLeft" value="Move left"/>
  33. <input type="button" id="moveRight" value="Move right"/>
  34. <input type="button" id="toggleRollingMode" value="toggleRollingMode"/>
  35. </div>
  36. </div>
  37. <script type="text/javascript">
  38. // create a timeline with some data
  39. var container = document.getElementById('visualization');
  40. var items = new vis.DataSet([
  41. {id: 1, content: 'item 1', start: '2014-04-20'},
  42. {id: 2, content: 'item 2', start: '2014-04-14'},
  43. {id: 3, content: 'item 3', start: '2014-04-18'},
  44. {id: 4, content: 'item 4', start: '2014-04-16', end: '2014-04-19'},
  45. {id: 5, content: 'item 5', start: '2014-04-25'},
  46. {id: 6, content: 'item 6', start: '2014-04-27', type: 'point'}
  47. ]);
  48. var options = {};
  49. var timeline = new vis.Timeline(container, items, options);
  50. /**
  51. * Move the timeline a given percentage to left or right
  52. * @param {Number} percentage For example 0.1 (left) or -0.1 (right)
  53. */
  54. function move (percentage) {
  55. var range = timeline.getWindow();
  56. var interval = range.end - range.start;
  57. timeline.setWindow({
  58. start: range.start.valueOf() - interval * percentage,
  59. end: range.end.valueOf() - interval * percentage
  60. });
  61. }
  62. // attach events to the navigation buttons
  63. document.getElementById('zoomIn').onclick = function () { timeline.zoomIn( 0.2); };
  64. document.getElementById('zoomOut').onclick = function () { timeline.zoomOut( 0.2); };
  65. document.getElementById('moveLeft').onclick = function () { move( 0.2); };
  66. document.getElementById('moveRight').onclick = function () { move(-0.2); };
  67. document.getElementById('toggleRollingMode').onclick = function () { timeline.toggleRollingMode() };
  68. </script>
  69. </body>
  70. </html>