@visactor/vtable-gantt 1.23.3-alpha.0 → 1.24.0

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 (55) hide show
  1. package/cjs/Gantt.d.ts +18 -0
  2. package/cjs/Gantt.js +135 -9
  3. package/cjs/Gantt.js.map +1 -1
  4. package/cjs/gantt-helper.d.ts +7 -0
  5. package/cjs/gantt-helper.js +75 -66
  6. package/cjs/gantt-helper.js.map +1 -1
  7. package/cjs/index.d.ts +1 -1
  8. package/cjs/index.js +1 -1
  9. package/cjs/index.js.map +1 -1
  10. package/cjs/plugins/index.js.map +1 -1
  11. package/cjs/scenegraph/dependency-link.js +28 -38
  12. package/cjs/scenegraph/dependency-link.js.map +1 -1
  13. package/cjs/scenegraph/grid.js +8 -7
  14. package/cjs/scenegraph/grid.js.map +1 -1
  15. package/cjs/scenegraph/mark-line.js +10 -12
  16. package/cjs/scenegraph/mark-line.js.map +1 -1
  17. package/cjs/scenegraph/task-bar.d.ts +4 -1
  18. package/cjs/scenegraph/task-bar.js +73 -23
  19. package/cjs/scenegraph/task-bar.js.map +1 -1
  20. package/cjs/scenegraph/timeline-header.js +1 -4
  21. package/cjs/scenegraph/timeline-header.js.map +1 -1
  22. package/cjs/state/state-manager.js +22 -18
  23. package/cjs/state/state-manager.js.map +1 -1
  24. package/cjs/tools/isx.d.ts +1 -1
  25. package/cjs/ts-types/gantt-engine.d.ts +7 -0
  26. package/cjs/ts-types/gantt-engine.js.map +1 -1
  27. package/dist/vtable-gantt.js +1374 -694
  28. package/dist/vtable-gantt.min.js +2 -2
  29. package/es/Gantt.d.ts +18 -0
  30. package/es/Gantt.js +135 -8
  31. package/es/Gantt.js.map +1 -1
  32. package/es/gantt-helper.d.ts +7 -0
  33. package/es/gantt-helper.js +74 -63
  34. package/es/gantt-helper.js.map +1 -1
  35. package/es/index.d.ts +1 -1
  36. package/es/index.js +1 -1
  37. package/es/index.js.map +1 -1
  38. package/es/plugins/index.js.map +1 -1
  39. package/es/scenegraph/dependency-link.js +29 -27
  40. package/es/scenegraph/dependency-link.js.map +1 -1
  41. package/es/scenegraph/grid.js +6 -8
  42. package/es/scenegraph/grid.js.map +1 -1
  43. package/es/scenegraph/mark-line.js +10 -11
  44. package/es/scenegraph/mark-line.js.map +1 -1
  45. package/es/scenegraph/task-bar.d.ts +4 -1
  46. package/es/scenegraph/task-bar.js +74 -23
  47. package/es/scenegraph/task-bar.js.map +1 -1
  48. package/es/scenegraph/timeline-header.js +2 -3
  49. package/es/scenegraph/timeline-header.js.map +1 -1
  50. package/es/state/state-manager.js +22 -18
  51. package/es/state/state-manager.js.map +1 -1
  52. package/es/tools/isx.d.ts +1 -1
  53. package/es/ts-types/gantt-engine.d.ts +7 -0
  54. package/es/ts-types/gantt-engine.js.map +1 -1
  55. package/package.json +6 -6
