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.

94 lines
3.4 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. 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>(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)})(window,document,'script','//www.google-analytics.com/analytics.js','ga');ga('create', 'UA-61231638-1', 'auto');ga('send', 'pageview');</script></head>
  17. <body>
  18. <p>This example demonstrates functions to adjust the visible window of the Timeline.</p>
  19. <p>
  20. <input type="button" id="window1" value="Set window from 2014-01-01 to 2014-04-01"><br>
  21. <input type="button" id="window2" value="Set window from 2014-01-01 to 2014-04-01 without animation"><br>
  22. <input type="button" id="moveTo" value="Move to 2014-02-01"><br>
  23. <input type="button" id="fit" value="Fit all items"><br>
  24. <input type="button" id="select" value="Select & focus items 5 and 6"><br>
  25. <input type="button" id="focus1" value="Focus item 2"><br>
  26. <input type="button" id="focus2" value="Focus items 5 and 6 (slow and linear animation)"><br>
  27. <input type="button" id="focus3" value="Focus current selection"><br>
  28. </p>
  29. <div id="visualization"></div>
  30. <script>
  31. // create a dataset with items
  32. // we specify the type of the fields `start` and `end` here to be strings
  33. // containing an ISO date. The fields will be outputted as ISO dates
  34. // automatically getting data from the DataSet via items.get().
  35. var items = new vis.DataSet({
  36. type: { start: 'ISODate', end: 'ISODate' }
  37. });
  38. // add items to the DataSet
  39. items.add([
  40. {id: 1, content: 'item 1<br>start', start: '2014-01-23'},
  41. {id: 2, content: 'item 2', start: '2014-01-18'},
  42. {id: 3, content: 'item 3', start: '2014-01-21'},
  43. {id: 4, content: 'item 4', start: '2014-01-19', end: '2014-01-24'},
  44. {id: 5, content: 'item 5', start: '2014-01-28', type:'point'},
  45. {id: 6, content: 'item 6', start: '2014-01-26'}
  46. ]);
  47. var container = document.getElementById('visualization');
  48. var options = {
  49. start: '2014-01-10',
  50. end: '2014-02-10',
  51. editable: true,
  52. showCurrentTime: true
  53. };
  54. var timeline = new vis.Timeline(container, items, options);
  55. document.getElementById('window1').onclick = function() {
  56. timeline.setWindow('2014-01-01', '2014-04-01');
  57. };
  58. document.getElementById('window2').onclick = function() {
  59. timeline.setWindow('2014-01-01', '2014-04-01', {animation: false});
  60. };
  61. document.getElementById('fit').onclick = function() {
  62. timeline.fit();
  63. };
  64. document.getElementById('select').onclick = function() {
  65. timeline.setSelection([5, 6], {
  66. focus: true
  67. });
  68. };
  69. document.getElementById('focus1').onclick = function() {
  70. timeline.focus(2);
  71. };
  72. document.getElementById('focus2').onclick = function() {
  73. timeline.focus([5, 6], {animation: {duration: 3000, easingFunction: 'linear'}}); // ms
  74. };
  75. document.getElementById('focus3').onclick = function() {
  76. var selection = timeline.getSelection();
  77. timeline.focus(selection);
  78. };
  79. document.getElementById('moveTo').onclick = function() {
  80. timeline.moveTo('2014-02-01');
  81. };
  82. </script>
  83. </body>
  84. </html>