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.

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