Skip to content

Commit

Permalink
feat: add showTodayLine in view option (#45)
Browse files Browse the repository at this point in the history
  • Loading branch information
HandsomeButterball authored Jul 18, 2020
1 parent f432a60 commit 4ed8c3b
Show file tree
Hide file tree
Showing 9 changed files with 22 additions and 13 deletions.
1 change: 1 addition & 0 deletions packages/gantt/src/class/date-point.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ export class GanttDatePoint {
public y: number,
public additions?: {
isWeekend: boolean;
isToday: boolean;
}
) {}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<div class="gantt-calendar-today-overlay">
<div class="gantt-calendar-today-overlay" *ngIf="ganttUpper.showTodayLine">
<svg [attr.width]="view.width" height="1">
<g>
<polygon class="today-line-angle" />
Expand All @@ -15,6 +15,7 @@
*ngFor="let point of view.secondaryDatePoints; trackBy: trackBy"
class="secondary-text"
[class.secondary-text-weekend]="point.additions?.isWeekend"
[class.secondary-text-today]="point.additions?.isToday"
[attr.x]="point.x"
[attr.y]="point.y"
>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@
&-weekend {
fill: $gantt-date-secondary-weekend-color;
}
&-today {
fill: $gantt-date-today-color;
}
}

.primary-text,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ export class GanttCalendarComponent implements OnInit, AfterViewInit, OnChanges,
@HostBinding('class.gantt-calendar-overlay') className = true;

constructor(
@Inject(GANTT_UPPER_TOKEN) private ganttUpper: GanttUpper,
@Inject(GANTT_UPPER_TOKEN) public ganttUpper: GanttUpper,
private cdr: ChangeDetectorRef,
private ngZone: NgZone,
private dom: GanttDomService,
Expand Down
3 changes: 2 additions & 1 deletion packages/gantt/src/gantt-upper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ export abstract class GanttUpper {

@Input() end: number;

@Input() showTodayLine = true;

@Input() draggable: boolean;

@Input() styles: GanttStyles;
Expand Down Expand Up @@ -92,7 +94,6 @@ export abstract class GanttUpper {

private expandedItemIds: string[] = [];


@HostBinding('class.gantt') ganttClass = true;

constructor(protected elementRef: ElementRef<HTMLElement>, protected cdr: ChangeDetectorRef, protected ngZone: NgZone) {}
Expand Down
7 changes: 6 additions & 1 deletion packages/gantt/src/utils/date.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ import {
addHours,
differenceInCalendarDays,
isWeekend,
getWeek
getWeek,
isToday
} from 'date-fns';

export * from 'date-fns';
Expand Down Expand Up @@ -226,4 +227,8 @@ export class GanttDate {
isWeekend() {
return isWeekend(this.value);
}

isToday() {
return isToday(this.value);
}
}
6 changes: 3 additions & 3 deletions packages/gantt/src/views/day.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,12 @@ import { GanttView, GanttViewOptions, primaryDatePointTop, secondaryDatePointTop
import { GanttDate, eachWeekOfInterval, eachDayOfInterval } from '../utils/date';
import { GanttDatePoint } from '../class/date-point';


const viewOptions: GanttViewOptions = {
cellWidth: 35,
start: new GanttDate().startOfYear().startOfWeek({ weekStartsOn: 1 }),
end: new GanttDate().endOfYear().endOfWeek({ weekStartsOn: 1 }),
addAmount: 1,
addUnit: 'month',
addUnit: 'month'
};

export class GanttViewDay extends GanttView {
Expand All @@ -17,7 +16,7 @@ export class GanttViewDay extends GanttView {
showTimeline = false;

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

startOf(date: GanttDate) {
Expand Down Expand Up @@ -65,6 +64,7 @@ export class GanttViewDay extends GanttView {
secondaryDatePointTop,
{
isWeekend: start.isWeekend(),
isToday: start.isToday()
}
);
points.push(point);
Expand Down
5 changes: 2 additions & 3 deletions packages/gantt/src/views/month.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,17 @@ import { GanttView, GanttViewOptions, primaryDatePointTop, secondaryDatePointTop
import { GanttDate, differenceInCalendarQuarters, eachMonthOfInterval } from '../utils/date';
import { GanttDatePoint } from '../class/date-point';


const viewOptions: GanttViewOptions = {
start: new GanttDate().startOfQuarter().addQuarters(-1),
end: new GanttDate().endOfQuarter().addQuarters(2),
cellWidth: 280,
addAmount: 1,
addUnit: 'quarter',
addUnit: 'quarter'
};

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

startOf(date: GanttDate) {
Expand Down
5 changes: 2 additions & 3 deletions packages/gantt/src/views/quarter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,19 @@ import { GanttDate } from '../utils/date';
import { GanttDatePoint } from '../class/date-point';
import { eachYearOfInterval, differenceInCalendarQuarters } from 'date-fns';


const viewOptions: GanttViewOptions = {
start: new GanttDate().addYears(-1).startOfYear(),
end: new GanttDate().addYears(1).endOfYear(),
min: new GanttDate().addYears(-2).startOfYear(),
max: new GanttDate().addYears(2).endOfYear(),
cellWidth: 500,
addAmount: 1,
addUnit: 'year',
addUnit: 'year'
};

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

startOf(date: GanttDate) {
Expand Down

0 comments on commit 4ed8c3b

Please sign in to comment.