import { DateTime, Settings } from "luxon"; import { GanttViewType } from "./base"; import { GanttViewWeek } from "./week"; import { GanttViewDay } from "./day"; import { GanttViewMonth } from "./month"; import { CellDescriptor, DescriptorSet, IntervalDescriptor, TickDescriptor } from "./descriptors"; // export interface DescriptorSet { // interval: IntervalDescriptor[], // cell: IntervalDescriptor[], // tick: IntervalDescriptor[], // } // export interface IntervalDescriptor { // title: string; // subTitle?: string; // width: string, // firstTickOffset?: string, // } export class GanttView { viewType: GanttViewType; private _width: number = 0; // width of this gantt view in pixel descriptorSet: DescriptorSet = { interval: [], cell: [], tick: [], } constructor() { // defining time settings Settings.defaultZone = 'utc'; Settings.defaultLocale = "de"; // initialize view dates (as week view) this.viewType = new GanttViewWeek(DateTime.now()); } set width(width: number) { this._width = width; this.descriptorSet = this.viewType.update({ width: width }); } set globalBaseFontSize(size: number) { this.viewType.globalBaseFontSize = size; } get month(): string { return this.viewType.start.toFormat('MMMM yyyy') } get week(): string { return this.viewType.start.toFormat('nn') } get intervalDescriptor(): IntervalDescriptor[] { return this.descriptorSet.interval }; get cellDescriptors(): CellDescriptor[] { return this.descriptorSet.cell }; get tickDescriptors(): TickDescriptor[] { return this.descriptorSet.tick }; durationToWidth(seconds: number, opts?: { offsetCorrection?: number }): string { return this.viewType.durationToWidth(seconds, opts); } getOffset(date: DateTime | number, opts?: { dstCorrection?: boolean, offsetCorrection?: number }): string { return this.viewType.getOffset(date, opts); } changeView(view: string): void { switch (view) { case 'day': this.viewType = new GanttViewDay(this.viewType.start); break; case 'week': this.viewType = new GanttViewWeek(this.viewType.start); break; case 'month': this.viewType = new GanttViewMonth(this.viewType.start); break; } this.descriptorSet = this.viewType.update({ width: this._width }); } back(): void { this.descriptorSet = this.viewType.update({ action: 'back' }) } next(): void { this.descriptorSet = this.viewType.update({ action: 'next' }) } today(): void { this.viewType.setToday() this.descriptorSet = this.viewType.update({ width: this._width }); } }