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.

163 lines
4.3 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. .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. </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. items.add([
  80. {_id: 0, content: 'item 0', start: now.clone().add(3, 'days').toDate(), title: 'hello title!'},
  81. {_id: '1', content: 'item 1<br>start', start: now.clone().add(4, 'days').toDate()},
  82. {_id: 2, content: '<a href="javascript: alert(\'you clicked an anchor\');">Click here! (anchor)</a><br><br>' +
  83. '<div onclick="alert(\'you clicked a div\'); ">Click here! (div)</div>', start: now.clone().add(-2, 'days').toDate() },
  84. {_id: 3, content: 'item 3', start: now.clone().add(2, 'days').toDate(), style: 'color: red;'},
  85. {
  86. _id: 4, content: 'item 4 foo bar foo bar foo bar foo bar foo bar',
  87. start: now.clone().add(0, 'days').toDate(),
  88. end: now.clone().add(7, 'days').toDate(),
  89. title: 'hello title!'
  90. },
  91. {_id: 5, content: 'item 5', start: now.clone().add(9, 'days').toDate(), type:'point', title: 'hello title!'},
  92. {_id: 6, content: 'item 6', start: now.clone().add(11, 'days').toDate()}
  93. ]);
  94. var container = document.getElementById('visualization');
  95. var options = {
  96. editable: true,
  97. //orientation: 'top',
  98. start: now.clone().add(-7, 'days'),
  99. end: now.clone().add(7, 'days'),
  100. //maxHeight: 200,
  101. //height: 200,
  102. showCurrentTime: true,
  103. showCustomTime: true,
  104. format: {
  105. minorLabels: {
  106. 'weekday': 'dddd D',
  107. 'month': 'MMMM'
  108. },
  109. majorLabels: {
  110. 'minute': 'dddd D MMMM',
  111. 'hour': 'dddd D MMMM'
  112. }
  113. },
  114. // timeAxis: {
  115. // scale: 'hour',
  116. // step: 2
  117. // }
  118. //clickToUse: true,
  119. //min: moment('2013-01-01'),
  120. //max: moment('2013-12-31'),
  121. //zoomMin: 1000 * 60 * 60 * 24, // 1 day
  122. zoomMax: 1000 * 60 * 60 * 24 * 30 * 6 // 6 months
  123. };
  124. console.timeEnd('create dataset');
  125. console.time('create timeline');
  126. var timeline = new vis.Timeline(container, items, options);
  127. console.timeEnd('create timeline');
  128. timeline.on('select', function (selection) {
  129. console.log('select', selection);
  130. });
  131. /*
  132. timeline.on('rangechange', function (range) {
  133. console.log('rangechange', range);
  134. });
  135. timeline.on('rangechanged', function (range) {
  136. console.log('rangechanged', range);
  137. });
  138. */
  139. items.on('add', console.log.bind(console));
  140. items.on('update', console.log.bind(console));
  141. items.on('remove', console.log.bind(console));
  142. </script>
  143. </body>
  144. </html>