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.

152 lines
4.0 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="../node_modules/moment/locale/nl.js"></script>
  7. <script>
  8. moment.locale('nl');
  9. </script>
  10. <script src="../dist/vis.js"></script>
  11. <link href="../dist/vis.css" rel="stylesheet" type="text/css" />
  12. <style type="text/css">
  13. body, html {
  14. font-family: sans-serif;
  15. font-size: 11pt;
  16. }
  17. #visualization .itemset {
  18. /*background: rgba(255, 255, 0, 0.5);*/
  19. }
  20. #visualization .grid.vertical.odd {
  21. background: #f5f5f5;
  22. }
  23. #visualization .grid.vertical.saturday,
  24. #visualization .grid.vertical.sunday {
  25. background: gray;
  26. }
  27. #visualization .text.saturday,
  28. #visualization .text.sunday {
  29. color: white;
  30. }
  31. </style>
  32. </head>
  33. <body>
  34. <div>
  35. <label for="orientation">Orientation</label>
  36. <select id="orientation">
  37. <option value="top">top</option>
  38. <option value="bottom" selected>bottom</option>
  39. </select>
  40. </div>
  41. <script>
  42. var o = document.getElementById('orientation');
  43. o.onchange = function () {
  44. timeline.setOptions({
  45. orientation: o.value
  46. });
  47. };
  48. </script>
  49. <div>
  50. <label for="currenttime"><input id="currenttime" type="checkbox" checked="true"> Show current time</label>
  51. </div>
  52. <script>
  53. var currenttime = document.getElementById('currenttime');
  54. currenttime.onchange = function () {
  55. timeline.setOptions({
  56. showCurrentTime: currenttime.checked
  57. });
  58. };
  59. </script>
  60. <br>
  61. <div id="visualization"></div>
  62. <script>
  63. console.time('create dataset');
  64. // create a dataset with items
  65. var now = moment().minutes(0).seconds(0).milliseconds(0);
  66. var items = new vis.DataSet({
  67. type: {
  68. start: 'ISODate',
  69. end: 'ISODate'
  70. },
  71. fieldId: '_id'
  72. });
  73. items.add([
  74. {_id: 0, content: 'item 0', start: now.clone().add(3, 'days').toDate(), title: 'hello title!'},
  75. {_id: '1', content: 'item 1<br>start', start: now.clone().add(4, 'days').toDate()},
  76. {_id: 2, content: '<a href="javascript: alert(\'you clicked an anchor\');">Click here! (anchor)</a><br><br>' +
  77. '<div onclick="alert(\'you clicked a div\'); ">Click here! (div)</div>', start: now.clone().add(-2, 'days').toDate() },
  78. {_id: 3, content: 'item 3', start: now.clone().add(2, 'days').toDate(), style: 'color: red;'},
  79. {
  80. _id: 4, content: 'item 4 foo bar foo bar foo bar foo bar foo bar',
  81. start: now.clone().add(0, 'days').toDate(),
  82. end: now.clone().add(7, 'days').toDate(),
  83. title: 'hello title!'
  84. },
  85. {_id: 5, content: 'item 5', start: now.clone().add(9, 'days').toDate(), type:'point', title: 'hello title!'},
  86. {_id: 6, content: 'item 6', start: now.clone().add(11, 'days').toDate()}
  87. ]);
  88. var container = document.getElementById('visualization');
  89. var options = {
  90. editable: true,
  91. //orientation: 'top',
  92. start: now.clone().add(-7, 'days'),
  93. end: now.clone().add(7, 'days'),
  94. //maxHeight: 200,
  95. //height: 200,
  96. showCurrentTime: true,
  97. showCustomTime: true,
  98. format: {
  99. minorLabels: {
  100. 'weekday': 'dddd D',
  101. 'month': 'MMMM'
  102. },
  103. majorLabels: {
  104. 'minute': 'dddd D MMMM',
  105. 'hour': 'dddd D MMMM'
  106. }
  107. }
  108. //clickToUse: true,
  109. //min: moment('2013-01-01'),
  110. //max: moment('2013-12-31'),
  111. //zoomMin: 1000 * 60 * 60 * 24, // 1 day
  112. //zoomMax: 1000 * 60 * 60 * 24 * 30 * 6 // 6 months
  113. };
  114. console.timeEnd('create dataset');
  115. console.time('create timeline');
  116. var timeline = new vis.Timeline(container, items, options);
  117. console.timeEnd('create timeline');
  118. timeline.on('select', function (selection) {
  119. console.log('select', selection);
  120. });
  121. /*
  122. timeline.on('rangechange', function (range) {
  123. console.log('rangechange', range);
  124. });
  125. timeline.on('rangechanged', function (range) {
  126. console.log('rangechanged', range);
  127. });
  128. */
  129. items.on('add', console.log.bind(console));
  130. items.on('update', console.log.bind(console));
  131. items.on('remove', console.log.bind(console));
  132. </script>
  133. </body>
  134. </html>