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.

89 lines
2.6 KiB

  1. <!DOCTYPE HTML>
  2. <html>
  3. <head>
  4. <title>Timeline | Edit items</title>
  5. <style type="text/css">
  6. body, html {
  7. font-family: sans-serif;
  8. }
  9. </style>
  10. <script src="../../dist/vis.js"></script>
  11. <link href="../../dist/vis.css" rel="stylesheet" type="text/css" />
  12. </head>
  13. <body>
  14. <div id="visualization"></div>
  15. <p></p>
  16. <div id="log"></div>
  17. <script type="text/javascript">
  18. var items = new vis.DataSet([
  19. {id: 1, content: 'item 1', start: new Date(2013, 3, 20)},
  20. {id: 2, content: 'item 2', start: new Date(2013, 3, 14)},
  21. {id: 3, content: 'item 3', start: new Date(2013, 3, 18)},
  22. {id: 4, content: 'item 4', start: new Date(2013, 3, 16), end: new Date(2013, 3, 19)},
  23. {id: 5, content: 'item 5', start: new Date(2013, 3, 25)},
  24. {id: 6, content: 'item 6', start: new Date(2013, 3, 27)}
  25. ]);
  26. var container = document.getElementById('visualization');
  27. var options = {
  28. editable: true,
  29. onAdd: function (item, callback) {
  30. item.content = prompt('Enter text content for new item:', item.content);
  31. if (item.content != null) {
  32. callback(item); // send back adjusted new item
  33. }
  34. else {
  35. callback(null); // cancel item creation
  36. }
  37. },
  38. onMove: function (item, callback) {
  39. if (confirm('Do you really want to move the item to\n' +
  40. 'start: ' + item.start + '\n' +
  41. 'end: ' + item.end + '?')) {
  42. callback(item); // send back item as confirmation (can be changed
  43. }
  44. else {
  45. callback(null); // cancel editing item
  46. }
  47. },
  48. onUpdate: function (item, callback) {
  49. item.content = prompt('Edit items text:', item.content);
  50. if (item.content != null) {
  51. callback(item); // send back adjusted item
  52. }
  53. else {
  54. callback(null); // cancel updating the item
  55. }
  56. },
  57. onRemove: function (item, callback) {
  58. if (confirm('Remove item ' + item.content + '?')) {
  59. callback(item); // confirm deletion
  60. }
  61. else {
  62. callback(null); // cancel deletion
  63. }
  64. }
  65. };
  66. var timeline = new vis.Timeline(container, items, options);
  67. items.on('*', function (event, properties) {
  68. logEvent(event, properties);
  69. });
  70. function logEvent(event, properties) {
  71. var log = document.getElementById('log');
  72. var msg = document.createElement('div');
  73. msg.innerHTML = 'event=' + JSON.stringify(event) + ', ' +
  74. 'properties=' + JSON.stringify(properties);
  75. log.firstChild ? log.insertBefore(msg, log.firstChild) : log.appendChild(msg);
  76. }
  77. </script>
  78. </body>
  79. </html>