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.

135 lines
3.5 KiB

11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
  1. <!DOCTYPE HTML>
  2. <html>
  3. <head>
  4. <title></title>
  5. <script src="../node_modules/moment/moment.js"></script>
  6. <script src="../dist/vis.js"></script>
  7. <link href="../dist/vis.css" rel="stylesheet" type="text/css" />
  8. <style type="text/css">
  9. body, html {
  10. font-family: sans-serif;
  11. font-size: 11pt;
  12. }
  13. #visualization .itemset {
  14. /*background: rgba(255, 255, 0, 0.5);*/
  15. }
  16. /*
  17. .vis.timeline .item.range .content {
  18. overflow: hidden;
  19. max-width: none;
  20. }
  21. */
  22. </style>
  23. </head>
  24. <body>
  25. <div>
  26. <label for="orientation">Orientation</label>
  27. <select id="orientation">
  28. <option value="top">top</option>
  29. <option value="bottom" selected>bottom</option>
  30. </select>
  31. </div>
  32. <script>
  33. var o = document.getElementById('orientation');
  34. o.onchange = function () {
  35. timeline.setOptions({
  36. orientation: o.value
  37. });
  38. };
  39. </script>
  40. <div>
  41. <label for="currenttime"><input id="currenttime" type="checkbox" checked="true"> Show current time</label>
  42. </div>
  43. <script>
  44. var currenttime = document.getElementById('currenttime');
  45. currenttime.onchange = function () {
  46. timeline.setOptions({
  47. showCurrentTime: currenttime.checked
  48. });
  49. };
  50. </script>
  51. <br>
  52. <div id="visualization"></div>
  53. <script>
  54. console.time('create dataset');
  55. // create a dataset with items
  56. var now = moment().minutes(0).seconds(0).milliseconds(0);
  57. var items = new vis.DataSet({
  58. type: {
  59. start: 'ISODate',
  60. end: 'ISODate'
  61. },
  62. fieldId: '_id'
  63. });
  64. items.add([
  65. {_id: 0, content: 'item 0', start: now.clone().add('days', 3).toDate()},
  66. {_id: 1, content: 'item 1<br>start', start: now.clone().add('days', 4).toDate()},
  67. {_id: 2, content: 'item 2', start: now.clone().add('days', -2).toDate() },
  68. {_id: 3, content: 'item 3', start: now.clone().add('days', 2).toDate()},
  69. {
  70. _id: 4, content: 'item 4 asdfjkadsf adksfk adskfadks aksdfk asdfkkadkskafdskdfs ',
  71. start: now.clone().add('days', 0).toDate(),
  72. end: now.clone().add('days', 7).toDate(), className: 'overflow'
  73. },
  74. {
  75. _id: 7, content: 'item 7 asdfjkadsf adksfk adskfadks aksdfk asdfkkadkskafdskdfs ',
  76. start: now.clone().add('days', 0).toDate(),
  77. end: now.clone().add('days', 7).toDate()
  78. },
  79. {_id: 5, content: 'item 5', start: now.clone().add('days', 9).toDate(), type:'point'},
  80. {_id: 6, content: 'item 6', start: now.clone().add('days', 11).toDate()}
  81. ]);
  82. var container = document.getElementById('visualization');
  83. var options = {
  84. editable: true,
  85. //orientation: 'top',
  86. start: now.clone().add('days', -7),
  87. end: now.clone().add('days', 7),
  88. //maxHeight: 200,
  89. //height: 200,
  90. showCurrentTime: true,
  91. showCustomTime: true,
  92. //min: moment('2013-01-01'),
  93. //max: moment('2013-12-31'),
  94. //zoomMin: 1000 * 60 * 60 * 24, // 1 day
  95. zoomMax: 1000 * 60 * 60 * 24 * 30 * 6 // 6 months
  96. };
  97. console.timeEnd('create dataset');
  98. console.time('create timeline');
  99. var timeline = new vis.Timeline(container, items, options);
  100. console.timeEnd('create timeline');
  101. timeline.on('select', function (selection) {
  102. console.log('select', selection);
  103. });
  104. /*
  105. timeline.on('rangechange', function (range) {
  106. console.log('rangechange', range);
  107. });
  108. timeline.on('rangechanged', function (range) {
  109. console.log('rangechanged', range);
  110. });
  111. */
  112. items.on('add', console.log.bind(console));
  113. items.on('update', console.log.bind(console));
  114. items.on('remove', console.log.bind(console));
  115. </script>
  116. </body>
  117. </html>