Skip to content

Commit

Permalink
fix: use custom start and end #INFR-909
Browse files Browse the repository at this point in the history
  • Loading branch information
HandsomeButterball committed Aug 22, 2020
1 parent 6e95832 commit 162262c
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 23 deletions.
28 changes: 18 additions & 10 deletions packages/gantt/src/gantt-upper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -160,17 +160,25 @@ export abstract class GanttUpper {
private getViewDate() {
let start = this.start;
let end = this.end;
this.originItems.forEach((item) => {
if (item.start) {
start = start ? Math.min(start, item.start) : item.start;
}
if (item.end) {
end = end ? Math.max(end, item.end) : item.end;
}
});
if (!this.start || !this.end) {
this.originItems.forEach((item) => {
if (item.start && !this.start) {
start = start ? Math.min(start, item.start) : item.start;
}
if (item.end && !this.end) {
end = end ? Math.max(end, item.end) : item.end;
}
});
}
return {
start: new GanttDate(start),
end: new GanttDate(end)
start: {
date: new GanttDate(start),
isCustom: this.start ? true : false
},
end: {
date: new GanttDate(end),
isCustom: this.end ? true : false
}
};
}

Expand Down
4 changes: 2 additions & 2 deletions packages/gantt/src/views/day.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { GanttView, GanttViewOptions, primaryDatePointTop, secondaryDatePointTop } from './view';
import { GanttView, GanttViewOptions, primaryDatePointTop, secondaryDatePointTop, GanttViewDate } from './view';
import { GanttDate, eachWeekOfInterval, eachDayOfInterval } from '../utils/date';
import { GanttDatePoint } from '../class/date-point';

Expand All @@ -15,7 +15,7 @@ export class GanttViewDay extends GanttView {

showTimeline = false;

constructor(start: GanttDate, end: GanttDate, options?: GanttViewOptions) {
constructor(start: GanttViewDate, end: GanttViewDate, options?: GanttViewOptions) {
super(start, end, Object.assign({}, viewOptions, options));
}

Expand Down
4 changes: 2 additions & 2 deletions packages/gantt/src/views/factory.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { GanttViewOptions } from './view';
import { GanttViewOptions, GanttViewDate } from './view';
import { GanttViewMonth } from './month';
import { GanttDate } from '../utils/date';
import { GanttViewType } from '../class/view-type';
import { GanttViewQuarter } from './quarter';
import { GanttViewDay } from './day';


export function createViewFactory(type: GanttViewType, start: GanttDate, end: GanttDate, options?: GanttViewOptions) {
export function createViewFactory(type: GanttViewType, start: GanttViewDate, end: GanttViewDate, options?: GanttViewOptions) {
switch (type) {
case GanttViewType.month:
return new GanttViewMonth(start, end, options);
Expand Down
4 changes: 2 additions & 2 deletions packages/gantt/src/views/month.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { GanttView, GanttViewOptions, primaryDatePointTop, secondaryDatePointTop } from './view';
import { GanttView, GanttViewOptions, primaryDatePointTop, secondaryDatePointTop, GanttViewDate } from './view';
import { GanttDate, differenceInCalendarQuarters, eachMonthOfInterval } from '../utils/date';
import { GanttDatePoint } from '../class/date-point';

Expand All @@ -11,7 +11,7 @@ const viewOptions: GanttViewOptions = {
};

export class GanttViewMonth extends GanttView {
constructor(start: GanttDate, end: GanttDate, options?: GanttViewOptions) {
constructor(start: GanttViewDate, end: GanttViewDate, options?: GanttViewOptions) {
super(start, end, Object.assign({}, viewOptions, options));
}

Expand Down
4 changes: 2 additions & 2 deletions packages/gantt/src/views/quarter.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { GanttView, GanttViewOptions, primaryDatePointTop, secondaryDatePointTop } from './view';
import { GanttView, GanttViewOptions, primaryDatePointTop, secondaryDatePointTop, GanttViewDate } from './view';
import { GanttDate } from '../utils/date';
import { GanttDatePoint } from '../class/date-point';
import { eachYearOfInterval, differenceInCalendarQuarters } from 'date-fns';
Expand All @@ -14,7 +14,7 @@ const viewOptions: GanttViewOptions = {
};

export class GanttViewQuarter extends GanttView {
constructor(start: GanttDate, end: GanttDate, options?: GanttViewOptions) {
constructor(start: GanttViewDate, end: GanttViewDate, options?: GanttViewOptions) {
super(start, end, Object.assign({}, viewOptions, options));
}

Expand Down
19 changes: 14 additions & 5 deletions packages/gantt/src/views/view.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@ export const primaryDatePointTop = 18;

export const secondaryDatePointTop = 36;

export interface GanttViewDate {
date: GanttDate;
isCustom?: boolean;
}

export interface GanttViewOptions {
start?: GanttDate;
end?: GanttDate;
Expand Down Expand Up @@ -50,12 +55,16 @@ export abstract class GanttView {

options: GanttViewOptions;

constructor(start: GanttDate, end: GanttDate, options: GanttViewOptions) {
constructor(start: GanttViewDate, end: GanttViewDate, options: GanttViewOptions) {
this.options = Object.assign({}, viewOptions, options);
start = this.startOf(start.value < this.options.start.value ? start : this.options.start);
end = this.endOf(end.value > this.options.end.value ? end : this.options.end);
this.start$ = new BehaviorSubject<GanttDate>(start);
this.end$ = new BehaviorSubject<GanttDate>(end);
const startDate = start.isCustom
? this.startOf(start.date)
: this.startOf(start.date.value < this.options.start.value ? start.date : this.options.start);
const endDate = end.isCustom
? this.endOf(end.date)
: this.endOf(end.date.value > this.options.end.value ? end.date : this.options.end);
this.start$ = new BehaviorSubject<GanttDate>(startDate);
this.end$ = new BehaviorSubject<GanttDate>(endDate);
this.initialize();
}

Expand Down

0 comments on commit 162262c

Please sign in to comment.