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.

144 lines
3.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
  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. <script>
  57. console.time('create dataset');
  58. // create a dataset with items
  59. var now = moment().minutes(0).seconds(0).milliseconds(0);
  60. var items = new vis.DataSet({
  61. type: {
  62. start: 'ISODate',
  63. end: 'ISODate'
  64. },
  65. fieldId: '_id'
  66. });
  67. items.add([
  68. {_id: 0, content: 'item 0', start: now.clone().add(3, 'days').toDate(), title: 'hello title!'},
  69. {_id: '1', content: 'item 1<br>start', start: now.clone().add(4, 'days').toDate()},
  70. {_id: 2, content: '<a href="javascript: alert(\'you clicked an anchor\');">Click here! (anchor)</a><br><br>' +
  71. '<div onclick="alert(\'you clicked a div\'); ">Click here! (div)</div>', start: now.clone().add(-2, 'days').toDate() },
  72. {_id: 3, content: 'item 3', start: now.clone().add(2, 'days').toDate(), style: 'color: red;'},
  73. {
  74. _id: 4, content: 'item 4 foo bar foo bar foo bar foo bar foo bar',
  75. start: now.clone().add(0, 'days').toDate(),
  76. end: now.clone().add(7, 'days').toDate(),
  77. title: 'hello title!'
  78. },
  79. {_id: 5, content: 'item 5', start: now.clone().add(9, 'days').toDate(), type:'point', title: 'hello title!'},
  80. {_id: 6, content: 'item 6', start: now.clone().add(11, 'days').toDate()}
  81. ]);
  82. var container = document.getElementById('visualization');
  83. var options = {
  84. editable: true,
  85. //orientation: 'top',
  86. start: now.clone().add(-7, 'days'),
  87. end: now.clone().add(7, 'days'),
  88. //maxHeight: 200,
  89. //height: 200,
  90. showCurrentTime: true,
  91. showCustomTime: true,
  92. format: {
  93. minorLabels: {
  94. 'weekday': 'dddd D',
  95. 'month': 'MMMM'
  96. },
  97. majorLabels: {
  98. 'minute': 'dddd D MMMM',
  99. 'hour': 'dddd D MMMM'
  100. }
  101. },
  102. //clickToUse: true,
  103. //min: moment('2013-01-01'),
  104. //max: moment('2013-12-31'),
  105. //zoomMin: 1000 * 60 * 60 * 24, // 1 day
  106. zoomMax: 1000 * 60 * 60 * 24 * 30 * 6 // 6 months
  107. };
  108. console.timeEnd('create dataset');
  109. console.time('create timeline');
  110. var timeline = new vis.Timeline(container, items, options);
  111. console.timeEnd('create timeline');
  112. timeline.on('select', function (selection) {
  113. console.log('select', selection);
  114. });
  115. /*
  116. timeline.on('rangechange', function (range) {
  117. console.log('rangechange', range);
  118. });
  119. timeline.on('rangechanged', function (range) {
  120. console.log('rangechanged', range);
  121. });
  122. */
  123. items.on('add', console.log.bind(console));
  124. items.on('update', console.log.bind(console));
  125. items.on('remove', console.log.bind(console));
  126. </script>
  127. </body>
  128. </html>