package/cjs/Gantt.d.ts CHANGED
@@ -52,6 +52,7 @@ export declare class Gantt extends EventTarget {
52
52
  taskBarStyle: ITaskBarStyle | ((interactionArgs: TaskBarInteractionArgumentType) => ITaskBarStyle);
53
53
  taskBarMilestoneStyle: IMilestoneStyle;
54
54
  projectBarStyle: ITaskBarStyle | ((interactionArgs: TaskBarInteractionArgumentType) => ITaskBarStyle);
55
+ baselineStyle: ITaskBarStyle | ((interactionArgs: TaskBarInteractionArgumentType) => ITaskBarStyle);
55
56
  taskBarMilestoneHypotenuse: number;
56
57
  taskBarHoverStyle: ITaskBarHoverStyle;
57
58
  taskBarSelectedStyle: ITaskBarSelectedStyle;
@@ -80,6 +81,9 @@ export declare class Gantt extends EventTarget {
80
81
  startDateField: string;
81
82
  endDateField: string;
82
83
  progressField: string;
84
+ baselineStartDateField: string;
85
+ baselineEndDateField: string;
86
+ baselinePosition: 'top' | 'bottom' | 'overlap';
83
87
  minDate: Date;
84
88
  maxDate: Date;
85
89
  _minDateTime: number;
@@ -115,6 +119,10 @@ export declare class Gantt extends EventTarget {
115
119
  };
116
120
  private millisecondsPerPixel;
117
121
  zoomScaleManager?: ZoomScaleManager;
122
+ private _timelineColWidths;
123
+ private _timelineColX;
124
+ private _timelineColStartTimes;
125
+ private _timelineColEndTimes;
118
126
  recalculateTimeScale(): void;
119
127
  zoomByFactor(factor: number, keepCenter?: boolean, centerX?: number): void;
120
128
  taskTableWidth: number;
@@ -131,6 +139,10 @@ export declare class Gantt extends EventTarget {
131
139
  getContainer(): HTMLElement;
132
140
  _sortScales(): void;
133
141
  _generateTimeLineDateMap(): void;
142
+ private _rebuildTimelineColXMap;
143
+ getXByTime(time: number): number;
144
+ getDateIndexByTime(time: number): number;
145
+ getDateIndexByX(x: number): number;
134
146
  getRowHeightByIndex(index: number): number;
135
147
  getRowsHeightByIndex(startIndex: number, endIndex: number): number;
136
148
  getAllRowsHeight(): number;
@@ -149,6 +161,11 @@ export declare class Gantt extends EventTarget {
149
161
  endDate: Date;
150
162
  progress: number;
151
163
  };
164
+ getBaselineInfoByTaskListIndex(taskShowIndex: number, sub_task_index?: number | number[]): {
165
+ baselineStartDate: Date | null;
166
+ baselineEndDate: Date | null;
167
+ baselineDays: number;
168
+ };
152
169
  _updateStartDateToTaskRecord(startDate: Date, index: number, sub_task_index?: number | number[]): void;
153
170
  _updateEndDateToTaskRecord(endDate: Date, index: number, sub_task_index?: number): void;
154
171
  _updateStartEndDateToTaskRecord(startDate: Date, endDate: Date, index: number, sub_task_index?: number): void;
@@ -193,6 +210,7 @@ export declare class Gantt extends EventTarget {
193
210
  };
194
211
  parseTimeFormat(date: string): string;
195
212
  getTaskBarStyle(task_index: number, sub_task_index?: number | number[]): ITaskBarStyle;
213
+ getBaselineStyle(task_index: number, sub_task_index?: number | number[]): ITaskBarStyle;
196
214
  formatDate(date: Date | string, format: string): string;
197
215
  getCurrentMillisecondsPerPixel(): number;
198
216
  setMillisecondsPerPixel(millisecondsPerPixel: number): void;
package/cjs/Gantt.js CHANGED
@@ -28,8 +28,9 @@ class Gantt extends EventTarget_1.EventTarget {
28
28
  }
29
29
  constructor(container, options) {
30
30
  var _a, _b, _c, _d, _e, _f;
31
- super(), this.parsedOptions = {}, this.container = container, this.options = options,
32
- this.taskTableWidth = "number" == typeof (null === (_a = null == options ? void 0 : options.taskListTable) || void 0 === _a ? void 0 : _a.tableWidth) ? null === (_b = null == options ? void 0 : options.taskListTable) || void 0 === _b ? void 0 : _b.tableWidth : -1,
31
+ super(), this.parsedOptions = {}, this._timelineColWidths = [], this._timelineColX = [],
32
+ this._timelineColStartTimes = [], this._timelineColEndTimes = [], this.container = container,
33
+ this.options = options, this.taskTableWidth = "number" == typeof (null === (_a = null == options ? void 0 : options.taskListTable) || void 0 === _a ? void 0 : _a.tableWidth) ? null === (_b = null == options ? void 0 : options.taskListTable) || void 0 === _b ? void 0 : _b.tableWidth : -1,
33
34
  this.taskTableColumns = null !== (_d = null === (_c = null == options ? void 0 : options.taskListTable) || void 0 === _c ? void 0 : _c.columns) && void 0 !== _d ? _d : [],
34
35
  this.records = null !== (_e = null == options ? void 0 : options.records) && void 0 !== _e ? _e : [],
35
36
  (null === (_f = options.timelineHeader) || void 0 === _f ? void 0 : _f.zoomScale) && !1 !== options.timelineHeader.zoomScale.enabled && (this.zoomScaleManager = new zoom_scale_1.ZoomScaleManager(this, options.timelineHeader.zoomScale)),
@@ -238,6 +239,80 @@ class Gantt extends EventTarget_1.EventTarget {
238
239
  _generateTimeLineDateMap() {
239
240
  if (this.parsedOptions.minDate && this.parsedOptions.maxDate) for (const scale of this.parsedOptions.reverseSortedTimelineScales) scale.timelineDates = (0,
240
241
  gantt_helper_1.generateTimeLineDate)(new Date(this.parsedOptions.minDate), this.parsedOptions.maxDate, scale);
242
+ this._rebuildTimelineColXMap();
243
+ }
244
+ _rebuildTimelineColXMap() {
245
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o;
246
+ const minScale = null === (_a = this.parsedOptions.reverseSortedTimelineScales) || void 0 === _a ? void 0 : _a[0], timelineDates = null !== (_b = null == minScale ? void 0 : minScale.timelineDates) && void 0 !== _b ? _b : [], baseWidth = null !== (_c = this.parsedOptions.timelineColWidth) && void 0 !== _c ? _c : 0, hideWeekend = !0 === (null === (_e = null === (_d = this.options) || void 0 === _d ? void 0 : _d.timelineHeader) || void 0 === _e ? void 0 : _e.hideWeekend), weekendColWidth = null === (_g = null === (_f = this.options) || void 0 === _f ? void 0 : _f.timelineHeader) || void 0 === _g ? void 0 : _g.weekendColWidth, enableWeekendWidth = "day" === (null == minScale ? void 0 : minScale.unit) && 1 === (null == minScale ? void 0 : minScale.step) && (hideWeekend || void 0 !== weekendColWidth);
247
+ this._timelineColWidths = new Array(timelineDates.length), this._timelineColX = new Array(timelineDates.length + 1),
248
+ this._timelineColStartTimes = new Array(timelineDates.length), this._timelineColEndTimes = new Array(timelineDates.length),
249
+ this._timelineColX[0] = 0;
250
+ let sumX = 0;
251
+ for (let i = 0; i < timelineDates.length; i++) {
252
+ const d = timelineDates[i], startTime = null !== (_k = null === (_j = null === (_h = d.startDate) || void 0 === _h ? void 0 : _h.getTime) || void 0 === _j ? void 0 : _j.call(_h)) && void 0 !== _k ? _k : 0, endTime = null !== (_o = null === (_m = null === (_l = d.endDate) || void 0 === _l ? void 0 : _l.getTime) || void 0 === _m ? void 0 : _m.call(_l)) && void 0 !== _o ? _o : startTime;
253
+ this._timelineColStartTimes[i] = startTime, this._timelineColEndTimes[i] = endTime;
254
+ let w = baseWidth;
255
+ if (enableWeekendWidth) {
256
+ const day = d.startDate.getDay();
257
+ (0 === day || 6 === day) && (hideWeekend ? w = 0 : "number" == typeof weekendColWidth ? w = weekendColWidth : "function" == typeof weekendColWidth && (w = weekendColWidth(baseWidth)));
258
+ }
259
+ w = Math.max(0, Number.isFinite(w) ? w : baseWidth), this._timelineColWidths[i] = w,
260
+ sumX += w, this._timelineColX[i + 1] = sumX;
261
+ }
262
+ }
263
+ getXByTime(time) {
264
+ var _a, _b, _c, _d, _e;
265
+ const startTimes = this._timelineColStartTimes, endTimes = this._timelineColEndTimes, widths = this._timelineColWidths, xPrefix = this._timelineColX;
266
+ if (!((null == startTimes ? void 0 : startTimes.length) && (null == endTimes ? void 0 : endTimes.length) && (null == widths ? void 0 : widths.length) && (null == xPrefix ? void 0 : xPrefix.length))) return 0;
267
+ if (time <= startTimes[0]) return 0;
268
+ const lastIndex = endTimes.length - 1;
269
+ if (time > endTimes[lastIndex]) return null !== (_a = xPrefix[lastIndex + 1]) && void 0 !== _a ? _a : 0;
270
+ let low = 0, high = lastIndex;
271
+ for (;low <= high; ) {
272
+ const mid = low + high >> 1, st = startTimes[mid], et = endTimes[mid];
273
+ if (time < st) high = mid - 1; else {
274
+ if (!(time > et)) {
275
+ const offset = (time - st) / Math.max(1, et - st + 1);
276
+ return (null !== (_b = xPrefix[mid]) && void 0 !== _b ? _b : 0) + (null !== (_c = widths[mid]) && void 0 !== _c ? _c : 0) * offset;
277
+ }
278
+ low = mid + 1;
279
+ }
280
+ }
281
+ const idx = Math.max(0, Math.min(lastIndex, high)), st = startTimes[idx], et = endTimes[idx], duration = Math.max(1, et - st + 1), offset = Math.max(0, Math.min(1, (time - st) / duration));
282
+ return (null !== (_d = xPrefix[idx]) && void 0 !== _d ? _d : 0) + (null !== (_e = widths[idx]) && void 0 !== _e ? _e : 0) * offset;
283
+ }
284
+ getDateIndexByTime(time) {
285
+ const startTimes = this._timelineColStartTimes, endTimes = this._timelineColEndTimes;
286
+ if (!(null == startTimes ? void 0 : startTimes.length) || !(null == endTimes ? void 0 : endTimes.length)) return 0;
287
+ if (time <= startTimes[0]) return 0;
288
+ const lastIndex = endTimes.length - 1;
289
+ if (time > endTimes[lastIndex]) return lastIndex;
290
+ let low = 0, high = lastIndex;
291
+ for (;low <= high; ) {
292
+ const mid = low + high >> 1, st = startTimes[mid], et = endTimes[mid];
293
+ if (time < st) high = mid - 1; else {
294
+ if (!(time > et)) return mid;
295
+ low = mid + 1;
296
+ }
297
+ }
298
+ return Math.max(0, Math.min(lastIndex, high));
299
+ }
300
+ getDateIndexByX(x) {
301
+ var _a, _b, _c;
302
+ const totalX = x + this.stateManager.scroll.horizontalBarPos, xPrefix = this._timelineColX;
303
+ if (!(null == xPrefix ? void 0 : xPrefix.length)) return 0;
304
+ if (totalX <= 0) return 0;
305
+ const lastIndex = xPrefix.length - 2;
306
+ if (totalX >= (null !== (_a = xPrefix[lastIndex + 1]) && void 0 !== _a ? _a : 0)) return Math.max(0, lastIndex);
307
+ let low = 0, high = lastIndex;
308
+ for (;low <= high; ) {
309
+ const mid = low + high >> 1, left = null !== (_b = xPrefix[mid]) && void 0 !== _b ? _b : 0, right = null !== (_c = xPrefix[mid + 1]) && void 0 !== _c ? _c : left;
310
+ if (totalX < left) high = mid - 1; else {
311
+ if (!(totalX >= right)) return mid;
312
+ low = mid + 1;
313
+ }
314
+ }
315
+ return Math.max(0, Math.min(lastIndex, low));
241
316
  }
242
317
  getRowHeightByIndex(index) {
243
318
  return this.taskListTableInstance ? this.taskListTableInstance.getRowHeight(index + this.taskListTableInstance.columnHeaderLevelCount) : this.parsedOptions.rowHeight;
@@ -252,8 +327,9 @@ class Gantt extends EventTarget_1.EventTarget {
252
327
  return this.parsedOptions.timeLineHeaderRowHeights.reduce(((acc, curr, index) => !1 === this.parsedOptions.sortedTimelineScales[index].visible ? acc : acc + curr), 0);
253
328
  }
254
329
  getAllDateColsWidth() {
255
- var _a, _b;
256
- return this.parsedOptions.timelineColWidth * (null !== (_b = null === (_a = this.parsedOptions.reverseSortedTimelineScales[0].timelineDates) || void 0 === _a ? void 0 : _a.length) && void 0 !== _b ? _b : 0);
330
+ var _a, _b, _c;
331
+ const xPrefix = this._timelineColX;
332
+ return (null == xPrefix ? void 0 : xPrefix.length) ? null !== (_a = xPrefix[xPrefix.length - 1]) && void 0 !== _a ? _a : 0 : this.parsedOptions.timelineColWidth * (null !== (_c = null === (_b = this.parsedOptions.reverseSortedTimelineScales[0].timelineDates) || void 0 === _b ? void 0 : _b.length) && void 0 !== _c ? _c : 0);
257
333
  }
258
334
  getAllTaskBarsHeight() {
259
335
  return this.taskListTableInstance ? this.taskListTableInstance.getRowsHeight(this.taskListTableInstance.columnHeaderLevelCount, this.taskListTableInstance.rowCount - 1) : this.itemCount * this.parsedOptions.rowHeight;
@@ -322,6 +398,37 @@ class Gantt extends EventTarget_1.EventTarget {
322
398
  progress: progress
323
399
  };
324
400
  }
401
+ getBaselineInfoByTaskListIndex(taskShowIndex, sub_task_index) {
402
+ const taskRecord = this.getRecordByIndex(taskShowIndex, sub_task_index), baselineStartDateField = this.parsedOptions.baselineStartDateField, baselineEndDateField = this.parsedOptions.baselineEndDateField;
403
+ if (!(baselineStartDateField && baselineEndDateField && (null == taskRecord ? void 0 : taskRecord[baselineStartDateField]) && (null == taskRecord ? void 0 : taskRecord[baselineEndDateField]))) return {
404
+ baselineStartDate: null,
405
+ baselineEndDate: null,
406
+ baselineDays: 0
407
+ };
408
+ const rawBaselineStartDateTime = (0, util_1.createDateAtMidnight)(null == taskRecord ? void 0 : taskRecord[baselineStartDateField]).getTime(), rawBaselineEndDateTime = (0,
409
+ util_1.createDateAtMidnight)(null == taskRecord ? void 0 : taskRecord[baselineEndDateField]).getTime();
410
+ if (rawBaselineEndDateTime < this.parsedOptions._minDateTime || rawBaselineStartDateTime > this.parsedOptions._maxDateTime) return {
411
+ baselineStartDate: null,
412
+ baselineEndDate: null,
413
+ baselineDays: 0
414
+ };
415
+ let baselineStartDate, baselineEndDate;
416
+ if (this.parsedOptions.timeScaleIncludeHour) {
417
+ baselineStartDate = (0, util_1.createDateAtMidnight)(Math.min(Math.max(this.parsedOptions._minDateTime, rawBaselineStartDateTime), this.parsedOptions._maxDateTime));
418
+ const rawEnd = null == taskRecord ? void 0 : taskRecord[baselineEndDateField];
419
+ let hasMillisecondProvided = !1;
420
+ "string" == typeof rawEnd && (hasMillisecondProvided = /:\d{2}\.\d+/.test(rawEnd));
421
+ const shouldForceMillisecond = !hasMillisecondProvided;
422
+ baselineEndDate = (0, util_1.createDateAtLastMillisecond)(Math.max(Math.min(this.parsedOptions._maxDateTime, rawBaselineEndDateTime), this.parsedOptions._minDateTime), shouldForceMillisecond);
423
+ } else baselineStartDate = (0, util_1.createDateAtMidnight)(Math.min(Math.max(this.parsedOptions._minDateTime, rawBaselineStartDateTime), this.parsedOptions._maxDateTime), !0),
424
+ baselineEndDate = (0, util_1.createDateAtLastHour)(Math.max(Math.min(this.parsedOptions._maxDateTime, rawBaselineEndDateTime), this.parsedOptions._minDateTime), !0);
425
+ const baselineDays = (baselineEndDate.getTime() - baselineStartDate.getTime() + 1) / 864e5;
426
+ return {
427
+ baselineStartDate: baselineStartDate,
428
+ baselineEndDate: baselineEndDate,
429
+ baselineDays: baselineDays
430
+ };
431
+ }
325
432
  _updateStartDateToTaskRecord(startDate, index, sub_task_index) {
326
433
  var _a;
327
434
  const taskRecord = this.getRecordByIndex(index, sub_task_index), startDateField = this.parsedOptions.startDateField, dateFormat = null !== (_a = this.parsedOptions.dateFormat) && void 0 !== _a ? _a : (0,
@@ -473,15 +580,13 @@ class Gantt extends EventTarget_1.EventTarget {
473
580
  }
474
581
  _scrollToMarkLine() {
475
582
  if (this.parsedOptions.scrollToMarkLineDate && this.parsedOptions.minDate) {
476
- const minDate = this.parsedOptions.minDate, {unit: unit, step: step} = this.parsedOptions.reverseSortedTimelineScales[0], left = (0,
477
- util_1.computeCountToTimeScale)(this.parsedOptions.scrollToMarkLineDate, minDate, unit, step) * this.parsedOptions.timelineColWidth - this.tableNoFrameWidth / 2;
583
+ const left = this.getXByTime(this.parsedOptions.scrollToMarkLineDate.getTime()) - this.tableNoFrameWidth / 2;
478
584
  this.stateManager.setScrollLeft(left);
479
585
  }
480
586
  }
481
587
  scrollToMarkLine(date) {
482
588
  if (!date || !this.parsedOptions.minDate) return;
483
- const minDate = this.parsedOptions.minDate, {unit: unit, step: step} = this.parsedOptions.reverseSortedTimelineScales[0], left = (0,
484
- util_1.computeCountToTimeScale)(date, minDate, unit, step) * this.parsedOptions.timelineColWidth - this.tableNoFrameWidth / 2;
589
+ const left = this.getXByTime(date.getTime()) - this.tableNoFrameWidth / 2;
485
590
  this.stateManager.setScrollLeft(left);
486
591
  }
487
592
  addLink(link) {
@@ -520,9 +625,17 @@ class Gantt extends EventTarget_1.EventTarget {
520
625
  };
521
626
  }
522
627
  getDateColWidth(dateIndex) {
523
- return this.parsedOptions.timelineColWidth;
628
+ var _a;
629
+ const widths = this._timelineColWidths;
630
+ return (null == widths ? void 0 : widths.length) && dateIndex >= 0 && dateIndex < widths.length ? null !== (_a = widths[dateIndex]) && void 0 !== _a ? _a : 0 : this.parsedOptions.timelineColWidth;
524
631
  }
525
632
  getDateColsWidth(startDateIndex, endDateIndex) {
633
+ var _a, _b;
634
+ const xPrefix = this._timelineColX;
635
+ if (null == xPrefix ? void 0 : xPrefix.length) {
636
+ const start = Math.max(0, Math.min(startDateIndex, xPrefix.length - 1)), end = Math.max(0, Math.min(endDateIndex + 1, xPrefix.length - 1));
637
+ return end <= start ? 0 : (null !== (_a = xPrefix[end]) && void 0 !== _a ? _a : 0) - (null !== (_b = xPrefix[start]) && void 0 !== _b ? _b : 0);
638
+ }
526
639
  return (endDateIndex - startDateIndex + 1) * this.parsedOptions.timelineColWidth;
527
640
  }
528
641
  getDateRangeByIndex(index) {
@@ -553,6 +666,19 @@ class Gantt extends EventTarget_1.EventTarget {
553
666
  }
554
667
  return style;
555
668
  }
669
+ getBaselineStyle(task_index, sub_task_index) {
670
+ const {startDate: startDate, endDate: endDate, taskRecord: taskRecord} = this.getTaskInfoByTaskListIndex(task_index, sub_task_index), style = this.parsedOptions.baselineStyle;
671
+ if ("function" == typeof style) {
672
+ return style({
673
+ index: task_index,
674
+ startDate: startDate,
675
+ endDate: endDate,
676
+ taskRecord: taskRecord,
677
+ ganttInstance: this
678
+ });
679
+ }
680
+ return style;
681
+ }
556
682
  formatDate(date, format) {
557
683
  return (0, util_1.formatDate)(date instanceof Date ? date : new Date(date), format);
558
684
  }