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.

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