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.

112 lines
2.4 KiB

  1. <!DOCTYPE HTML>
  2. <html>
  3. <head>
  4. <title>Timeline | Nested Groups example</title>
  5. <style>
  6. body, html {
  7. font-family: arial, sans-serif;
  8. font-size: 11pt;
  9. }
  10. #visualization {
  11. box-sizing: border-box;
  12. width: 100%;
  13. height: 300px;
  14. }
  15. </style>
  16. <!-- note: moment.js must be loaded before vis.js, else vis.js uses its embedded version of moment.js -->
  17. <script src="http://cdnjs.cloudflare.com/ajax/libs/moment.js/2.8.4/moment.min.js"></script>
  18. <script src="../../../dist/vis.js"></script>
  19. <link href="../../../dist/vis.min.css" rel="stylesheet" type="text/css" />
  20. </head>
  21. <body>
  22. <p>
  23. This example demonstrate using groups. Note that a DataSet is used for both
  24. items and groups, allowing to dynamically add, update or remove both items
  25. and groups via the DataSet.
  26. </p>
  27. <div id="visualization"></div>
  28. <script>
  29. var now = moment().minutes(0).seconds(0).milliseconds(0);
  30. var itemCount = 60;
  31. // create a data set with groups
  32. var groups = new vis.DataSet();
  33. groups.add([
  34. {
  35. id: 1,
  36. content: "Lee",
  37. nestedGroups: [11,12,13]
  38. },
  39. {
  40. id: 2,
  41. content: "invisible group",
  42. visible: false
  43. },
  44. {
  45. id: 3,
  46. content: "John",
  47. nestedGroups: [14],
  48. showNested: false
  49. },
  50. {
  51. id: 4,
  52. content: "Alson"
  53. },
  54. ]);
  55. groups.add([
  56. {
  57. id: 11,
  58. content: "cook",
  59. },
  60. {
  61. id: 12,
  62. content: "shop",
  63. },
  64. {
  65. id: 13,
  66. content: "clean house",
  67. },
  68. {
  69. id: 14,
  70. content: "wash dishes",
  71. }
  72. ]);
  73. // create a dataset with items
  74. var items = new vis.DataSet();
  75. var groupIds = groups.getIds();
  76. var types = [ 'box', 'point', 'range', 'background']
  77. for (var i = 0; i < itemCount; i++) {
  78. var start = now.clone().add(Math.random() * 200, 'hours');
  79. var end = start.clone().add(2, 'hours');
  80. var randomGroupId = groupIds[Math.floor(Math.random() * groupIds.length)];
  81. var type = types[Math.floor(4 * Math.random())]
  82. items.add({
  83. id: i,
  84. group: randomGroupId,
  85. content: 'item ' + i,
  86. start: start,
  87. end: end,
  88. type: type
  89. });
  90. }
  91. // create visualization
  92. var container = document.getElementById('visualization');
  93. var options = {
  94. groupOrder: 'content' // groupOrder can be a property name or a sorting function
  95. };
  96. var timeline = new vis.Timeline(container, items, groups, options);
  97. </script>
  98. </body>
  99. </html>