sprintify-ui 0.2.10 → 0.2.12

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (35) hide show
  1. package/dist/sprintify-ui.es.js +3731 -3727
  2. package/dist/types/src/components/BaseActionItem.vue.d.ts +27 -20
  3. package/dist/types/src/components/BaseActionItemButton.vue.d.ts +21 -28
  4. package/dist/types/src/components/BaseAddressForm.vue.d.ts +63 -50
  5. package/dist/types/src/components/BaseBadge.vue.d.ts +41 -40
  6. package/dist/types/src/components/BaseBoolean.vue.d.ts +9 -14
  7. package/dist/types/src/components/BaseCropper.vue.d.ts +42 -25
  8. package/dist/types/src/components/BaseCropperModal.vue.d.ts +18 -17
  9. package/dist/types/src/components/BaseDataIteratorSectionBox.vue.d.ts +11 -14
  10. package/dist/types/src/components/BaseDataIteratorSectionButton.vue.d.ts +12 -15
  11. package/dist/types/src/components/BaseDataIteratorSectionModal.vue.d.ts +20 -17
  12. package/dist/types/src/components/BaseDataTableRowAction.vue.d.ts +18 -15
  13. package/dist/types/src/components/BaseDatePicker.vue.d.ts +107 -74
  14. package/dist/types/src/components/BaseDraggable.vue.d.ts +35 -20
  15. package/dist/types/src/components/BaseFilePicker.vue.d.ts +43 -42
  16. package/dist/types/src/components/BaseFilePickerCrop.vue.d.ts +43 -40
  17. package/dist/types/src/components/BaseFileUploader.vue.d.ts +83 -62
  18. package/dist/types/src/components/BaseGantt.vue.d.ts +424 -0
  19. package/dist/types/src/components/BaseHeader.vue.d.ts +81 -66
  20. package/dist/types/src/components/BaseIconPicker.vue.d.ts +27 -34
  21. package/dist/types/src/components/BaseLayoutNotificationItemContent.vue.d.ts +18 -15
  22. package/dist/types/src/components/BaseSideNavigation.vue.d.ts +11 -26
  23. package/dist/types/src/components/BaseSideNavigationItem.vue.d.ts +27 -32
  24. package/dist/types/src/components/BaseTabItem.vue.d.ts +27 -32
  25. package/dist/types/src/components/BaseTabs.vue.d.ts +11 -26
  26. package/dist/types/src/services/gantt/format.d.ts +24 -0
  27. package/dist/types/src/services/gantt/timescale.d.ts +26 -0
  28. package/dist/types/src/services/gantt/types.d.ts +67 -0
  29. package/package.json +1 -1
  30. package/src/components/BaseGantt.stories.js +130 -0
  31. package/src/components/BaseGantt.vue +333 -0
  32. package/src/components/BaseNumber.vue +37 -23
  33. package/src/services/gantt/format.ts +113 -0
  34. package/src/services/gantt/timescale.ts +243 -0
  35. package/src/services/gantt/types.ts +75 -0
