all files / export/ pdf-gantt.js

94.87% Statements 222/234
85.53% Branches 65/76
89.47% Functions 17/19
95.22% Lines 219/230
11 statements, 6 functions, 9 branches Ignored     
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317                              118× 118× 118× 118× 118× 118× 118× 118× 118× 118× 118× 118×     37298× 114×   37298×         112× 112× 112× 112× 112× 106×   112× 112× 112× 112× 112× 112× 112× 112× 112× 532×   112× 112× 79× 79× 79× 79×     33× 33× 33× 33×   112× 307× 228×     79× 79×   307× 307× 307× 307× 307× 307×   307× 307× 109× 109×     198× 198×   307× 307× 307×   72× 72×   307× 307×   307×   307×                     282× 282× 282× 282×   282× 282× 282× 282× 282× 282×       18× 18× 18× 18×   18× 18× 18×                     307× 307×     106× 106× 757× 757× 757× 757× 757×     112× 112× 112× 112× 112× 112× 112× 112× 302× 302× 302× 301× 301× 301× 301× 301× 301× 88× 88× 88×   301× 3279× 3279× 3279× 3279× 3279× 3279× 3279× 3259× 3259×   3279× 3275× 294× 294×         294× 294× 294× 294× 294× 294× 58×     236×   294× 294× 294× 294×             3275× 3275× 3275× 834× 834× 834×     297× 297× 297× 297× 297× 297× 297× 34×     263×   297× 297× 297× 297× 297×         297× 190× 190× 190×     107× 340× 340×          
/* istanbul ignore next */ 
var __extends = (this && this.__extends) || (function () {
    var extendStatics = function (d, b) {
        extendStatics = Object.setPrototypeOf ||
            ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
            function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
        return extendStatics(d, b);
    };
    return function (d, b) {
        extendStatics(d, b);
        function __() { this.constructor = d; }
        d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
    };
})();
var __assign = (this && this.__assign) || function () {
    __assign = Object.assign || function(t) {
        for (var s, i = 1, n = arguments.length; i < n; i++) {
            s = arguments[i];
            for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
                t[p] = s[p];
        }
        return t;
    };
    return __assign.apply(this, arguments);
};
define(["require", "exports", "./pdf-taskbar", "@syncfusion/ej2-base", "@syncfusion/ej2-pdf-export", "./pdf-treegrid", "./pdf-timeline", "../base/utils", "./pdf-connector-line", "./pdf-event-marker"], function (require, exports, pdf_taskbar_1, ej2_base_1, ej2_pdf_export_1, pdf_treegrid_1, pdf_timeline_1, utils_1, pdf_connector_line_1, pdf_event_marker_1) {
    "use strict";
    Object.defineProperty(exports, "__esModule", { value: true });
    var PdfGantt = (function (_super) {
        __extends(PdfGantt, _super);
        function PdfGantt(parent) {
            var _this = _super.call(this) || this;
            _this.exportProps = {};
            _this.changeCloneProjectDates = false;
            _this.parent = parent;
            _this.chartHeader = new pdf_timeline_1.PdfTimeline(_this);
            _this.eventMarker = new pdf_event_marker_1.EventMarker(parent);
            _this.predecessor = new pdf_connector_line_1.PdfGanttPredecessor(parent, _this);
            _this.headerDetails = [];
            _this.pdfPageDetail = [];
            _this.taskbarCollection = [];
            _this.predecessorCollection = [];
            return _this;
        }
        Object.defineProperty(PdfGantt.prototype, "taskbar", {
            get: function () {
                if (ej2_base_1.isNullOrUndefined(this.taskbars)) {
                    this.taskbars = new pdf_taskbar_1.PdfGanttTaskbarCollection(this.parent);
                }
                return this.taskbars;
            },
            enumerable: true,
            configurable: true
        });
        PdfGantt.prototype.drawChart = function (result) {
            this.result = result;
            this.totalPages = this.result.page.section.count;
            this.perColumnPages = this.totalPages / this.layouter.columnRanges.length;
            this.calculateRange();
            this.drawGantttChart();
            this.drawPageBorder();
        };
        PdfGantt.prototype.calculateRange = function () {
            var lastColumnRange = this.layouter.columnRanges[this.layouter.columnRanges.length - 1];
            var totalColumnWidth = 0;
            var isPageFinished = true;
            var pageWidth = 0;
            var remainWidth = 0;
            var point = 0;
            var headerWidth = utils_1.pixelToPoint(this.chartHeader.width);
            var timelineSettings = this.parent.timelineModule;
            for (var index = lastColumnRange[0]; index <= lastColumnRange[1]; index++) {
                totalColumnWidth += this.layouter.treegrid.columns.getColumn(index).width;
            }
            totalColumnWidth += 0.5;
            if (totalColumnWidth + 100 < this.result.page.getClientSize().width) {
                remainWidth = this.result.page.getClientSize().width - totalColumnWidth;
                this.chartPageIndex = this.startPageIndex = this.totalPages - this.perColumnPages;
                isPageFinished = false;
                this.startPoint = new ej2_pdf_export_1.PointF(totalColumnWidth, 0);
            }
            else {
                this.result.page.section.add();
                this.chartPageIndex = this.startPageIndex = this.totalPages;
                isPageFinished = true;
                this.startPoint = new ej2_pdf_export_1.PointF(point, 0);
            }
            while (Math.round(point) < Math.round(headerWidth)) {
                if (isPageFinished) {
                    pageWidth = this.result.page.getClientSize().width;
                }
                else {
                    pageWidth = remainWidth;
                    isPageFinished = true;
                }
                var detail = {};
                var range = [];
                var convertedWidth = utils_1.pixelToPoint(this.chartHeader.bottomTierCellWidth);
                var width = 0;
                Eif (this.chartHeader.bottomTierCellWidth !== 0) {
                    width = (Math.floor(pageWidth / convertedWidth) * convertedWidth);
                }
                range[0] = point;
                if (headerWidth - point <= width) {
                    range[1] = headerWidth;
                    detail.totalWidth = utils_1.pointToPixel(headerWidth - point);
                }
                else {
                    range[1] = point + width;
                    detail.totalWidth = utils_1.pointToPixel(width);
                }
                detail.startPoint = range[0];
                detail.endPoint = range[1];
                if (this.parent.cloneProjectStartDate.getHours() === 0 && this.parent.cloneProjectStartDate.getMinutes() === 0
                    && this.parent.cloneProjectStartDate.getSeconds() === 0) {
                    this.changeCloneProjectDates = true;
                    this.parent.cloneProjectStartDate.setHours(8);
                }
                var timelineStartDate = this.parent.dataOperation.getDateFromFormat(this.parent.timelineModule.timelineStartDate);
                var count = ej2_base_1.isNullOrUndefined(timelineSettings.customTimelineSettings.bottomTier.count) ?
                    timelineSettings.customTimelineSettings.topTier.count : timelineSettings.customTimelineSettings.bottomTier.count;
                var scheduleType = timelineSettings.customTimelineSettings.bottomTier.unit === 'None' ?
                    timelineSettings.customTimelineSettings.topTier.unit : timelineSettings.customTimelineSettings.bottomTier.unit;
                switch (scheduleType) {
                    case 'Minutes':
                        {
                            detail.startDate = new Date(timelineStartDate.getTime());
                            var sDays = Math.floor(utils_1.pointToPixel(detail.startPoint) / (this.chartHeader.bottomTierCellWidth));
                            detail.startDate.setMinutes(detail.startDate.getMinutes() + sDays * count);
                            detail.startDate.setSeconds(detail.startDate.getSeconds() + 1);
                            detail.endDate = new Date(detail.startDate.getTime());
                            var eDays = Math.floor(utils_1.pointToPixel(detail.endPoint - detail.startPoint)
                                / (this.chartHeader.bottomTierCellWidth));
                            detail.endDate.setMinutes(detail.endDate.getMinutes() + eDays * count);
                            break;
                        }
                    case 'Hour':
                        {
                            detail.startDate = new Date(timelineStartDate.getTime());
                            var sDays1 = Math.floor(utils_1.pointToPixel(detail.startPoint) / (this.chartHeader.bottomTierCellWidth));
                            detail.startDate.setHours(detail.startDate.getHours() + sDays1 * count);
                            detail.startDate.setMinutes(detail.startDate.getMinutes() + 1);
                            detail.endDate = new Date(detail.startDate.getTime());
                            var eDays1 = Math.floor(utils_1.pointToPixel(detail.endPoint - detail.startPoint)
                                / (this.chartHeader.bottomTierCellWidth));
                            detail.endDate.setHours(detail.endDate.getHours() + eDays1 * count);
                            break;
                        }
                    case 'Day':
                        {
                            detail.startDate = new Date(timelineStartDate.getTime());
                            var startDays = (Math.round(detail.startPoint / utils_1.pixelToPoint(this.chartHeader.bottomTierCellWidth)));
                            detail.startDate.setDate(detail.startDate.getDate() + startDays * count);
                            var endDays = Math.round(((detail.endPoint - detail.startPoint)
                                / utils_1.pixelToPoint(this.chartHeader.bottomTierCellWidth))) - 1;
                            var startdate = detail.startDate;
                            startdate.setHours(0, 0, 0);
                            var secondsToAdd = this.parent.workingTimeRanges[0].to * 1000;
                            detail.endDate = new Date(startdate.getTime() + secondsToAdd);
                            detail.endDate.setDate(detail.startDate.getDate() + endDays * count);
                            break;
                        }
                    case 'Week':
                        {
                            detail.startDate = new Date(timelineStartDate.getTime());
                            var startDays1 = (detail.startPoint / utils_1.pixelToPoint(this.chartHeader.bottomTierCellWidth) * 7);
                            detail.startDate.setDate(detail.startDate.getDate() + startDays1 * count);
                            var endDays1 = Math.round((detail.endPoint - detail.startPoint)
                                / utils_1.pixelToPoint(this.chartHeader.bottomTierCellWidth)) * 7 - 1;
                            detail.endDate = new Date(detail.startDate.getTime());
                            detail.endDate.setDate(detail.startDate.getDate() + endDays1 * count);
                            break;
                        }
                    case 'Month':
                        {
                            detail.startDate = new Date(timelineStartDate.getTime());
                            var startDays2 = (detail.startPoint / utils_1.pixelToPoint(this.chartHeader.bottomTierCellWidth) * 31);
                            detail.startDate.setDate(detail.startDate.getDate() + startDays2 * count);
                            var endDays2 = Math.round((detail.endPoint - detail.startPoint)
                                / utils_1.pixelToPoint(this.chartHeader.bottomTierCellWidth)) * 31 - 1;
                            detail.endDate = new Date(detail.startDate.getTime());
                            detail.endDate.setDate(detail.startDate.getDate() + endDays2 * count);
                            break;
                        }
                    case 'Year':
                        {
                            detail.startDate = new Date(timelineStartDate.getTime());
                            var startDays3 = (detail.startPoint / utils_1.pixelToPoint(this.chartHeader.bottomTierCellWidth) * 365);
                            detail.startDate.setDate(detail.startDate.getDate() + startDays3 * count);
                            var endDays3 = Math.round((detail.endPoint - detail.startPoint)
                                / utils_1.pixelToPoint(this.chartHeader.bottomTierCellWidth)) * 365 - 1;
                            detail.endDate = new Date(detail.startDate.getTime());
                            detail.endDate.setDate(detail.startDate.getDate() + endDays3 * count);
                            break;
                        }
                }
                this.headerDetails.push(detail);
                point += width;
            }
        };
        PdfGantt.prototype.drawPageBorder = function () {
            var pages = this.result.page.section.getPages();
            for (var index = 0; index < pages.length; index++) {
                var page = pages[index];
                var graphics = page.graphics;
                var pageSize = page.getClientSize();
                var pen = new ej2_pdf_export_1.PdfPen(new ej2_pdf_export_1.PdfColor(206, 206, 206));
                graphics.drawRectangle(pen, 0, 0, pageSize.width, pageSize.height);
            }
        };
        PdfGantt.prototype.drawGantttChart = function () {
            var _this = this;
            var taskbarPoint = this.startPoint;
            var pagePoint = new ej2_pdf_export_1.PointF();
            var pageStartX = 0;
            var cumulativeWidth = 0;
            var cumulativeHeight = 0;
            var pageData;
            this.headerDetails.forEach(function (detail, index) {
                var page = _this.result.page.section.getPages()[_this.startPageIndex];
                page['contentWidth'] = (_this.parent.pdfExportModule.gantt.taskbar.isAutoFit()) ? utils_1.pointToPixel(_this.headerDetails[index].endPoint - _this.headerDetails[index].startPoint) : _this.headerDetails[index].endPoint - _this.headerDetails[index].startPoint;
                _this.chartHeader.drawTimeline(page, _this.startPoint, detail);
                taskbarPoint.y = taskbarPoint.y + utils_1.pixelToPoint(_this.parent.timelineModule.isSingleTier ? 45 : 60);
                pageStartX = taskbarPoint.x;
                cumulativeHeight = utils_1.pixelToPoint(_this.parent.timelineModule.isSingleTier ? 45 : 60);
                _this.headerDetails[_this.headerDetails.indexOf(detail)].startIndex = _this.startPageIndex;
                _this.headerDetails[_this.headerDetails.indexOf(detail)].pageStartPoint = taskbarPoint;
                _this.parent.eventMarkerColloction.map(function (eventMarker) {
                    var timelimeHeight = utils_1.pixelToPoint(_this.parent.timelineModule.isSingleTier ? 45 : 60);
                    var pdfPage = _this.result.page.section.getPages()[_this.startPageIndex];
                    _this.eventMarker.drawEventMarker(pdfPage, taskbarPoint, cumulativeWidth, detail, eventMarker, timelimeHeight);
                });
                for (var i = 0; i < _this.taskbarCollection.length; i++) {
                    var task = _this.taskbarCollection[i];
                    var rowHeight = _this.rows.getRow(i + 1).height;
                    var pdfPage = _this.result.page.section.getPages()[_this.startPageIndex];
                    var graphics = pdfPage.graphics;
                    var pen = new ej2_pdf_export_1.PdfPen(new ej2_pdf_export_1.PdfColor(206, 206, 206));
                    var lineWidth = void 0;
                    if (page['contentWidth'] && (_this.parent.gridLines === 'Both' || _this.parent.gridLines === 'Horizontal')) {
                        lineWidth = _this.chartHeader.timelineWidth;
                        graphics.drawRectangle(pen, pageStartX, taskbarPoint.y, page['contentWidth'] + 0.5, rowHeight);
                    }
                    var isNextPage = task.drawTaskbar(pdfPage, taskbarPoint, detail, cumulativeWidth, rowHeight, _this.taskbarCollection[parseInt(i.toString(), 10)], lineWidth);
                    if (isNextPage) {
                        Eif (_this.enableHeader) {
                            taskbarPoint.y = utils_1.pixelToPoint(_this.parent.timelineModule.isSingleTier ? 45 : 60);
                        }
                        else {
                            taskbarPoint.y = 0;
                        }
                        _this.startPageIndex++;
                        pageData = {};
                        pageData.height = cumulativeHeight;
                        pageData.pageStartX = pageStartX;
                        pageData.startPoint = __assign({}, pagePoint);
                        if (_this.parent.pdfExportModule.gantt.taskbar.isAutoFit()) {
                            pageData.width = (detail.totalWidth);
                        }
                        else {
                            pageData.width = (detail.totalWidth);
                        }
                        _this.pdfPageDetail.push(pageData);
                        pagePoint.y += pageData.height;
                        Eif (_this.enableHeader) {
                            cumulativeHeight = _this.chartHeader.height;
                        }
                        else {
                            taskbarPoint.y = 0;
                            cumulativeHeight = 0;
                        }
                    }
                    taskbarPoint.y += rowHeight;
                    cumulativeHeight += rowHeight;
                    _this.parent.eventMarkerColloction.map(function (eventMarker) {
                        var timelimeHeight = utils_1.pixelToPoint(_this.parent.timelineModule.isSingleTier ? 45 : 60);
                        var pdfPage = _this.result.page.section.getPages()[_this.startPageIndex];
                        _this.eventMarker.drawEventMarker(pdfPage, taskbarPoint, cumulativeWidth, detail, eventMarker, timelimeHeight);
                    });
                }
                _this.headerDetails[index].endIndex = _this.startPageIndex;
                cumulativeWidth += detail.totalWidth;
                pageData = {};
                pageData.height = cumulativeHeight;
                pageData.pageStartX = pageStartX;
                pageData.startPoint = __assign({}, pagePoint);
                if (_this.parent.pdfExportModule.gantt.taskbar.isAutoFit()) {
                    pageData.width = (detail.totalWidth);
                }
                else {
                    pageData.width = utils_1.pixelToPoint(detail.totalWidth);
                }
                _this.pdfPageDetail.push(pageData);
                pagePoint.x += pageData.width;
                pagePoint.y = 0;
                Eif (_this.enableHeader) {
                    cumulativeHeight = _this.chartHeader.height;
                }
                else {
                    taskbarPoint.y = 0;
                }
                if (_this.headerDetails.indexOf(detail) !== _this.headerDetails.length - 1) {
                    _this.result.page.section.add();
                    _this.startPageIndex = _this.result.page.section.count - 1;
                    taskbarPoint = _this.startPoint = new ej2_pdf_export_1.PointF(0, 0);
                }
            });
            for (var i = 0; i < this.predecessorCollection.length; i++) {
                var predecessor = this.predecessorCollection[i];
                predecessor.drawPredecessor(this);
            }
        };
        return PdfGantt;
    }(pdf_treegrid_1.PdfTreeGrid));
    exports.PdfGantt = PdfGantt;
});