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.

88 lines
2.7 KiB

  1. <!DOCTYPE HTML>
  2. <html>
  3. <head>
  4. <title>Timeline | Show current and custom time bars</title>
  5. <style type="text/css">
  6. body, html {
  7. font-family: 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. <script src="../googleAnalytics.js"></script>
  14. </head>
  15. <body>
  16. <p>
  17. The Timeline has functions to add multiple custom time bars which can be dragged by the user.
  18. </p>
  19. <p>
  20. <input type="button" id="add" value="Add custom vertical bar">
  21. <input type="text" id="barId" placeholder="custom bar ID">
  22. </p>
  23. <p>
  24. <input type="button" id="remove" value="Remove custom vertical bar">
  25. <input type="text" id="barIndex" value="1" placeholder="custom bar ID">
  26. </p>
  27. <p>
  28. <code><strong>timechange</strong></code> event, index: <span id="timechangeBar"></span>, time: <span id="timechangeEvent"></span>
  29. </p>
  30. <p>
  31. <code><strong>timechanged</strong></code> event, index: <span id="timechangedBar"></span>, time: <span id="timechangedEvent"></span>
  32. </p><br>
  33. <div id="visualization"></div>
  34. <script type="text/javascript">
  35. var container = document.getElementById('visualization');
  36. var items = new vis.DataSet();
  37. var customDate = new Date();
  38. var options = {
  39. showCurrentTime: true,
  40. start: new Date(Date.now() - 1000 * 60 * 60 * 24),
  41. end: new Date(Date.now() + 1000 * 60 * 60 * 24 * 6)
  42. };
  43. var timeline = new vis.Timeline(container, items, options);
  44. // Set first time bar
  45. customDate = new Date(customDate.getFullYear(), customDate.getMonth(), customDate.getDate() + 1);
  46. timeline.addCustomTime(customDate, '1');
  47. document.getElementById('add').onclick = function () {
  48. try {
  49. customDate = new Date(customDate.getFullYear(), customDate.getMonth(), customDate.getDate() + 1);
  50. var barId = document.getElementById('barId').value || undefined;
  51. timeline.addCustomTime(customDate, barId);
  52. document.getElementById('barId').value = '';
  53. }
  54. catch (err) {
  55. console.log(err);
  56. alert(err);
  57. }
  58. };
  59. document.getElementById('remove').onclick = function () {
  60. try {
  61. timeline.removeCustomTime(document.getElementById('barIndex').value);
  62. document.getElementById('barIndex').value = '';
  63. }
  64. catch (err) {
  65. console.log(err);
  66. alert(err);
  67. }
  68. };
  69. timeline.on('timechange', function (properties) {
  70. document.getElementById('timechangeBar').innerHTML = properties.id;
  71. document.getElementById('timechangeEvent').innerHTML = properties.time;
  72. });
  73. timeline.on('timechanged', function (properties) {
  74. document.getElementById('timechangedBar').innerHTML = properties.id;
  75. document.getElementById('timechangedEvent').innerHTML = properties.time;
  76. });
  77. </script>
  78. </body>
  79. </html>