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.

80 lines
3.4 KiB

  1. <!DOCTYPE HTML>
  2. <html>
  3. <head>
  4. <title>Timeline | Subgroups</title>
  5. <script src="../../../dist/vis.js"></script>
  6. <link href="../../../dist/vis.css" rel="stylesheet" type="text/css" />
  7. <style>
  8. body, html {
  9. font-family: arial, sans-serif;
  10. font-size: 11pt;
  11. }
  12. .vis-item.vis-background.negative {
  13. background-color: rgba(255, 0, 0, 0.2);
  14. }
  15. .vis-item.vis-background.positive {
  16. background-color: rgba(105, 255, 98, 0.20);
  17. }
  18. .vis-item.vis-background.marker {
  19. border-left: 2px solid green;
  20. }
  21. </style>
  22. </head>
  23. <body>
  24. <p>This example shows the workings of the subgroups. Subgroups do not use stacking, and only work when stacking is disabled.</p>
  25. <button onclick="toggleStackSubgroups()">Toggle stackSubgroups</button>
  26. <div id="visualization"></div>
  27. <script>
  28. // create a dataset with items
  29. // we specify the type of the fields `start` and `end` here to be strings
  30. // containing an ISO date. The fields will be outputted as ISO dates
  31. // automatically getting data from the DataSet via items.get().
  32. var items = new vis.DataSet({
  33. type: { start: 'ISODate', end: 'ISODate' }
  34. });
  35. var groups = new vis.DataSet([{
  36. id: 'bar', content:'bar', subgroupOrder: function (a,b) {return a.subgroupOrder - b.subgroupOrder;}
  37. },{
  38. id: 'foo', content:'foo', subgroupOrder: 'subgroupOrder' // this group has no subgroups but this would be the other method to do the sorting.
  39. }]);
  40. // add items to the DataSet
  41. items.add([
  42. {id: 'A',start: '2014-01-20', end: '2014-01-22', type: 'background', group:'foo'},
  43. {id: 'B',start: '2014-01-22', end: '2014-01-23', type: 'background', group:'foo', className: 'negative'},
  44. {id: 0, content: 'no subgroup', start: '2014-01-20', end: '2014-01-22',group:'foo'},
  45. {id: 'SG_1_1',start: '2014-01-25', end: '2014-01-27', type: 'background', group:'bar', subgroup:'sg_1', subgroupOrder:0},
  46. {id: 'SG_1_2', start: '2014-01-26', end: '2014-01-27', type: 'background', className: 'positive',group:'bar', subgroup:'sg_1', subgroupOrder:0},
  47. {id: 1, content: 'subgroup0', start: '2014-01-23 12:00:00', end: '2014-01-26 12:00:00',group:'bar', subgroup:'sg_1', subgroupOrder:0},
  48. {id: 'SG_2_1', start: '2014-01-27', end: '2014-01-29', type: 'background', group:'bar', subgroup:'sg_2', subgroupOrder:1},
  49. {id: 'SG_2_2', start: '2014-01-27', end: '2014-01-28', type: 'background', className: 'negative',group:'bar', subgroup:'sg_2', subgroupOrder:1},
  50. {id: 2, content: 'subgroup1', start: '2014-01-27', end: '2014-01-29',group:'bar', subgroup:'sg_2', subgroupOrder:1},
  51. {id: 'background', start: '2014-01-29', end: '2014-01-30', type: 'background', className: 'negative',group:'bar'},
  52. {id: 'background_all', start: '2014-01-31', end: '2014-02-02', type: 'background', className: 'positive'},
  53. ]);
  54. var container = document.getElementById('visualization');
  55. var options = {
  56. // orientation:'top'
  57. start: '2014-01-10',
  58. end: '2014-02-10',
  59. editable: true,
  60. stack: false,
  61. stackSubgroups: true
  62. };
  63. var timeline = new vis.Timeline(container, items, groups, options);
  64. function toggleStackSubgroups() {
  65. options.stackSubgroups = !options.stackSubgroups;
  66. timeline.setOptions(options);
  67. }
  68. </script>
  69. </body>
  70. </html>