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.

93 lines
2.9 KiB

  1. <!DOCTYPE HTML>
  2. <html>
  3. <head>
  4. <title>Timeline | Adjusting window</title>
  5. <style>
  6. body, html {
  7. font-family: arial, sans-serif;
  8. font-size: 11pt;
  9. }
  10. </style>
  11. <script src="../../dist/vis.js"></script>
  12. <link href="../../dist/vis.css" rel="stylesheet" type="text/css" />
  13. </head>
  14. <body>
  15. <p>This example demonstrates functions to adjust the visible window of the Timeline.</p>
  16. <input type="button" id="window1" value="Set window from 2014-01-01 to 2014-04-01"><br>
  17. <input type="button" id="window2" value="Set window from 2014-01-01 to 2014-04-01 without animation"><br>
  18. <input type="button" id="fit" value="Fit all items"><br>
  19. <input type="button" id="select" value="Select & focus items 5 and 6"><br>
  20. <input type="button" id="focus1" value="Focus item 2"><br>
  21. <input type="button" id="focus2" value="Focus items 5 and 6 (slow animation)"><br>
  22. <input type="button" id="focus3" value="Focus current selection"><br>
  23. <input type="button" id="moveTo" value="Move to 2014-02-01"><br>
  24. <div id="visualization"></div>
  25. <script>
  26. // create a dataset with items
  27. // we specify the type of the fields `start` and `end` here to be strings
  28. // containing an ISO date. The fields will be outputted as ISO dates
  29. // automatically getting data from the DataSet via items.get().
  30. var items = new vis.DataSet({
  31. type: { start: 'ISODate', end: 'ISODate' }
  32. });
  33. // add items to the DataSet
  34. items.add([
  35. {id: 1, content: 'item 1<br>start', start: '2014-01-23'},
  36. {id: 2, content: 'item 2', start: '2014-01-18'},
  37. {id: 3, content: 'item 3', start: '2014-01-21'},
  38. {id: 4, content: 'item 4', start: '2014-01-19', end: '2014-01-24'},
  39. {id: 5, content: 'item 5', start: '2014-01-28', type:'point'},
  40. {id: 6, content: 'item 6', start: '2014-01-26'}
  41. ]);
  42. var container = document.getElementById('visualization');
  43. var options = {
  44. start: '2014-01-10',
  45. end: '2014-02-10',
  46. editable: true,
  47. showCurrentTime: true
  48. };
  49. var timeline = new vis.Timeline(container, items, options);
  50. document.getElementById('window1').onclick = function() {
  51. timeline.setWindow('2014-01-01', '2014-04-01');
  52. };
  53. document.getElementById('window2').onclick = function() {
  54. timeline.setWindow('2014-01-01', '2014-04-01', {
  55. animate: false
  56. });
  57. };
  58. document.getElementById('fit').onclick = function() {
  59. timeline.fit();
  60. };
  61. document.getElementById('select').onclick = function() {
  62. timeline.setSelection([5, 6], {
  63. focus: true
  64. });
  65. };
  66. document.getElementById('focus1').onclick = function() {
  67. timeline.focus(2);
  68. };
  69. document.getElementById('focus2').onclick = function() {
  70. timeline.focus([5, 6], {
  71. animate: 3000 // ms
  72. });
  73. };
  74. document.getElementById('focus3').onclick = function() {
  75. var selection = timeline.getSelection();
  76. timeline.focus(selection);
  77. };
  78. document.getElementById('moveTo').onclick = function() {
  79. timeline.moveTo('2014-02-01');
  80. };
  81. </script>
  82. </body>
  83. </html>