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.

54 lines
1.5 KiB

  1. <!DOCTYPE HTML>
  2. <html>
  3. <head>
  4. <title>Timeline | Custom snapping</title>
  5. <script src="../../../dist/vis.js"></script>
  6. <link href="../../../dist/vis.css" rel="stylesheet" type="text/css" />
  7. <script src="../../googleAnalytics.js"></script>
  8. </head>
  9. <body>
  10. <p>
  11. When moving the items in on the Timeline below, they will snap to full hours,
  12. independent of being zoomed in or out.
  13. </p>
  14. <div id="visualization"></div>
  15. <script type="text/javascript">
  16. // DOM element where the Timeline will be attached
  17. var container = document.getElementById('visualization');
  18. // Create a DataSet (allows two way data-binding)
  19. var items = new vis.DataSet([
  20. {id: 1, content: 'A', start: '2015-02-09T04:00:00'},
  21. {id: 2, content: 'B', start: '2015-02-09T14:00:00'},
  22. {id: 3, content: 'C', start: '2015-02-09T16:00:00'},
  23. {id: 4, content: 'D', start: '2015-02-09T17:00:00'},
  24. {id: 5, content: 'E', start: '2015-02-10T03:00:00'}
  25. ]);
  26. // Configuration for the Timeline
  27. var options = {
  28. editable: true,
  29. // always snap to full hours, independent of the scale
  30. snap: function (date, scale, step) {
  31. var hour = 60 * 60 * 1000;
  32. return Math.round(date / hour) * hour;
  33. }
  34. // to configure no snapping at all:
  35. //
  36. // snap: null
  37. //
  38. // or let the snap function return the date unchanged:
  39. //
  40. // snap: function (date, scale, step) {
  41. // return date;
  42. // }
  43. };
  44. // Create a Timeline
  45. var timeline = new vis.Timeline(container, items, options);
  46. </script>
  47. </body>
  48. </html>