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.

122 lines
3.2 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. </style>
  17. </head>
  18. <body>
  19. <div>
  20. <label for="orientation">Orientation</label>
  21. <select id="orientation">
  22. <option value="top">top</option>
  23. <option value="bottom" selected>bottom</option>
  24. </select>
  25. </div>
  26. <script>
  27. var o = document.getElementById('orientation');
  28. o.onchange = function () {
  29. timeline.setOptions({
  30. orientation: o.value
  31. });
  32. };
  33. </script>
  34. <div>
  35. <label for="currenttime"><input id="currenttime" type="checkbox" checked="true"> Show current time</label>
  36. </div>
  37. <script>
  38. var currenttime = document.getElementById('currenttime');
  39. currenttime.onchange = function () {
  40. timeline.setOptions({
  41. showCurrentTime: currenttime.checked
  42. });
  43. };
  44. </script>
  45. <br>
  46. <div id="visualization"></div>
  47. <script>
  48. console.time('create dataset');
  49. // create a dataset with items
  50. var now = moment().minutes(0).seconds(0).milliseconds(0);
  51. var items = new vis.DataSet({
  52. type: {
  53. start: 'ISODate',
  54. end: 'ISODate'
  55. },
  56. fieldId: '_id'
  57. });
  58. items.add([
  59. {_id: 0, content: 'item 0', start: now.clone().add('days', 3).toDate(), title: 'hello title!'},
  60. {_id: '1', content: 'item 1<br>start', start: now.clone().add('days', 4).toDate()},
  61. {_id: 2, content: 'item 2', start: now.clone().add('days', -2).toDate() },
  62. {_id: 3, content: 'item 3', start: now.clone().add('days', 2).toDate()},
  63. {
  64. _id: 4, content: 'item 4 ',
  65. start: now.clone().add('days', 0).toDate(),
  66. end: now.clone().add('days', 7).toDate(),
  67. title: 'hello title!'
  68. },
  69. {_id: 5, content: 'item 5', start: now.clone().add('days', 9).toDate(), type:'point', title: 'hello title!'},
  70. {_id: 6, content: 'item 6', start: now.clone().add('days', 11).toDate()}
  71. ]);
  72. var container = document.getElementById('visualization');
  73. var options = {
  74. editable: true,
  75. //orientation: 'top',
  76. start: now.clone().add('days', -7),
  77. end: now.clone().add('days', 7),
  78. //maxHeight: 200,
  79. //height: 200,
  80. showCurrentTime: true,
  81. showCustomTime: true,
  82. //min: moment('2013-01-01'),
  83. //max: moment('2013-12-31'),
  84. //zoomMin: 1000 * 60 * 60 * 24, // 1 day
  85. zoomMax: 1000 * 60 * 60 * 24 * 30 * 6 // 6 months
  86. };
  87. console.timeEnd('create dataset');
  88. console.time('create timeline');
  89. var timeline = new vis.Timeline(container, items, options);
  90. console.timeEnd('create timeline');
  91. timeline.on('select', function (selection) {
  92. console.log('select', selection);
  93. });
  94. /*
  95. timeline.on('rangechange', function (range) {
  96. console.log('rangechange', range);
  97. });
  98. timeline.on('rangechanged', function (range) {
  99. console.log('rangechanged', range);
  100. });
  101. */
  102. items.on('add', console.log.bind(console));
  103. items.on('update', console.log.bind(console));
  104. items.on('remove', console.log.bind(console));
  105. </script>
  106. </body>
  107. </html>