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. <script src="../../googleAnalytics.js"></script>
  25. </head>
  26. <body>
  27. <p>Specify individual items to be editable or readonly. Toggle edit options and override behavior from timeline.editable</p>
  28. <div id="visualization"></div>
  29. <p>
  30. <form>
  31. Timeline.editable = {</br>
  32. <input name="add" type="checkbox" checked>add</input></br>
  33. <input name="remove" type="checkbox" checked>remove</input></br>
  34. <input name="updateGroup" type="checkbox">updateGroup</input></br>
  35. <input name="updateTime" type="checkbox" checked>updateTime</input><br>
  36. <input name="overrideItems" type="checkbox">overrideItems</input><br>
  37. }
  38. </form>
  39. </p>
  40. <script>
  41. // create a DataSet with items
  42. var items = new vis.DataSet([
  43. {id: 1, content: 'Editable', editable: true, start: '2010-08-23', group: 1},
  44. {id: 2, content: 'Editable', editable: true, start: '2010-08-23T23:00:00', group: 2},
  45. {id: 3, content: 'Read-only', editable: false, start: '2010-08-24T16:00:00', group: 1},
  46. {id: 4, content: 'Read-only', editable: false, start: '2010-08-26', end: '2010-09-02', group: 2},
  47. {id: 5, content: 'Editable', editable: true, start: '2010-08-28', group: 1},
  48. {id: 6, content: 'Read-only', editable: false, start: '2010-08-29', group: 2},
  49. {id: 7, content: 'Editable', editable: true, start: '2010-08-31', end: '2010-09-03', group: 1},
  50. {id: 8, content: 'Read-only', editable: false, start: '2010-09-04T12:00:00', group: 2},
  51. {id: 9, content: 'Default', start: '2010-09-04', group: 1},
  52. {id: 10, content: 'Default', start: '2010-08-24', group: 2}
  53. ]);
  54. var groups = [
  55. {
  56. id: 1,
  57. content: 'group 1'
  58. },
  59. {
  60. id: 2,
  61. content: 'group 2'
  62. }
  63. ]
  64. var container = document.getElementById('visualization');
  65. var options = {
  66. editable: {
  67. add: true,
  68. remove: true,
  69. updateGroup: false,
  70. updateTime: true,
  71. overrideItems: false
  72. } // default for all items
  73. };
  74. var timeline = new vis.Timeline(container, items, groups, options);
  75. var updateEditOptions = function(e){
  76. var changedOption = e.target.name;
  77. var options = { editable: { } };
  78. options.editable[changedOption] = e.target.checked;
  79. timeline.setOptions(options);
  80. };
  81. var cbs = document.getElementsByTagName("input");
  82. [].forEach.call(cbs, function(cb){
  83. cb.onchange = updateEditOptions;
  84. });
  85. </script>
  86. </body>
  87. </html>