Skip to content

Commit 0f88a5c

Browse files
committed
feat: support Date type for gantt start and end date
1 parent c4b04c2 commit 0f88a5c

File tree

5 files changed

+28
-26
lines changed

5 files changed

+28
-26
lines changed

example/src/app/gantt/gantt.component.ts

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -64,25 +64,25 @@ export class AppGanttExampleComponent implements OnInit, AfterViewInit {
6464
{ id: '000008', title: 'Task 8', end: 1628783999, color: '#709dc1' },
6565
{ id: '000009', title: 'Task 9', start: 1639307597, end: 1640344397 },
6666
{ id: '0000010', title: 'Task 10', start: 1609067597, end: 1617275597 },
67-
{ id: '0000011', title: 'Task 11', start: 1611918797, end: 1611918797 },
68-
{ id: '0000012', title: 'Task 12', start: 1627816397, end: 1631358797 },
69-
{ id: '0000013', title: 'Task 13', start: 1625051597, end: 1630667597, links: ['0000012'] },
70-
{ id: '0000014', title: 'Task 14', start: 1627920000, end: 1629129599 },
71-
{ id: '0000015', title: 'Task 15', start: 1633259597, end: 1639480397 },
72-
{ id: '0000016', title: 'Task 16', start: 1624965197, end: 1627211597 },
73-
{ id: '0000017', title: 'Task 17', start: 1641035597, end: 1649157197 },
74-
{ id: '0000018', title: 'Task 18', start: 1637061197, end: 1642677197 },
75-
{ id: '0000019', title: 'Task 19', start: 1637925197, end: 1646305997 },
76-
{ id: '0000020', title: 'Task 20', start: 1628334797, end: 1629889997 },
77-
{ id: '0000021', title: 'Task 21', start: 1622891597, end: 1627643597 },
78-
{ id: '0000022', title: 'Task 22', start: 1616238797, end: 1620731597 },
79-
{ id: '0000023', title: 'Task 23', start: 1626693197, end: 1630149197 },
80-
{ id: '0000024', title: 'Task 24', start: 1626174797, end: 1626952397 },
81-
{ id: '0000025', title: 'Task 25', start: 1631013197, end: 1637493197 },
82-
{ id: '0000026', title: 'Task 26', start: 1635937997, end: 1643886797 },
83-
{ id: '0000027', title: 'Task 27', start: 1637665997, end: 1644059597 },
84-
{ id: '0000028', title: 'Task 28', start: 1611400397, end: 1615547597 },
85-
{ id: '0000029', title: 'Task 29', start: 1618053197, end: 1619176397 }
67+
{ id: '0000011', title: 'Task 11', start: new Date(1611918797 * 1000), end: new Date(1611918797 * 1000) },
68+
{ id: '0000012', title: 'Task 12', start: new Date(1627816397 * 1000), end: new Date(1631358797 * 1000) },
69+
{ id: '0000013', title: 'Task 13', start: new Date(1625051597 * 1000), end: new Date(1630667597 * 1000), links: ['0000012'] },
70+
{ id: '0000014', title: 'Task 14', start: new Date(1627920000 * 1000), end: new Date(1629129599 * 1000) },
71+
{ id: '0000015', title: 'Task 15', start: new Date(1633259597 * 1000), end: new Date(1639480397 * 1000) },
72+
{ id: '0000016', title: 'Task 16', start: new Date(1624965197 * 1000), end: new Date(1627211597 * 1000) },
73+
{ id: '0000017', title: 'Task 17', start: new Date(1641035597 * 1000), end: new Date(1649157197 * 1000) },
74+
{ id: '0000018', title: 'Task 18', start: new Date(1637061197 * 1000), end: new Date(1642677197 * 1000) },
75+
{ id: '0000019', title: 'Task 19', start: new Date(1637925197 * 1000), end: new Date(1646305997 * 1000) },
76+
{ id: '0000020', title: 'Task 20', start: new Date(1628334797 * 1000), end: new Date(1629889997 * 1000) },
77+
{ id: '0000021', title: 'Task 21', start: new Date(1622891597 * 1000), end: new Date(1627643597 * 1000) },
78+
{ id: '0000022', title: 'Task 22', start: new Date(1616238797 * 1000), end: new Date(1620731597 * 1000) },
79+
{ id: '0000023', title: 'Task 23', start: new Date(1626693197 * 1000), end: new Date(1630149197 * 1000) },
80+
{ id: '0000024', title: 'Task 24', start: new Date(1626174797 * 1000), end: new Date(1626952397 * 1000) },
81+
{ id: '0000025', title: 'Task 25', start: new Date(1631013197 * 1000), end: new Date(1637493197 * 1000) },
82+
{ id: '0000026', title: 'Task 26', start: new Date(1635937997 * 1000), end: new Date(1643886797 * 1000) },
83+
{ id: '0000027', title: 'Task 27', start: new Date(1637665997 * 1000), end: new Date(1644059597 * 1000) },
84+
{ id: '0000028', title: 'Task 28', start: new Date(1611400397 * 1000), end: new Date(1615547597 * 1000) },
85+
{ id: '0000029', title: 'Task 29', start: new Date(1618053197 * 1000), end: new Date(1619176397 * 1000) }
8686
];
8787

8888
baselineItems: GanttBaselineItem[] = [];

packages/gantt/src/class/item.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ export enum GanttItemType {
2121
export interface GanttItem<T = unknown> {
2222
id: string;
2323
title: string;
24-
start?: number;
25-
end?: number;
24+
start?: number | Date;
25+
end?: number | Date;
2626
group_id?: string;
2727
links?: (GanttLink | string)[];
2828
draggable?: boolean;

packages/gantt/src/gantt-upper.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -271,10 +271,12 @@ export abstract class GanttUpper implements OnChanges, OnInit, OnDestroy {
271271
if (!this.start || !this.end) {
272272
this.originItems.forEach((item) => {
273273
if (item.start && !this.start) {
274-
start = start ? Math.min(start, item.start) : item.start;
274+
const itemStart = item.start instanceof Date ? item.start.getTime() / 1000 : item.start;
275+
start = start ? Math.min(start, itemStart) : itemStart;
275276
}
276277
if (item.end && !this.end) {
277-
end = end ? Math.max(end, item.end) : item.end;
278+
const itemEnd = item.start instanceof Date ? item.start.getTime() / 1000 : item.start;
279+
end = end ? Math.max(end, itemEnd) : itemEnd;
278280
}
279281
});
280282
}

packages/gantt/src/gantt.component.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -363,7 +363,7 @@ export class NgxGanttComponent extends GanttUpper implements OnInit, OnChanges,
363363
this.ganttRoot.scrollToToday();
364364
}
365365

366-
scrollToDate(date: number | GanttDate) {
366+
scrollToDate(date: number | Date | GanttDate) {
367367
this.ganttRoot.scrollToDate(date);
368368
}
369369

packages/gantt/src/root.component.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -181,9 +181,9 @@ export class NgxGanttRootComponent implements OnInit, OnDestroy {
181181
this.dom.scrollMainContainer(x);
182182
}
183183

184-
public scrollToDate(date: number | GanttDate) {
184+
public scrollToDate(date: number | Date | GanttDate) {
185185
let x: number;
186-
if (typeof date === 'number') {
186+
if (typeof date === 'number' || date instanceof Date) {
187187
x = this.view.getXPointByDate(new GanttDate(date));
188188
} else {
189189
x = this.view.getXPointByDate(date);

0 commit comments

Comments
 (0)