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.

198 lines
5.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
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. .vis-timeline .vis-item.vis-range .vis-drag-left,
  21. .vis-timeline .vis-item.vis-range .vis-drag-right {
  22. /*width: 40px;*/
  23. background: rgba(255,255,255,0.5);
  24. }
  25. #visualization .vis-grid.vis-vertical.odd {
  26. background: #f5f5f5;
  27. }
  28. #visualization .vis-grid.vis-vertical.saturday,
  29. #visualization .vis-grid.vis-vertical.sunday {
  30. background: gray;
  31. }
  32. #visualization .vis-text.saturday,
  33. #visualization .vis-text.sunday {
  34. color: white;
  35. }
  36. </style>
  37. <script>(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)})(window,document,'script','//www.google-analytics.com/analytics.js','ga');ga('create', 'UA-61231638-1', 'auto');ga('send', 'pageview');</script></head>
  38. <body>
  39. <div>
  40. <label for="orientation">Orientation</label>
  41. <select id="orientation">
  42. <option value="both" selected>both</option>
  43. <option value="bottom">bottom</option>
  44. <option value="top">top</option>
  45. </select>
  46. </div>
  47. <script>
  48. var o = document.getElementById('orientation');
  49. o.onchange = function () {
  50. timeline.setOptions({
  51. orientation: o.value
  52. });
  53. };
  54. </script>
  55. <div>
  56. <label for="currenttime"><input id="currenttime" type="checkbox" checked="true"> Show current time</label>
  57. </div>
  58. <script>
  59. var currenttime = document.getElementById('currenttime');
  60. currenttime.onchange = function () {
  61. timeline.setOptions({
  62. showCurrentTime: currenttime.checked
  63. });
  64. };
  65. </script>
  66. <br>
  67. <div id="visualization"></div>
  68. <div style="height: 1000px;"></div><!-- for testing vertical scroll on touch devices-->
  69. <script>
  70. console.time('create dataset');
  71. // create a dataset with items
  72. var now = moment().minutes(0).seconds(0).milliseconds(0);
  73. var items = new vis.DataSet({
  74. type: {
  75. start: 'ISODate',
  76. end: 'ISODate'
  77. },
  78. fieldId: '_id'
  79. });
  80. var someHtml = document.createElement('div');
  81. someHtml.innerHTML = 'Click <a href="javascript: alert(\'you clicked an anchor\');">here <span style="color: green;">or here</span></a><br><button onclick="alert(\'click\')">Click me</button>';
  82. items.add([
  83. {_id: 0, content: someHtml, start: now.clone().add(3, 'days').toDate(), title: 'hello title!'},
  84. {_id: '1', content: 'item 1<br>start', start: now.clone().add(4, 'days').toDate()},
  85. {_id: 2, content: '<a href="javascript: alert(\'you clicked an anchor\');">Click here! (anchor)</a><br><br>' +
  86. '<div onclick="alert(\'you clicked a div\'); ">Click here! (div)</div>', start: now.clone().add(-2, 'days').toDate() },
  87. {_id: 3, content: 'item 3', start: now.clone().add(2, 'days').toDate(), style: 'color: red;'},
  88. {
  89. _id: 4, content: 'item 4 foo bar foo bar foo bar foo bar foo bar',
  90. start: now.clone().add(0, 'days').toDate(),
  91. end: now.clone().add(7, 'days').toDate(),
  92. title: 'hello title!'
  93. },
  94. {
  95. _id: 4.1, content: 'item 4.1 test overflow foo bar foo bar foo bar',
  96. start: now.clone().add(0, 'days').toDate(),
  97. end: now.clone().add(1, 'days').toDate(),
  98. title: 'hello title!'
  99. },
  100. {
  101. _id: 4.2, content: 'item 4.2 test overflow foo bar foo bar foo bar',
  102. start: now.clone().add(1, 'days').toDate(),
  103. end: now.clone().add(1, 'days').add(1, 'minutes').toDate(),
  104. title: 'hello title!'
  105. },
  106. {_id: 5, content: 'item 5', start: now.clone().add(9, 'days').toDate(), type:'point', title: 'hello title!'},
  107. {_id: 6, content: 'item 6', start: now.clone().add(11, 'days').toDate()}
  108. ]);
  109. var container = document.getElementById('visualization');
  110. var options = {
  111. editable: true,
  112. //orientation: 'top',
  113. orientation: 'both',
  114. start: now.clone().add(-7, 'days'),
  115. end: now.clone().add(7, 'days'),
  116. //maxHeight: 200,
  117. //height: 200,
  118. showCurrentTime: true,
  119. showCustomTime: true,
  120. format: {
  121. minorLabels: {
  122. 'weekday': 'dddd D',
  123. 'month': 'MMMM'
  124. },
  125. majorLabels: {
  126. 'minute': 'dddd D MMMM',
  127. 'hour': 'dddd D MMMM'
  128. }
  129. },
  130. // timeAxis: {
  131. // scale: 'hour',
  132. // step: 2
  133. // }
  134. //clickToUse: true,
  135. //min: moment('2013-01-01'),
  136. //max: moment('2013-12-31'),
  137. //zoomMin: 1000 * 60 * 60 * 24, // 1 day
  138. zoomMax: 1000 * 60 * 60 * 24 * 30 * 6 // 6 months
  139. };
  140. console.timeEnd('create dataset');
  141. console.time('create timeline');
  142. var timeline = new vis.Timeline(container, items, options);
  143. console.timeEnd('create timeline');
  144. timeline.on('select', function (selection) {
  145. console.log('select', selection);
  146. });
  147. timeline.on('click', function (props) {
  148. console.log('click', props);
  149. });
  150. timeline.on('contextmenu', function (props) {
  151. console.log('contextmenu', props);
  152. });
  153. // timeline.on('touch', function (event) {
  154. // console.log('touch', event, Object.keys(event));
  155. // });
  156. //
  157. // timeline.on('release', function (event) {
  158. // console.log('release', event, Object.keys(event));
  159. // });
  160. /*
  161. timeline.on('rangechange', function (range) {
  162. console.log('rangechange', range);
  163. });
  164. timeline.on('rangechanged', function (range) {
  165. console.log('rangechanged', range);
  166. });
  167. */
  168. items.on('add', console.log.bind(console));
  169. items.on('update', console.log.bind(console));
  170. items.on('remove', console.log.bind(console));
  171. </script>
  172. </body>
  173. </html>