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.

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