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.

99 lines
3.0 KiB

  1. <!DOCTYPE HTML>
  2. <html>
  3. <head>
  4. <title>Timeline | Individual editable items</title>
  5. <style>
  6. body, html {
  7. font-family: arial, sans-serif;
  8. font-size: 11pt;
  9. }
  10. div.vis-editable,
  11. div.vis-editable.vis-selected {
  12. /* custom styling for editable items... */
  13. }
  14. div.vis-readonly,
  15. div.vis-readonly.vis-selected {
  16. /* custom styling for readonly items... */
  17. background-color: #ff4500;
  18. border-color: red;
  19. color: white;
  20. }
  21. </style>
  22. <script src="../../../dist/vis.js"></script>
  23. <link href="../../../dist/vis-timeline-graph2d.min.css" rel="stylesheet" type="text/css" />
  24. </head>
  25. <body>
  26. <p>Specify individual items to be editable or readonly. Toggle edit options and override behavior from timeline.editable</p>
  27. <div id="visualization"></div>
  28. <p>
  29. <form>
  30. Timeline.editable = {</br>
  31. <input name="add" type="checkbox" checked>add</input></br>
  32. <input name="remove" type="checkbox" checked>remove</input></br>
  33. <input name="updateGroup" type="checkbox">updateGroup</input></br>
  34. <input name="updateTime" type="checkbox" checked>updateTime</input><br>
  35. <input name="overrideItems" type="checkbox">overrideItems</input><br>
  36. }
  37. </form>
  38. </p>
  39. <script>
  40. // create a DataSet with items
  41. var items = new vis.DataSet([
  42. {id: 1, content: 'Editable', editable: true, start: '2010-08-23', group: 1},
  43. {id: 2, content: 'Editable', editable: true, start: '2010-08-23T23:00:00', group: 2},
  44. {id: 3, content: 'Read-only', editable: false, start: '2010-08-24T16:00:00', group: 1},
  45. {id: 4, content: 'Read-only', editable: false, start: '2010-08-26', end: '2010-09-02', group: 2},
  46. {id: 5, content: 'Editable', editable: true, start: '2010-08-28', group: 1},
  47. {id: 6, content: 'Read-only', editable: false, start: '2010-08-29', group: 2},
  48. {id: 7, content: 'Editable', editable: true, start: '2010-08-31', end: '2010-09-03', group: 1},
  49. {id: 8, content: 'Read-only', editable: false, start: '2010-09-04T12:00:00', group: 2},
  50. {id: 9, content: 'Default', start: '2010-09-04', group: 1},
  51. {id: 10, content: 'Default', start: '2010-08-24', group: 2}
  52. ]);
  53. var groups = [
  54. {
  55. id: 1,
  56. content: 'group 1'
  57. },
  58. {
  59. id: 2,
  60. content: 'group 2'
  61. }
  62. ]
  63. var container = document.getElementById('visualization');
  64. var options = {
  65. editable: {
  66. add: true,
  67. remove: true,
  68. updateGroup: false,
  69. updateTime: true,
  70. overrideItems: false
  71. } // default for all items
  72. };
  73. var timeline = new vis.Timeline(container, items, groups, options);
  74. var updateEditOptions = function(e){
  75. var changedOption = e.target.name;
  76. var options = { editable: { } };
  77. options.editable[changedOption] = e.target.checked;
  78. timeline.setOptions(options);
  79. };
  80. var cbs = document.getElementsByTagName("input");
  81. [].forEach.call(cbs, function(cb){
  82. cb.onchange = updateEditOptions;
  83. });
  84. </script>
  85. </body>
  86. </html>