ng2-gantt
Version:
Angular 2 Gantt
160 lines (127 loc) • 4.79 kB
text/typescript
import { Component, OnInit, Input, ViewChild, ElementRef } from '@angular/core';
import { GanttService } from '../../shared/services/gantt.service';
import { Zooming } from '../../shared/interfaces';
export class GanttActivityBackgroundComponent implements OnInit {
tasks: any;
timeScale:any;
zoom: any;
zoomLevel: string;
bg: ElementRef;
private rows: any[] = [];
private cells: any[] = [];
constructor(private ganttService: GanttService) { }
ngOnInit() {
this.drawGrid();
this.zoom.subscribe((zoomLevel: string) => {
this.zoomLevel = zoomLevel;
this.drawGrid();
});
}
isDayWeekend(date: Date): boolean {
return this.ganttService.isDayWeekend(date);
}
private setRowStyle() {
return {
'height': this.ganttService.rowHeight + 'px'
};
}
private setCellStyle() {
var width = this.ganttService.cellWidth;
if (this.zoomLevel === Zooming[Zooming.hours]) {
width = this.ganttService.hourCellWidth;
}
return {
'width': width + 'px'
};
}
private drawGrid(): void {
if (this.zoomLevel === Zooming[Zooming.hours]) {
this.cells = [];
this.timeScale.forEach((date: any) => {
for (var i = 0; i <= 23; i++) {
this.cells.push(date);
}
});
} else {
this.cells = this.timeScale;
}
}
}
//TODO(dale): replace with either svg or canvas
// exceeding the maximum length/width/area on most browsers renders the canvas
// unusable (it will ignore any draw commands, even in the usable area)
// private drawGrid2(): void {
// this.bg.nativeElement.innerHTML = '';
// //grid width and height
// var bw = 1384; // maximum width 16384 CHROME
// var bh = 300; //this.project.tasks.length * this.ganttService.rowHeight;
// var rowHeight = this.ganttService.rowHeight;
// var cellWidth = 0;
// if (this.zoomLevel === Zooming[Zooming.hours]) {
// cellWidth = this.ganttService.hourCellWidth;
// } else {
// cellWidth = this.ganttService.cellWidth;
// }
// var canvas = document.createElement('canvas');
// canvas.setAttribute("width", bw.toString());
// canvas.setAttribute("height", bh.toString());
// var context = canvas.getContext("2d");
// var lineSpacer = 0;
// // vertical lines
// for (var x = 0; x <= bw; x += cellWidth) {
// lineSpacer += cellWidth / cellWidth;
// context.moveTo(x + lineSpacer - 1.5, 0);
// context.lineTo(x + lineSpacer - 1.5, bh);
// }
// // horizontal lines
// for (var x = 0; x <= bh; x += rowHeight) {
// context.moveTo(0, x);
// context.lineTo(bw , x);
// }
// context.strokeStyle = "#e0e0e0";
// context.stroke();
// this.bg.nativeElement.append(canvas);
// }
// var canvas = $('<canvas/>').attr({width: cw, height: ch}).appendTo('body');
// var context = canvas.get(0).getContext("2d");
// function drawBoard(){
// for (var x = 0; x <= bw; x += 40) {
// context.moveTo(0.5 + x + p, p);
// context.lineTo(0.5 + x + p, bh + p);
// }
// for (var x = 0; x <= bh; x += 40) {
// context.moveTo(p, 0.5 + x + p);
// context.lineTo(bw + p, 0.5 + x + p);
// }
// context.strokeStyle = "black";
// context.stroke();
// }
// drawBoard();