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.

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