all files / heatmap/datasource/ twodimensional.js

98.48% Statements 130/132
95.31% Branches 122/128
100% Functions 12/12
98.47% Lines 129/131
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   267×   313× 313× 313× 313× 313× 313× 313× 313× 313× 313× 313× 313× 313× 313× 313× 313× 313× 313× 313× 313× 313× 313×     313× 3434× 3434× 3434× 21819× 21809×   21819×   3434× 10× 10× 50×           3424×   3434× 3434×   15× 15×   3434× 3434× 3434× 748×   3434× 3427×   3434×   313×     313×     313× 260× 260×   313× 313× 313× 313× 313×   313×     21809× 576×   141× 141× 282× 10×   282× 141×   141× 141× 141×     141×     435×     389× 389×     46×         21233×     20833× 32×   31×           20801×       400×       3434× 3434× 149×   149× 149× 149× 149×     3285× 3285×   3434×   3583× 456×   3127× 186×   2941×   12×   3583×   3583× 318×   3265× 1592×   1673×   13×   3583×   43344×   26122×   262× 262× 262× 262×        
define(["require", "exports", "@syncfusion/ej2-base"], function (require, exports, ej2_base_1) {
    "use strict";
    Object.defineProperty(exports, "__esModule", { value: true });
    var TwoDimensional = (function () {
        function TwoDimensional(heatMap) {
            this.heatMap = heatMap;
        }
        TwoDimensional.prototype.processDataSource = function (dataSource) {
            var tempCloneData = ej2_base_1.extend([], dataSource, null, true);
            this.heatMap.clonedDataSource = [];
            this.completeDataSource = [];
            var axis = this.heatMap.axisCollections;
            var dataLength = axis[0].maxLength + 1;
            var labelLength = axis[0].axisLabelSize + (axis[0].min > 0 ? axis[0].min : 0);
            var xLength = dataLength > labelLength ? dataLength : labelLength;
            var minVal;
            var maxVal;
            dataLength = axis[1].maxLength + 1;
            labelLength = axis[1].axisLabelSize + (axis[1].min > 0 ? axis[1].min : 0);
            var yLength = dataLength > labelLength ? dataLength : labelLength;
            var tempVariable;
            var cloneDataIndex = 0;
            var minMaxDatasource = [];
            this.tempSizeArray = [];
            this.tempColorArray = [];
            this.heatMap.minColorValue = null;
            this.heatMap.maxColorValue = null;
            this.heatMap.dataMax = [];
            this.heatMap.dataMin = [];
            Iif (this.heatMap.paletteSettings.colorGradientMode === 'Column' && xLength < yLength) {
                xLength = yLength;
            }
            for (var z = axis[1].valueType === 'Category' ? axis[1].min : 0; z < (this.heatMap.paletteSettings.colorGradientMode === 'Column' ? xLength : yLength); z++) {
                var tempIndex = axis[0].valueType === 'Category' ? axis[0].min : 0;
                this.completeDataSource.push([]);
                while (tempIndex < xLength) {
                    if (tempIndex >= axis[0].min && tempIndex <= axis[0].max) {
                        this.processDataArray(tempCloneData, tempIndex, z, cloneDataIndex);
                    }
                    tempIndex++;
                }
                if (this.heatMap.paletteSettings.colorGradientMode === 'Column' && this.heatMap.paletteSettings.type === 'Gradient') {
                    tempVariable = ej2_base_1.extend([], tempCloneData[cloneDataIndex], null, true);
                    for (var i = 0; i < tempVariable.length; i++) {
                        Iif (typeof (tempVariable[i]) === 'object' && (tempVariable[i]) !== null || undefined || '') {
                            tempVariable[i] = tempVariable[i][0];
                        }
                    }
                }
                else {
                    tempVariable = ej2_base_1.extend([], this.completeDataSource[cloneDataIndex], null, true);
                }
                var minMaxVal = this.getMinMaxValue(minVal, maxVal, tempVariable);
                if ((this.heatMap.paletteSettings.colorGradientMode === 'Column' ||
                    this.heatMap.paletteSettings.colorGradientMode === 'Row') && this.heatMap.paletteSettings.type === 'Gradient') {
                    this.heatMap.dataMax[z] = minMaxVal[1];
                    this.heatMap.dataMin[z] = minMaxVal[0];
                }
                minVal = minMaxVal[0];
                maxVal = minMaxVal[1];
                if (this.heatMap.xAxis.isInversed) {
                    this.completeDataSource[cloneDataIndex] = this.completeDataSource[cloneDataIndex].reverse();
                }
                if (z >= this.heatMap.axisCollections[1].min && z <= this.heatMap.axisCollections[1].max) {
                    minMaxDatasource.push(this.completeDataSource[cloneDataIndex]);
                }
                cloneDataIndex++;
            }
            if (this.heatMap.paletteSettings.colorGradientMode === 'Row' && !this.heatMap.yAxis.isInversed &&
                this.heatMap.paletteSettings.type === 'Gradient') {
                this.heatMap.dataMax = this.heatMap.dataMax.reverse();
                this.heatMap.dataMin = this.heatMap.dataMin.reverse();
            }
            if (this.heatMap.paletteSettings.colorGradientMode === 'Column' && this.heatMap.xAxis.isInversed &&
                this.heatMap.paletteSettings.type === 'Gradient') {
                this.heatMap.dataMax = this.heatMap.dataMax.reverse();
                this.heatMap.dataMin = this.heatMap.dataMin.reverse();
            }
            if (!this.heatMap.yAxis.isInversed) {
                this.completeDataSource.reverse();
                minMaxDatasource.reverse();
            }
            this.heatMap.clonedDataSource = minMaxDatasource;
            this.heatMap.dataSourceMinValue = ej2_base_1.isNullOrUndefined(minVal) ? 0 : parseFloat(minVal.toString());
            this.heatMap.dataSourceMaxValue = ej2_base_1.isNullOrUndefined(maxVal) ? 0 : parseFloat(maxVal.toString());
            this.heatMap.isColorValueExist = ej2_base_1.isNullOrUndefined(this.heatMap.minColorValue) ? false : true;
            this.heatMap.minColorValue = ej2_base_1.isNullOrUndefined(this.heatMap.minColorValue) ?
                this.heatMap.dataSourceMinValue : parseFloat(this.heatMap.minColorValue.toString());
            this.heatMap.maxColorValue = ej2_base_1.isNullOrUndefined(this.heatMap.maxColorValue) ?
                this.heatMap.dataSourceMaxValue : parseFloat(this.heatMap.maxColorValue.toString());
        };
        TwoDimensional.prototype.processDataArray = function (tempCloneData, tempIndex, z, cloneDataIndex) {
            if (this.heatMap.bubbleSizeWithColor) {
                if (tempCloneData[tempIndex] && !ej2_base_1.isNullOrUndefined(tempCloneData[tempIndex][z])
                    && typeof (tempCloneData[tempIndex][z]) === 'object') {
                    var internalArray = tempCloneData[tempIndex][z];
                    for (var tempx = 0; tempx < internalArray.length; tempx++) {
                        if (ej2_base_1.isNullOrUndefined(internalArray[tempx]) || isNaN(internalArray[tempx])) {
                            internalArray[tempx] = '';
                        }
                        if (tempx === 0) {
                            this.tempSizeArray.push(internalArray[tempx]);
                        }
                        else Eif (tempx === 1) {
                            this.tempColorArray.push(internalArray[tempx]);
                            break;
                        }
                    }
                    this.completeDataSource[cloneDataIndex].push(internalArray);
                }
                else {
                    if (!ej2_base_1.isNullOrUndefined(tempCloneData[tempIndex]) && (tempCloneData[tempIndex][z] ||
                        (tempCloneData[tempIndex][z] === 0 &&
                            tempCloneData[tempIndex][z].toString() !== ''))) {
                        this.completeDataSource[cloneDataIndex].push([tempCloneData[tempIndex][z]]);
                        this.tempSizeArray.push(tempCloneData[tempIndex][z]);
                    }
                    else {
                        this.completeDataSource[cloneDataIndex].push('');
                    }
                }
            }
            else {
                if (tempCloneData[tempIndex] && (tempCloneData[tempIndex][z] ||
                    (tempCloneData[tempIndex][z] === 0 &&
                        tempCloneData[tempIndex][z].toString() !== ''))) {
                    if (typeof (tempCloneData[tempIndex][z]) === 'object') {
                        if (tempCloneData[tempIndex][z].length > 0 &&
                            !ej2_base_1.isNullOrUndefined(tempCloneData[tempIndex][z][0])) {
                            this.completeDataSource[cloneDataIndex].push(tempCloneData[tempIndex][z][0]);
                        }
                        else {
                            this.completeDataSource[cloneDataIndex].push('');
                        }
                    }
                    else {
                        this.completeDataSource[cloneDataIndex].push(tempCloneData[tempIndex][z]);
                    }
                }
                else {
                    this.completeDataSource[cloneDataIndex].push('');
                }
            }
        };
        TwoDimensional.prototype.getMinMaxValue = function (minVal, maxVal, tempVariable) {
            var minMaxValue = [];
            if (this.heatMap.bubbleSizeWithColor) {
                if (this.heatMap.paletteSettings.colorGradientMode === 'Column' && this.heatMap.paletteSettings.type === 'Gradient') {
                    this.tempSizeArray = tempVariable;
                }
                minMaxValue.push(this.getMinValue(minVal, this.tempSizeArray));
                minMaxValue.push(this.getMaxValue(maxVal, this.tempSizeArray));
                this.heatMap.minColorValue = this.getMinValue(this.heatMap.minColorValue, this.tempColorArray);
                this.heatMap.maxColorValue = this.getMaxValue(this.heatMap.maxColorValue, this.tempColorArray);
            }
            else {
                minMaxValue.push(this.getMinValue(minVal, tempVariable));
                minMaxValue.push(this.getMaxValue(maxVal, tempVariable));
            }
            return minMaxValue;
        };
        TwoDimensional.prototype.getMinValue = function (minVal, tempVariable) {
            if (ej2_base_1.isNullOrUndefined(minVal)) {
                minVal = this.performSort(tempVariable);
            }
            else if (this.performSort(tempVariable) < minVal) {
                minVal = this.performSort(tempVariable);
            }
            else if ((this.heatMap.paletteSettings.colorGradientMode === 'Row' ||
                this.heatMap.paletteSettings.colorGradientMode === 'Column') && this.heatMap.paletteSettings.type === 'Gradient') {
                minVal = this.performSort(tempVariable);
            }
            return !ej2_base_1.isNullOrUndefined(minVal) ? parseFloat(minVal.toString()) : minVal;
        };
        TwoDimensional.prototype.getMaxValue = function (maxVal, tempVariable) {
            if (ej2_base_1.isNullOrUndefined(maxVal) && tempVariable.length > 0) {
                maxVal = Math.max.apply(Math, tempVariable);
            }
            else if (Math.max.apply(Math, tempVariable) > maxVal) {
                maxVal = Math.max.apply(Math, tempVariable);
            }
            else if ((this.heatMap.paletteSettings.colorGradientMode === 'Row' ||
                this.heatMap.paletteSettings.colorGradientMode === 'Column') && this.heatMap.paletteSettings.type === 'Gradient') {
                maxVal = Math.max.apply(Math, tempVariable);
            }
            return !ej2_base_1.isNullOrUndefined(maxVal) ? parseFloat(maxVal.toString()) : maxVal;
        };
        TwoDimensional.prototype.performSort = function (tempVariable) {
            return tempVariable.sort(function (a, b) { return a - b; }).filter(this.checkmin)[0];
        };
        TwoDimensional.prototype.checkmin = function (val) {
            return !ej2_base_1.isNullOrUndefined(val) && val.toString() !== '';
        };
        TwoDimensional.prototype.destroy = function () {
            this.completeDataSource = null;
            this.tempColorArray = null;
            this.tempSizeArray = null;
            this.heatMap = null;
        };
        return TwoDimensional;
    }());
    exports.TwoDimensional = TwoDimensional;
});