Timeline.stories.js 3.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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: [{ id: "1", title: "Ressource 1" }, { id: "2", title: "Ressource 2" }]
  46. };
  47. exports.Week = Template.bind({});
  48. exports.Week.args = {
  49. start: "2021-04-04T22:00:00.000Z",
  50. end: "2021-04-11T21:59:00.000Z",
  51. slotduration: 360,
  52. legendSpan: 4,
  53. slotWidth: 30,
  54. legendFormat: { "d": "MMM D" }
  55. };
  56. exports.NestedRessource = Template.bind({});
  57. exports.NestedRessource.args = {
  58. start: "2021-04-05T05:00:00.000Z",
  59. end: "2021-04-05T17:59:00.000Z",
  60. ressources: [{ id: "2", title: "Ressource 2", parent: { id: "1", title: "Ressource 1" } }]
  61. };
  62. exports.WithEvents = Template.bind({});
  63. exports.WithEvents.args = {
  64. start: "2021-04-05T05:00:00.000Z",
  65. end: "2021-04-05T17:59:00.000Z",
  66. ressources: [{ id: "1", title: "Ressource 1" }, { id: "2", title: "Ressource 2" }],
  67. events: [
  68. { id: '1', title: "Fixed ressource", ressourceId: '1', start: new Date("2021-04-05T05:00:00.000Z"), end: new Date("2021-04-05T07:59:00.000Z"), ressourceEditable: false, bgColor: "darkgreen" },
  69. { id: '2', title: "Fixed time", ressourceId: '1', start: new Date("2021-04-05T09:00:00.000Z"), end: new Date("2021-04-05T10:59:00.000Z"), editable: false, bgColor: "FireBrick" },
  70. { id: '3', ressourceId: '2', start: new Date("2021-04-05T10:00:00.000Z"), end: new Date("2021-04-05T11:59:00.000Z") },
  71. { id: '4', ressourceId: '2', start: new Date("2021-04-05T11:00:00.000Z"), end: new Date("2021-04-05T12:59:00.000Z") },
  72. { id: '5', ressourceId: '2', start: new Date("2021-04-05T12:00:00.000Z"), end: new Date("2021-04-05T13:59:00.000Z") }
  73. ]
  74. };
  75. const nItem = 25;
  76. const date = (new Date("2021-04-05T05:00:00.000Z")).valueOf();
  77. exports.Rainbow = Template.bind({});
  78. exports.Rainbow.args = {
  79. start: "2021-04-05T05:00:00.000Z",
  80. end: "2021-04-05T17:59:00.000Z",
  81. ressources: [Array(8).fill(0).map((_, i) => new Ressource_1.default({ id: "" + i, title: "level " + i }))
  82. .reduce((acc, o) => { o.parent = acc; return o; }, undefined)],
  83. events: Array(nItem).fill(0).map((_, i) => {
  84. return {
  85. id: "" + i,
  86. ressourceId: "" + (i % 8),
  87. title: "Item " + i,
  88. start: new Date(date + 1800000 * i),
  89. end: new Date(date + 3600000 + 1800000 * i),
  90. bgColor: "hsl(" + Math.round(i / (nItem - 1) * 360) + ", 100%, 50%)"
  91. };
  92. })
  93. };
  94. //# sourceMappingURL=Timeline.stories.js.map