animateWindow.html 3.1 KB

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