@@ -0,0 +1,243 @@
1
+ import { DateTime, DateTimeUnit } from "luxon";
2
+ import { Group, Scale, Tick } from "./types";
3
+
4
+ export class Timescale {
5
+
6
+ private minWidth: number;
7
+ private width: number;
8
+ private min: DateTime;
9
+ private max: DateTime;
10
+ private scale!: Scale;
11
+ private millisecondToPixel!: number;
12
+
13
+ constructor(minWidth: number, min: DateTime, max: DateTime) {
14
+ this.minWidth = minWidth;
15
+ this.width = minWidth;
16
+ this.min = min;
17
+ this.max = max;
18
+ }
19
+
20
+ public handle() {
21
+
22
+
23
+ // Scale
24
+
25
+ this.scale = this.getScale();
26
+
27
+ // Round min and max
28
+
29
+ this.min = this.min.startOf(this.scale.tick.step);
30
+ this.max = this.max.endOf(this.scale.tick.step);
31
+
32
+ // Number of ticks
33
+
34
+ const numberOfTicks = Math.ceil(this.max.diff(this.min, this.scale.tick.step).as(this.scale.tick.step));
35
+
36
+ // Find actual width
37
+ // If the width is less than the min width, use the min width to stretch the chart
38
+
39
+ const minWidth = numberOfTicks * this.scale.tick.size;
40
+
41
+ if (minWidth > this.minWidth) {
42
+ this.width = minWidth;
43
+ }
44
+
45
+ // millisecondToPixel coefficient
46
+
47
+ this.millisecondToPixel = this.getMillisecondToPixel();
48
+
49
+ // Groups
50
+
51
+ const groups = this.getGroups();
52
+
53
+ // Ticks
54
+
55
+ const ticks = this.getTicks();
56
+
57
+ // Return
58
+
59
+ return {
60
+ groups,
61
+ ticks,
62
+ width: this.width,
63
+ millisecondToPixel: this.millisecondToPixel,
64
+ min: this.min,
65
+ max: this.max,
66
+ }
67
+ }
68
+
69
+
70
+ private getMillisecondToPixel(): number {
71
+ const duration = this.getDiffFromMin(this.max);
72
+
73
+ // Millisecond to pixel coefficient
74
+
75
+ const millisecondToPixel = this.width / duration;
76
+
77
+ return millisecondToPixel;
78
+ }
79
+
80
+ private getGroups(): Group[] {
81
+ let groups = [] as Group[];
82
+
83
+ let current = this.min.startOf(this.scale.group.step);
84
+ const max = this.max.endOf(this.scale.group.step);
85
+
86
+ while (current <= max) {
87
+
88
+ const x = this.getDiffFromMin(current) * this.millisecondToPixel;
89
+
90
+ const millisecondsWidth = this.diffInMilliseconds(current.endOf(this.scale.group.step), current.startOf(this.scale.group.step));
91
+ const width = millisecondsWidth * this.millisecondToPixel;
92
+
93
+ const label = current.toFormat(this.scale.group.format);
94
+
95
+ const labelX = x + (width / 2);
96
+ const labelTextAnchor = "middle";
97
+
98
+ const group = {
99
+ date: current,
100
+ x,
101
+ width,
102
+ label,
103
+ labelX,
104
+ labelTextAnchor,
105
+ } as Group;
106
+
107
+ groups.push(group);
108
+
109
+ current = current.plus({ [this.scale.group.step]: 1 });
110
+ }
111
+
112
+ groups = this.mutateGroupsToKeepOneVisible(groups);
113
+
114
+ return groups;
115
+ }
116
+
117
+ private getTicks(): Tick[] {
118
+ const ticks = [] as Tick[];
119
+
120
+ let current = this.min.startOf(this.scale.group.step).startOf(this.scale.tick.step);
121
+ const max = this.max.endOf(this.scale.group.step).endOf(this.scale.tick.step);
122
+
123
+ while (current < max) {
124
+
125
+ const x = this.getDiffFromMin(current) * this.millisecondToPixel;
126
+
127
+ const millisecondsWidth = this.diffInMilliseconds(current.endOf(this.scale.tick.step), current.startOf(this.scale.tick.step));
128
+ const width = millisecondsWidth * this.millisecondToPixel;
129
+
130
+ const label = current.toFormat(this.scale.tick.format);
131
+
132
+ const tick = {
133
+ date: current,
134
+ x,
135
+ width,
136
+ label,
137
+ align: this.scale.tick.align,
138
+ } as Tick;
139
+
140
+ ticks.push(tick);
141
+
142
+ current = current.plus({ [this.scale.tick.step]: 1 });
143
+ }
144
+
145
+ return ticks;
146
+ }
147
+
148
+
149
+ private getDiffFromMin(date: DateTime): number {
150
+ return this.diffInMilliseconds(date, this.min);
151
+ }
152
+
153
+ private diffInMilliseconds(date1: DateTime, date2: DateTime): number {
154
+ return date1.diff(date2, "milliseconds").milliseconds;
155
+ }
156
+
157
+ private mutateGroupsToKeepOneVisible(groups: Group[]): Group[] {
158
+
159
+ const groupLabelWidth = 100;
160
+
161
+ const lastGroup = groups[groups.length - 1] ?? null;
162
+
163
+ if (
164
+ lastGroup &&
165
+ lastGroup.labelX + groupLabelWidth > this.width && // Is not visible
166
+ lastGroup.x + groupLabelWidth < this.width // Completely fits
167
+ ) {
168
+ lastGroup.labelX = this.width - 5;
169
+ lastGroup.labelTextAnchor = "end";
170
+ }
171
+
172
+ return groups;
173
+ }
174
+
175
+ private getScale(): Scale {
176
+
177
+ const scaleMonth = {
178
+ tick: {
179
+ format: "LLLL",
180
+ step: 'month' as DateTimeUnit,
181
+ size: 100,
182
+ align: "middle",
183
+ },
184
+ group: {
185
+ format: "yyyy",
186
+ step: "year" as DateTimeUnit,
187
+ }
188
+ }
189
+
190
+ const scaleWeek = {
191
+ tick: {
192
+ format: "dd",
193
+ step: 'week' as DateTimeUnit,
194
+ size: 60,
195
+ align: "start",
196
+ },
197
+ group: {
198
+ format: "LLLL yyyy",
199
+ step: "month" as DateTimeUnit,
200
+ }
201
+ }
202
+
203
+ const scaleDay = {
204
+ tick: {
205
+ format: "dd",
206
+ step: 'day' as DateTimeUnit,
207
+ size: 20,
208
+ align: "middle",
209
+ },
210
+ group: {
211
+ format: "LLLL yyyy",
212
+ step: "month" as DateTimeUnit,
213
+ }
214
+ }
215
+
216
+ const scaleHour = {
217
+ tick: {
218
+ format: "HH:mm",
219
+ step: 'hour' as DateTimeUnit,
220
+ size: 40,
221
+ align: "middle",
222
+ },
223
+ group: {
224
+ format: "yyyy-MM-dd",
225
+ step: "day" as DateTimeUnit,
226
+ }
227
+ }
228
+
229
+ if (this.max.diff(this.min, "months").months > 5) {
230
+ return scaleMonth;
231
+ }
232
+
233
+ if (this.max.diff(this.min, "months").months > 3) {
234
+ return scaleWeek;
235
+ }
236
+
237
+ if (this.max.diff(this.min, "days").days > 3) {
238
+ return scaleDay;
239
+ }
240
+
241
+ return scaleHour;
242
+ }
243
+ }
@@ -0,0 +1,75 @@
1
+ import { DateTime, DateTimeUnit } from "luxon";
2
+
3
+ export interface GanttItem {
4
+ id: number;
5
+ start: string;
6
+ end: string;
7
+ name: string;
8
+ meta?: Record<string, unknown>;
9
+ color: string;
10
+ }
11
+
12
+ export interface GanttRow {
13
+ id: number;
14
+ name: string;
15
+ meta?: Record<string, unknown>;
16
+ items: GanttItem[];
17
+ }
18
+
19
+ export interface GanttRowFormatted {
20
+ id: number;
21
+ name: string;
22
+ meta?: Record<string, unknown>;
23
+ items: GanttItemFormatted[];
24
+ }
25
+
26
+ export interface GanttItemFormatted {
27
+ id: number;
28
+ start: DateTime;
29
+ end: DateTime;
30
+ name: string;
31
+ meta?: Record<string, unknown>;
32
+ color: string;
33
+ milliseconds: number;
34
+ x: number;
35
+ y: number;
36
+ width: number;
37
+ height: number;
38
+ }
39
+
40
+ export interface FormatConfig {
41
+ rows: GanttRow[];
42
+ minWidth: number;
43
+ rowHeight: number;
44
+ rowPadding: number;
45
+ }
46
+
47
+ export interface Tick {
48
+ date: DateTime;
49
+ x: number;
50
+ width: number;
51
+ label: string;
52
+ align: "start" | "middle" | string;
53
+ }
54
+
55
+ export interface Group {
56
+ date: DateTime;
57
+ x: number;
58
+ width: number;
59
+ label: string;
60
+ labelX: number;
61
+ labelTextAnchor: "start" | "middle" | "end";
62
+ }
63
+
64
+ export interface Scale {
65
+ tick: {
66
+ step: DateTimeUnit;
67
+ format: string;
68
+ size: number;
69
+ align: "start" | "middle" | string;
70
+ };
71
+ group: {
72
+ step: DateTimeUnit;
73
+ format: string;
74
+ };
75
+ }