all files / chart/print-export/ export.js

91.44% Statements 203/222
82.57% Branches 180/218
94.12% Functions 16/17
91.44% Lines 203/222
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 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336   4068× 4068× 4068× 4068× 4068× 4068×   25× 25× 25×     25× 25× 24× 13×     11×       13× 13× 13× 13× 13× 13× 13× 13× 13× 13×           13× 13× 13× 13×       13×   13× 13×   12× 12× 12×   12× 12× 12× 48×   12× 12× 12× 12×                                     13× 13× 23× 23×   22×   21×   17×   15×     13×   12×                   22×   12×         22×   13× 13× 23×   13×   12× 12× 12× 12× 12×   12× 13×     13× 13× 13× 13× 13× 26× 26×         19× 12× 12×   19× 19× 19× 19× 16× 20× 20×       14×       14×           19×   19×   13× 12×       12× 11× 11×   12×   12×     12×   12× 12× 13× 13× 13× 26× 26×         19× 438×     438×         13×   12× 13× 438×     12× 13×   12×   12× 12× 12× 13× 13× 389× 389× 389× 389× 503× 503×       46×   457× 457× 457× 41952×     41952× 438× 438× 438× 2110× 2110×     2110×       2110×   438×   438× 438× 438×     457× 19×     389× 389×   13×       45399×          
define(["require", "exports", "../../common/utils/export", "../../common/model/constants", "@syncfusion/ej2-excel-export"], function (require, exports, export_1, constants_1, ej2_excel_export_1) {
    "use strict";
    Object.defineProperty(exports, "__esModule", { value: true });
    var Export = (function () {
        function Export(chart) {
            this.actualRowCount = 0;
            this.series = [];
            this.axisCollection = [];
            this.requiredValuesLength = 0;
            this.histogramSeriesCount = 0;
            this.chart = chart;
        }
        Export.prototype.export = function (type, fileName, orientation, controls, width, height, isVertical, header, footer, exportToMultiplePage) {
            var exportChart = new export_1.ExportUtils(this.chart);
            controls = controls ? controls : [this.chart];
            var argsData = {
                cancel: false, name: constants_1.beforeExport, width: width, height: height
            };
            this.chart.trigger(constants_1.beforeExport, argsData);
            if (!argsData.cancel) {
                if (type === 'CSV' || type === 'XLSX') {
                    this.excelExport(controls, fileName, type);
                }
                else {
                    exportChart.export(type, fileName, orientation, controls, width = argsData.width, height = argsData.height, isVertical, header, footer, exportToMultiplePage);
                }
            }
        };
        Export.prototype.excelExport = function (controls, fileName, type) {
            this.rows = [];
            this.actualRowCount = 1;
            var workSheets = [];
            var requiredValues = [];
            var headerStyle = { bold: true, hAlign: 'Center', vAlign: 'Center', wrapText: true };
            var xValues = [];
            var isRangeNavigator = controls[0].getModuleName() === 'rangeNavigator';
            var isAccumulation = controls[0].getModuleName() === 'accumulationchart';
            this.series = isRangeNavigator ? controls[0].series : controls[0].visibleSeries;
            Iif (isRangeNavigator && this.series.length === 0) {
                if (controls[0].dataSource) {
                    this.createRangeNavigatorExcelSheet(controls[0], headerStyle, type);
                }
            }
            else {
                this.histogramSeriesCount = 0;
                this.requiredValuesLength = 0;
                this.axisCollection = [];
                Iif (isAccumulation || isRangeNavigator) {
                    this.axisCollection.push(null);
                }
                else {
                    this.axisCollection = controls[0].getModuleName() === 'stockChart' ? controls[0].chart.horizontalAxes : controls[0].horizontalAxes;
                }
                requiredValues = this.getRequiredValues(isRangeNavigator);
                if (this.requiredValuesLength === 0 && this.series.length === this.histogramSeriesCount) {
                    return;
                }
                xValues = this.getXValue(requiredValues, controls, isRangeNavigator, isAccumulation);
                this.getTitle(requiredValues, headerStyle, controls, isRangeNavigator, isAccumulation, type, xValues[0].length);
                this.createExcelSheet(isRangeNavigator, isAccumulation, xValues, type, requiredValues, headerStyle, controls);
            }
            var columns = [];
            this.requiredValuesLength = this.requiredValuesLength === 0 ? 1 : this.requiredValuesLength;
            for (var columnCount = 0; columnCount < this.requiredValuesLength; columnCount++) {
                columns.push({ index: columnCount + 1, width: 100 });
            }
            workSheets.push({ columns: columns, rows: this.rows });
            var book = new ej2_excel_export_1.Workbook({ worksheets: workSheets }, type === 'XLSX' ? 'xlsx' : 'csv');
            fileName = fileName ? fileName : type === 'XLSX' ? 'XLSX' : 'CSV';
            book.save(fileName + (type === 'XLSX' ? '.xlsx' : '.csv'));
        };
        Export.prototype.createRangeNavigatorExcelSheet = function (controls, headerStyle, type) {
            var xName = controls.xName;
            var yName = controls.yName;
            this.rows.push({
                index: this.actualRowCount, cells: [{ index: 1, value: controls.valueType.indexOf('DateTime') > -1 ? controls.valueType : 'Category', colSpan: 1, rowSpan: 1,
                        style: headerStyle },
                    { index: 2, value: yName, colSpan: 1, rowSpan: 1, style: headerStyle }]
            });
            this.actualRowCount++;
            var dataSource = controls.dataSource;
            for (var dataCount = 0; dataCount < dataSource.length; dataCount++) {
                this.rows.push({ index: this.actualRowCount, cells: [{ index: 1, value: (type === 'CSV' && dataSource[dataCount][xName] === null) ? '' :
                                dataSource[dataCount][xName], colSpan: 1, rowSpan: 1, style: headerStyle },
                        { index: 2, value: (type === 'CSV' && dataSource[dataCount][yName] === null) ? '' : dataSource[dataCount][yName], colSpan: 1, rowSpan: 1, style: {} }] });
                this.actualRowCount++;
            }
            this.requiredValuesLength = 2;
        };
        Export.prototype.getRequiredValues = function (isRangeNavigator) {
            var requiredValues = [];
            var _loop_1 = function (seriesCount) {
                var seriesType = this_1.series[seriesCount].type;
                if ((!isRangeNavigator && !this_1.series[seriesCount].visible) || this_1.series[seriesCount].category === 'TrendLine') {
                    requiredValues.push([]);
                    return "continue";
                }
                if (seriesType === 'Histogram') {
                    requiredValues.push([]);
                    this_1.histogramSeriesCount++;
                }
                else if (this_1.series[seriesCount].category === 'Pareto') {
                    requiredValues.push([this_1.series[seriesCount]['xName'], 'y']);
                }
                else if (seriesType.indexOf('Range') !== -1 || seriesType === 'Hilo') {
                    requiredValues.push([this_1.series[seriesCount]['xName'], this_1.series[seriesCount]['high'], this_1.series[seriesCount]['low']]);
                }
                else if (seriesType === 'HiloOpenClose' || seriesType === 'Candle') {
                    requiredValues.push([this_1.series[seriesCount]['xName'], this_1.series[seriesCount]['high'], this_1.series[seriesCount]['low'], this_1.series[seriesCount]['open'], this_1.series[seriesCount]['close']]);
                    if (seriesType === 'Candle' && this_1.series[seriesCount]['volume'] !== '') {
                        requiredValues[seriesCount].push(this_1.series[seriesCount]['volume']);
                    }
                }
                else if (seriesType === 'BoxAndWhisker') {
                    requiredValues.push([this_1.series[seriesCount]['xName'], 'maximum', 'upperQuartile', 'median', 'lowerQuartile', 'minimum', 'outliers']);
                }
                else if (seriesType === 'Bubble') {
                    requiredValues.push([this_1.series[seriesCount]['xName'], this_1.series[seriesCount]['yName']]);
                    Eif (this_1.series[seriesCount]['size'] !== '') {
                        requiredValues[seriesCount].push(this_1.series[seriesCount]['size']);
                    }
                }
                else Iif (seriesType === 'Pie') {
                    requiredValues.push([this_1.series[seriesCount]['xName'], this_1.series[seriesCount]['yName']]);
                    if (this_1.series[seriesCount]['radius'].match(/[a-zA-Z]/)) {
                        requiredValues[seriesCount].push(this_1.series[seriesCount]['radius']);
                    }
                }
                else {
                    requiredValues.push([this_1.series[seriesCount]['xName'], this_1.series[seriesCount]['yName']]);
                }
                if (this_1.series[seriesCount].errorBar &&
                    this_1.series[seriesCount].errorBar.visible) {
                    var errorBar_1 = this_1.series[seriesCount].errorBar;
                    var errorTypes = ['verticalError', 'horizontalError', 'verticalNegativeError', 'horizontalNegativeError', 'verticalPositiveError', 'horizontalPositiveError'];
                    errorTypes.forEach(function (errorType) {
                        Iif (typeof errorBar_1[errorType] === 'string') {
                            requiredValues[seriesCount].push(errorBar_1[errorType]);
                        }
                    });
                }
                this_1.requiredValuesLength += requiredValues[seriesCount].length;
            };
            var this_1 = this;
            for (var seriesCount = 0; seriesCount < this.series.length; seriesCount++) {
                _loop_1(seriesCount);
            }
            return requiredValues;
        };
        Export.prototype.getTitle = function (requiredValues, headerStyle, controls, isRangeNavigator, isAccumulation, type, xValueLength) {
            var cells = [];
            var additionalCells = [];
            var index = 1;
            var isTitle = false;
            if (!isRangeNavigator && type === 'XLSX' && controls[0].title) {
                this.rows.push({});
                this.actualRowCount++;
                isTitle = true;
            }
            for (var axisCount = 0; axisCount < this.axisCollection.length; axisCount++) {
                Iif (isAccumulation && xValueLength === 0) {
                    break;
                }
                var isYName = false;
                var valueType = '';
                var currentIndex = index;
                var isXValue = false;
                for (var seriesCount = 0; seriesCount < this.series.length; seriesCount++) {
                    var axisName = this.axisCollection[axisCount] !== null ? (this.axisCollection[axisCount].name === 'primaryXAxis' || (this.axisCollection[axisCount].name === 'primaryYAxis' && this.series[seriesCount].type.indexOf('Bar') > -1)) ? null : this.axisCollection[axisCount].name : '';
                    if (!isRangeNavigator && ((!isAccumulation && (axisName !==
                        this.series[seriesCount].xAxisName)) ||
                        !this.series[seriesCount].visible ||
                        this.series[seriesCount].category === 'TrendLine' || this.series[seriesCount].type === 'Histogram')) {
                        continue;
                    }
                    if (!isXValue) {
                        cells.push({});
                        index++;
                    }
                    isXValue = true;
                    var seriesName = this.series[seriesCount].name;
                    var requiredValuesLength = this.series[seriesCount].type === 'BoxAndWhisker' ? requiredValues[seriesCount].length - 1 : requiredValues[seriesCount].length;
                    if (requiredValues[seriesCount][1] === this.series[seriesCount].yName) {
                        for (var requiredValuesCount = 1; requiredValuesCount < requiredValuesLength; requiredValuesCount++) {
                            cells.push({ index: index, value: (requiredValuesCount === 1 ? seriesName ? seriesName : 'Series-' + (seriesCount + 1) : requiredValues[seriesCount][requiredValuesCount]), colSpan: 1, rowSpan: 1, style: headerStyle });
                            index++;
                        }
                    }
                    else {
                        cells.push({ index: index, value: seriesName ? seriesName : 'Series-' + (seriesCount + 1), colSpan: requiredValuesLength - 1, rowSpan: 1, style: headerStyle });
                        var localIndex = index;
                        for (var requiredValuesCount = 1; requiredValuesCount < requiredValuesLength; requiredValuesCount++) {
                            additionalCells.push({
                                index: localIndex, value: requiredValues[seriesCount][requiredValuesCount],
                                colSpan: 1, rowSpan: 1, style: headerStyle
                            });
                            localIndex++;
                        }
                        if (this.series[seriesCount].type === 'BoxAndWhisker') {
                            cells.push({ index: localIndex, value: requiredValues[seriesCount][requiredValuesLength],
                                colSpan: 1, rowSpan: 2, style: headerStyle
                            });
                            localIndex++;
                        }
                        index = localIndex;
                        isYName = true;
                    }
                    valueType = isAccumulation ? requiredValues[0][0] : isRangeNavigator ? controls[0].valueType :
                        this.axisCollection[axisCount].valueType;
                    valueType = (isAccumulation || valueType.indexOf('DateTime') > -1) ? valueType : 'Category';
                }
                if (isXValue) {
                    cells[(currentIndex - 1)] = { index: currentIndex, value: valueType, colSpan: 1,
                        rowSpan: isYName ? 2 : 1, style: headerStyle };
                }
            }
            if (cells.length) {
                this.rows.push({ index: this.actualRowCount, cells: cells });
                this.actualRowCount++;
            }
            if (additionalCells.length) {
                this.rows.push({ index: this.actualRowCount, cells: additionalCells });
                this.actualRowCount++;
            }
            if (isTitle) {
                cells = [];
                cells.push({ index: 1, value: controls[0].title,
                    colSpan: (index === 1 ? index : index - 1), rowSpan: 1, style: headerStyle });
                this.rows[0] = ({ index: 1, cells: cells });
            }
            this.requiredValuesLength = index - 1;
        };
        Export.prototype.getXValue = function (requiredValues, controls, isRangeNavigator, isAccumulation) {
            var xValues = [];
            for (var axisCount = 0; axisCount < this.axisCollection.length; axisCount++) {
                var xValue = [];
                var valueType = isAccumulation ? '' : isRangeNavigator ? controls[0].valueType : this.axisCollection[axisCount].valueType;
                for (var seriesCount = 0; seriesCount < this.series.length; seriesCount++) {
                    var axisName = this.axisCollection[axisCount] !== null ? (this.axisCollection[axisCount].name === 'primaryXAxis' || (this.axisCollection[axisCount].name === 'primaryYAxis' && this.series[seriesCount].type.indexOf('Bar') > -1)) ? null : this.axisCollection[axisCount].name : '';
                    if ((!isRangeNavigator && ((!isAccumulation && (axisName !==
                        this.series[seriesCount].xAxisName)) ||
                        !this.series[seriesCount].visible) ||
                        this.series[seriesCount].category === 'TrendLine' || this.series[seriesCount].type === 'Histogram')) {
                        continue;
                    }
                    for (var dataCount = 0; dataCount < this.series[seriesCount].dataSource.length; dataCount++) {
                        Iif (isAccumulation && !this.series[seriesCount].points[dataCount].visible) {
                            continue;
                        }
                        xValue.push((valueType.indexOf('DateTime') > -1) ? new Date(this.series[seriesCount].
                            dataSource[dataCount][requiredValues[seriesCount][0]]).getTime() :
                            this.series[seriesCount].dataSource[dataCount][requiredValues[seriesCount][0]]);
                    }
                }
                xValues.push(xValue);
            }
            var _loop_2 = function (xValuesLength) {
                xValues[xValuesLength] = xValues[xValuesLength].filter(function (item, index) {
                    return xValues[xValuesLength].indexOf(item) === index;
                });
            };
            for (var xValuesLength = 0; xValuesLength < xValues.length; xValuesLength++) {
                _loop_2(xValuesLength);
            }
            return (xValues);
        };
        Export.prototype.createExcelSheet = function (isRangeNavigator, isAccumulation, xValues, type, requiredValues, headerStyle, controls) {
            var startIndex = 0;
            var index = 0;
            for (var axisCount = 0; axisCount < this.axisCollection.length; axisCount++) {
                var valueType = isAccumulation ? '' : isRangeNavigator ? controls[0].valueType : this.axisCollection[axisCount].valueType;
                for (var xValueLength = 0; xValueLength < xValues[axisCount].length; xValueLength++) {
                    index = startIndex ? startIndex : 1;
                    var cells = [];
                    var isXValue = true;
                    for (var seriesCount = 0; seriesCount < this.series.length; seriesCount++) {
                        var axisName = this.axisCollection[axisCount] !== null ? (this.axisCollection[axisCount].name === 'primaryXAxis' || (this.axisCollection[axisCount].name === 'primaryYAxis' && this.series[seriesCount].type.indexOf('Bar') > -1)) ? null : this.axisCollection[axisCount].name : '';
                        if ((!isRangeNavigator && ((!isAccumulation &&
                            this.series[seriesCount].xAxisName !== axisName) ||
                            !this.series[seriesCount].visible) ||
                            this.series[seriesCount].category === 'TrendLine' || this.series[seriesCount].type === 'Histogram')) {
                            continue;
                        }
                        var isExist = false;
                        var dataSource = this.series[seriesCount].dataSource;
                        for (var dataCount = 0; dataCount < dataSource.length; dataCount++) {
                            var xValue = (valueType.indexOf('DateTime') > -1) ? this.series[seriesCount].category === 'Pareto' ? new Date(this.series[seriesCount].points[dataCount][requiredValues[seriesCount][0]]).getTime() :
                                new Date(dataSource[dataCount][requiredValues[seriesCount][0]]).getTime() :
                                this.series[seriesCount].category === 'Pareto' ? this.series[seriesCount].points[dataCount][requiredValues[seriesCount][0]] : dataSource[dataCount][requiredValues[seriesCount][0]];
                            if (xValues[axisCount][xValueLength] === xValue) {
                                var usedValueCount = isXValue ? 0 : 1;
                                var usedValueLength = this.series[seriesCount].type === 'BoxAndWhisker' ? requiredValues[seriesCount].length - 1 : requiredValues[seriesCount].length;
                                for (; usedValueCount < usedValueLength; usedValueCount++) {
                                    var value = (usedValueCount !== 0 && (this.series[seriesCount].type === 'BoxAndWhisker' || this.series[seriesCount].category === 'Pareto')) ? this.series[seriesCount].points[dataCount][requiredValues[seriesCount][usedValueCount]] : dataSource[dataCount][requiredValues[seriesCount][usedValueCount]];
                                    Iif (value === null && type === 'CSV') {
                                        value = '';
                                    }
                                    cells.push({
                                        index: (usedValueCount === 0 ? startIndex === 0 ? 1 : startIndex : index), value: value,
                                        colSpan: 1, rowSpan: 1, style: usedValueCount === 0 ? headerStyle : {}
                                    });
                                    index++;
                                }
                                if (this.series[seriesCount].type === 'BoxAndWhisker') {
                                    cells.push({ index: index, value: this.series[seriesCount].points[dataCount]['outliers'][0], colSpan: 1, rowSpan: 1, style: {} });
                                    index++;
                                }
                                isXValue = false;
                                isExist = true;
                                break;
                            }
                        }
                        if (!isExist) {
                            index += (requiredValues[seriesCount].length - 1);
                        }
                    }
                    this.rows.push({ index: this.actualRowCount, cells: cells });
                    this.actualRowCount++;
                }
                startIndex = index;
            }
        };
        Export.prototype.getDataUrl = function (chart) {
            var exportUtil = new export_1.ExportUtils(chart);
            return exportUtil.getDataUrl(chart);
        };
        Export.prototype.getModuleName = function () {
            return 'Export';
        };
        Export.prototype.destroy = function () {
        };
        return Export;
    }());
    exports.Export = Export;
});