Timeline.stories.js 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. "use strict";
  2. var __importDefault = (this && this.__importDefault) || function (mod) {
  3. return (mod && mod.__esModule) ? mod : { "default": mod };
  4. };
  5. Object.defineProperty(exports, "__esModule", { value: true });
  6. exports.Rainbow = exports.WithEvents = exports.NestedRessource = exports.Week = exports.Generic = void 0;
  7. const Ressource_1 = __importDefault(require("../Ressource"));
  8. const Timeline_1 = __importDefault(require("../Timeline"));
  9. exports.default = {
  10. title: "Javascript/Timeline",
  11. component: "jc-timeline",
  12. argTypes: {
  13. start: {
  14. control: { type: "date" },
  15. },
  16. end: {
  17. control: { type: "date" },
  18. },
  19. },
  20. };
  21. const Template = (args) => {
  22. const t = new Timeline_1.default();
  23. t.start = args.start;
  24. t.end = args.end;
  25. if (args.legendSpan)
  26. t.legendSpan = args.legendSpan;
  27. if (args.slotduration)
  28. t.slotDuration = args.slotduration;
  29. if (args.slotWidth)
  30. t.slotWidth = args.slotWidth;
  31. if (args.legendSpan)
  32. t.legendSpan = args.legendSpan;
  33. if (args.legendFormat)
  34. t.setLegendUnitFormatAll(args.legendFormat);
  35. if (args.ressources)
  36. t.addRessources(args.ressources);
  37. if (args.events)
  38. t.addEvents(args.events);
  39. return t;
  40. };
  41. exports.Generic = Template.bind({});
  42. exports.Generic.args = {
  43. start: "2021-04-04T22:00:00.000Z",
  44. end: "2021-04-05T21:59:00.000Z",
  45. ressources: [
  46. { id: "1", title: "Ressource 1" },
  47. { id: "2", title: "Ressource 2" },
  48. ],
  49. };
  50. exports.Week = Template.bind({});
  51. exports.Week.args = {
  52. start: "2021-04-04T22:00:00.000Z",
  53. end: "2021-04-11T21:59:00.000Z",
  54. slotduration: 360,
  55. legendSpan: 4,
  56. slotWidth: 30,
  57. legendFormat: { d: "MMM D" },
  58. };
  59. exports.NestedRessource = Template.bind({});
  60. exports.NestedRessource.args = {
  61. start: "2021-04-05T05:00:00.000Z",
  62. end: "2021-04-05T17:59:00.000Z",
  63. ressources: [{ id: "2", title: "Ressource 2", parent: { id: "1", title: "Ressource 1" } }],
  64. };
  65. exports.WithEvents = Template.bind({});
  66. exports.WithEvents.args = {
  67. start: "2021-04-05T05:00:00.000Z",
  68. end: "2021-04-05T17:59:00.000Z",
  69. ressources: [
  70. { id: "1", title: "Ressource 1" },
  71. { id: "2", title: "Ressource 2" },
  72. ],
  73. events: [
  74. {
  75. id: "1",
  76. title: "Fixed ressource",
  77. ressourceId: "1",
  78. start: new Date("2021-04-05T05:00:00.000Z"),
  79. end: new Date("2021-04-05T07:59:00.000Z"),
  80. ressourceEditable: false,
  81. bgColor: "darkgreen",
  82. },
  83. {
  84. id: "2",
  85. title: "Fixed time",
  86. ressourceId: "1",
  87. start: new Date("2021-04-05T09:00:00.000Z"),
  88. end: new Date("2021-04-05T10:59:00.000Z"),
  89. editable: false,
  90. bgColor: "FireBrick",
  91. },
  92. {
  93. id: "3",
  94. ressourceId: "2",
  95. start: new Date("2021-04-05T10:00:00.000Z"),
  96. end: new Date("2021-04-05T11:59:00.000Z"),
  97. },
  98. {
  99. id: "4",
  100. ressourceId: "2",
  101. start: new Date("2021-04-05T11:00:00.000Z"),
  102. end: new Date("2021-04-05T12:59:00.000Z"),
  103. },
  104. {
  105. id: "5",
  106. ressourceId: "2",
  107. start: new Date("2021-04-05T12:00:00.000Z"),
  108. end: new Date("2021-04-05T13:59:00.000Z"),
  109. content: '<div class="bubble">0</div>',
  110. },
  111. ],
  112. };
  113. const nItem = 25;
  114. const date = new Date("2021-04-05T05:00:00.000Z").valueOf();
  115. exports.Rainbow = Template.bind({});
  116. exports.Rainbow.args = {
  117. start: "2021-04-05T05:00:00.000Z",
  118. end: "2021-04-05T17:59:00.000Z",
  119. ressources: [
  120. Array(8)
  121. .fill(0)
  122. .map((_, i) => new Ressource_1.default({ id: "" + i, title: "level " + i }))
  123. .reduce((acc, o) => {
  124. o.parent = acc;
  125. return o;
  126. }, undefined),
  127. ],
  128. events: Array(nItem)
  129. .fill(0)
  130. .map((_, i) => {
  131. return {
  132. id: "" + i,
  133. ressourceId: "" + (i % 8),
  134. title: "Item " + i,
  135. start: new Date(date + 1800000 * i),
  136. end: new Date(date + 3600000 + 1800000 * i),
  137. bgColor: "hsl(" + Math.round((i / (nItem - 1)) * 360) + ", 100%, 50%)",
  138. };
  139. }),
  140. };
  141. //# sourceMappingURL=Timeline.stories.js.map