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.

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