all files / structured-elements/grid/ pdf-grid-column.js

69.01% Statements 49/71
41.67% Branches 10/24
75% Functions 12/16
69.01% Lines 49/71
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   12× 12×     690×                   222× 12×   222×                   12× 12×                 359×                                     1808×         904× 904×                         12×       12× 12×         12×       12× 12× 12×            
define(["require", "exports", "./pdf-grid-cell", "./../../graphics/fonts/pdf-string-format"], function (require, exports, pdf_grid_cell_1, pdf_string_format_1) {
    "use strict";
    Object.defineProperty(exports, "__esModule", { value: true });
    var PdfGridColumn = (function () {
        function PdfGridColumn(grid) {
            this.columnWidth = 0;
            this.grid = grid;
        }
        Object.defineProperty(PdfGridColumn.prototype, "width", {
            get: function () {
                return this.columnWidth;
            },
            set: function (value) {
                this.isCustomWidth = true;
                this.columnWidth = value;
            },
            enumerable: true,
            configurable: true
        });
        Object.defineProperty(PdfGridColumn.prototype, "format", {
            get: function () {
                if (this.stringFormat == null) {
                    this.stringFormat = new pdf_string_format_1.PdfStringFormat();
                }
                return this.stringFormat;
            },
            set: function (value) {
                this.stringFormat = value;
            },
            enumerable: true,
            configurable: true
        });
        return PdfGridColumn;
    }());
    exports.PdfGridColumn = PdfGridColumn;
    var PdfGridColumnCollection = (function () {
        function PdfGridColumnCollection(grid) {
            this.internalColumns = [];
            this.columnWidth = 0;
            this.grid = grid;
            this.internalColumns = [];
        }
        PdfGridColumnCollection.prototype.add = function (count) {
            for (var i = 0; i < count; i++) {
                this.internalColumns.push(new PdfGridColumn(this.grid));
                for (var index = 0; index < this.grid.rows.count; index++) {
                    var row = this.grid.rows.getRow(index);
                    var cell = new pdf_grid_cell_1.PdfGridCell();
                    cell.value = '';
                    row.cells.add(cell);
                }
            }
        };
        Object.defineProperty(PdfGridColumnCollection.prototype, "count", {
            get: function () {
                return this.internalColumns.length;
            },
            enumerable: true,
            configurable: true
        });
        Object.defineProperty(PdfGridColumnCollection.prototype, "width", {
            get: function () {
                if (this.columnWidth === 0) {
                    this.columnWidth = this.measureColumnsWidth();
                }
                if (this.grid.initialWidth !== 0 && this.columnWidth !== this.grid.initialWidth && !this.grid.style.allowHorizontalOverflow) {
                    this.columnWidth = this.grid.initialWidth;
                    this.grid.isPageWidth = true;
                }
                return this.columnWidth;
            },
            enumerable: true,
            configurable: true
        });
        Object.defineProperty(PdfGridColumnCollection.prototype, "columns", {
            get: function () {
                return this.internalColumns;
            },
            enumerable: true,
            configurable: true
        });
        PdfGridColumnCollection.prototype.getColumn = function (index) {
            Eif (index >= 0 && index <= this.columns.length) {
                return this.columns[index];
            }
            else {
                throw Error('can not get the column from the index: ' + index);
            }
        };
        PdfGridColumnCollection.prototype.measureColumnsWidth = function () {
            var totalWidth = 0;
            this.grid.measureColumnsWidth();
            for (var i = 0, count = this.internalColumns.length; i < count; i++) {
                totalWidth += this.internalColumns[i].width;
            }
            return totalWidth;
        };
        PdfGridColumnCollection.prototype.getDefaultWidths = function (totalWidth) {
            var widths = [];
            var summ = 0.0;
            var subFactor = this.count;
            for (var i = 0; i < this.count; i++) {
                Iif (this.grid.isPageWidth && totalWidth >= 0 && !this.internalColumns[i].isCustomWidth) {
                    this.internalColumns[i].width = 0;
                }
                else {
                    widths[i] = this.internalColumns[i].width;
                    Iif (this.internalColumns[i].width > 0 && this.internalColumns[i].isCustomWidth) {
                        totalWidth -= this.internalColumns[i].width;
                        subFactor--;
                    }
                    else {
                        widths[i] = 0;
                    }
                }
            }
            for (var i = 0; i < this.count; i++) {
                var width = totalWidth / subFactor;
                Eif (widths[i] <= 0) {
                    widths[i] = width;
                }
            }
            return widths;
        };
        return PdfGridColumnCollection;
    }());
    exports.PdfGridColumnCollection = PdfGridColumnCollection;
});