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.

89 lines
2.8 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. <div id="visualization"></div>
  24. <script>
  25. // create a dataset with items
  26. // we specify the type of the fields `start` and `end` here to be strings
  27. // containing an ISO date. The fields will be outputted as ISO dates
  28. // automatically getting data from the DataSet via items.get().
  29. var items = new vis.DataSet({
  30. type: { start: 'ISODate', end: 'ISODate' }
  31. });
  32. // add items to the DataSet
  33. items.add([
  34. {id: 1, content: 'item 1<br>start', start: '2014-01-23'},
  35. {id: 2, content: 'item 2', start: '2014-01-18'},
  36. {id: 3, content: 'item 3', start: '2014-01-21'},
  37. {id: 4, content: 'item 4', start: '2014-01-19', end: '2014-01-24'},
  38. {id: 5, content: 'item 5', start: '2014-01-28', type:'point'},
  39. {id: 6, content: 'item 6', start: '2014-01-26'}
  40. ]);
  41. var container = document.getElementById('visualization');
  42. var options = {
  43. start: '2014-01-10',
  44. end: '2014-02-10',
  45. editable: true,
  46. showCurrentTime: true
  47. };
  48. var timeline = new vis.Timeline(container, items, options);
  49. document.getElementById('window1').onclick = function() {
  50. timeline.setWindow('2014-01-01', '2014-04-01');
  51. };
  52. document.getElementById('window2').onclick = function() {
  53. timeline.setWindow('2014-01-01', '2014-04-01', {
  54. animate: false
  55. });
  56. };
  57. document.getElementById('fit').onclick = function() {
  58. timeline.fit();
  59. };
  60. document.getElementById('select').onclick = function() {
  61. timeline.setSelection([5, 6], {
  62. focus: true
  63. });
  64. };
  65. document.getElementById('focus1').onclick = function() {
  66. timeline.focus(2);
  67. };
  68. document.getElementById('focus2').onclick = function() {
  69. timeline.focus([5, 6], {
  70. animate: 3000 // ms
  71. });
  72. };
  73. document.getElementById('focus3').onclick = function() {
  74. var selection = timeline.getSelection();
  75. timeline.focus(selection);
  76. };
  77. </script>
  78. </body>
  79. </html>