all files / chart3d/axis/ double-axis.js

94.12% Statements 176/187
85.71% Branches 144/168
100% Functions 19/19
94.12% Lines 176/187
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   2643× 2643× 2643×   3634× 3634× 3634×     3634× 3634× 9987× 9987× 9987× 3439×   6548×   3634×   2220× 2220×                     2220× 2220× 2220×     2766× 650×   2116× 584×   2766× 788×   1978× 582×   2766× 26×   2766× 2766×   2220× 2220× 2220× 2220×   3172× 3172× 3172× 2518× 4234× 4234× 54×   4180× 4180× 4180×   4180× 4180×   1908×   1022×     4180× 1722× 476×     1246×     4180× 2458× 2458× 2458× 662×     1796×           2272×   4180× 2454×   4180× 3188×   4180×     2220× 2220× 2220× 1602× 1602× 1602× 102×   1500× 1060×     440×     2220× 2220×   1602×             102× 102× 102× 102× 102×       102×       102×   1060× 1060× 1060× 1060× 1060× 50× 50× 50× 50× 16×   50× 50×       1010× 1010×       1060× 1060× 1060× 69×   1060× 1060×   1060× 1060× 1010× 1010×   1060×   2718×       2718× 256× 256× 256× 1714×   256× 22×     2718×   2220× 2220× 2220× 2220× 2220× 2220× 2220× 2220× 44×   2220×       2220× 2220× 2220× 339×   2220× 2220× 20131× 20131× 20131× 20131×     2220× 18×   18×     2220× 2220×     2268× 334×   332×   1934×   20315× 20315×     4177×        
define(["require", "exports", "../../common/utils/helper", "../utils/doubleRange", "../../common/utils/helper", "@syncfusion/ej2-base", "../utils/chart3dRender"], function (require, exports, helper_1, doubleRange_1, helper_2, ej2_base_1, chart3dRender_1) {
    "use strict";
    Object.defineProperty(exports, "__esModule", { value: true });
    var Double3D = (function () {
        function Double3D(chart) {
            this.isColumn = 0;
            this.isStacking = false;
            this.chart = chart;
        }
        Double3D.prototype.calculateNumericNiceInterval = function (axis, delta, size) {
            var actualDesiredIntervalsCount = helper_1.getActualDesiredIntervalsCount(size, axis);
            var niceInterval = delta / actualDesiredIntervalsCount;
            Iif (!ej2_base_1.isNullOrUndefined(axis.desiredIntervals)) {
                return niceInterval;
            }
            var minInterval = Math.pow(10, Math.floor(helper_2.logBase(niceInterval, 10)));
            for (var _i = 0, _a = axis.intervalDivs; _i < _a.length; _i++) {
                var interval = _a[_i];
                var currentInterval = minInterval * interval;
                if (actualDesiredIntervalsCount < (delta / currentInterval)) {
                    break;
                }
                niceInterval = currentInterval;
            }
            return niceInterval;
        };
        Double3D.prototype.getActualRange = function (axis, size) {
            this.initializeDoubleRange(axis);
            Iif ((!axis.startFromZero) && (this.isColumn > 0)) {
                axis.actualRange.interval = axis.interval || this.calculateNumericNiceInterval(axis, axis.doubleRange.delta, size);
                axis.actualRange.max = axis.doubleRange.end + axis.actualRange.interval;
                if ((axis.doubleRange.start - axis.actualRange.interval < 0 && axis.doubleRange.start > 0)) {
                    axis.actualRange.min = 0;
                }
                else {
                    axis.actualRange.min = axis.doubleRange.start - (this.isStacking ? 0 : axis.actualRange.interval);
                }
            }
            else {
                axis.actualRange.interval = axis.interval || this.calculateNumericNiceInterval(axis, axis.doubleRange.delta, size);
                axis.actualRange.min = axis.doubleRange.start;
                axis.actualRange.max = axis.doubleRange.end;
            }
        };
        Double3D.prototype.initializeDoubleRange = function (axis) {
            if (axis.minimum !== null) {
                this.min = axis.minimum;
            }
            else if (this.min === null || this.min === Number.POSITIVE_INFINITY) {
                this.min = 0;
            }
            if (axis.maximum !== null) {
                this.max = axis.maximum;
            }
            else if (this.max === null || this.max === Number.NEGATIVE_INFINITY) {
                this.max = 5;
            }
            if (this.min === this.max) {
                this.max = axis.valueType.indexOf('Category') > -1 ? this.max : this.min + 1;
            }
            axis.doubleRange = new doubleRange_1.DoubleRange(this.min, this.max);
            axis.actualRange = {};
        };
        Double3D.prototype.calculateRangeAndInterval = function (size, axis) {
            this.calculateRange(axis);
            this.getActualRange(axis, size);
            this.applyRangePadding(axis, size);
            this.calculateVisibleLabels(axis, this.chart);
        };
        Double3D.prototype.calculateRange = function (axis) {
            this.min = null;
            this.max = null;
            if (!helper_1.setRange(axis)) {
                for (var _i = 0, _a = axis.series; _i < _a.length; _i++) {
                    var series = _a[_i];
                    if (!series.visible) {
                        continue;
                    }
                    this.paddingInterval = 0;
                    Eif (!ej2_base_1.isNullOrUndefined(series.points)) {
                        axis.maxPointLength = series.points.length;
                    }
                    axis.maxPointLength = series.points.length;
                    if (((series.type.indexOf('Column') > -1) && axis.orientation === 'Horizontal')
                        || (series.type.indexOf('Bar') > -1 && axis.orientation === 'Vertical')) {
                        if ((series.xAxis.valueType === 'Double' || series.xAxis.valueType === 'DateTime')
                            && series.xAxis.rangePadding === 'Auto') {
                            this.paddingInterval = chart3dRender_1.getMinPointsDeltaValue(series.xAxis, axis.series) * 0.5;
                        }
                    }
                    if (axis.orientation === 'Horizontal') {
                        if (this.chart.requireInvertedAxis) {
                            this.yAxisRange(axis, series);
                        }
                        else {
                            this.findMinMax(series.xMin - this.paddingInterval, series.xMax + this.paddingInterval);
                        }
                    }
                    if (axis.orientation === 'Vertical') {
                        this.isColumn += (series.type.indexOf('Column') !== -1 || series.type.indexOf('Bar') !== -1) ? 1 : 0;
                        this.isStacking = series.type.indexOf('Stacking') !== -1;
                        if (this.chart.requireInvertedAxis) {
                            this.findMinMax(series.xMin - this.paddingInterval, series.xMax + this.paddingInterval);
                        }
                        else {
                            this.yAxisRange(axis, series);
                        }
                    }
                }
            }
        };
        Double3D.prototype.yAxisRange = function (axis, series) {
            this.findMinMax(series.yMin, series.yMax);
        };
        Double3D.prototype.findMinMax = function (min, max) {
            if (this.min === null || this.min > min) {
                this.min = min;
            }
            if (this.max === null || this.max < max) {
                this.max = max;
            }
            if ((this.max === this.min) && this.max < 0 && this.min < 0) {
                this.max = 0;
            }
        };
        Double3D.prototype.applyRangePadding = function (axis, size) {
            var start = axis.actualRange.min;
            var end = axis.actualRange.max;
            if (!helper_1.setRange(axis)) {
                var interval = axis.actualRange.interval;
                var padding = axis.getRangePadding(this.chart);
                if (padding === 'Additional' || padding === 'Round') {
                    this.findAdditional(axis, start, end, interval, size);
                }
                else if (padding === 'Normal') {
                    this.findNormal(axis, start, end, interval, size);
                }
                else {
                    this.updateActualRange(axis, start, end, interval);
                }
            }
            axis.actualRange.delta = axis.actualRange.max - axis.actualRange.min;
            this.calculateVisibleRange(size, axis);
        };
        Double3D.prototype.updateActualRange = function (axis, minimum, maximum, interval) {
            axis.actualRange = {
                min: axis.minimum != null ? axis.minimum : minimum,
                max: axis.maximum != null ? axis.maximum : maximum,
                interval: axis.interval != null ? axis.interval : interval,
                delta: axis.actualRange.delta
            };
        };
        Double3D.prototype.findAdditional = function (axis, start, end, interval, size) {
            var minimum;
            var maximum;
            minimum = Math.floor(start / interval) * interval;
            maximum = Math.ceil(end / interval) * interval;
            Iif (axis.rangePadding === 'Additional') {
                minimum -= interval;
                maximum += interval;
            }
            Iif (!ej2_base_1.isNullOrUndefined(axis.desiredIntervals)) {
                var delta = maximum - minimum;
                interval = this.calculateNumericNiceInterval(axis, delta, size);
            }
            this.updateActualRange(axis, minimum, maximum, interval);
        };
        Double3D.prototype.findNormal = function (axis, start, end, interval, size) {
            var remaining;
            var minimum;
            var maximum;
            var startValue = start;
            if (start < 0) {
                startValue = 0;
                minimum = start + (start * 0.05);
                remaining = interval + (minimum % interval);
                if ((0.365 * interval) >= remaining) {
                    minimum -= interval;
                }
                Eif (minimum % interval < 0) {
                    minimum = (minimum - interval) - (minimum % interval);
                }
            }
            else {
                minimum = start < ((5.0 / 6.0) * end) ? 0 : (start - (end - start) * 0.5);
                Iif (minimum % interval > 0) {
                    minimum -= (minimum % interval);
                }
            }
            maximum = (end > 0) ? (end + (end - startValue) * 0.05) : (end - (end - startValue) * 0.05);
            remaining = interval - (maximum % interval);
            if ((0.365 * interval) >= remaining) {
                maximum += interval;
            }
            Eif (maximum % interval > 0) {
                maximum = (maximum + interval) - (maximum % interval);
            }
            axis.doubleRange = new doubleRange_1.DoubleRange(minimum, maximum);
            if (minimum === 0 || (minimum < 0 && maximum < 0)) {
                interval = this.calculateNumericNiceInterval(axis, axis.doubleRange.delta, size);
                maximum = Math.ceil(maximum / interval) * interval;
            }
            this.updateActualRange(axis, minimum, maximum, interval);
        };
        Double3D.prototype.calculateVisibleRange = function (size, axis) {
            axis.visibleRange = {
                max: axis.actualRange.max, min: axis.actualRange.min,
                delta: axis.actualRange.delta, interval: axis.actualRange.interval
            };
            if (axis.maximum && axis.orientation === 'Vertical' && axis.rangePadding === 'Auto') {
                var duplicateTempInterval = void 0;
                var tempInterval = axis.visibleRange.min;
                for (; (tempInterval <= axis.visibleRange.max) && (duplicateTempInterval !== tempInterval); tempInterval += axis.visibleRange.interval) {
                    duplicateTempInterval = tempInterval;
                }
                if (duplicateTempInterval < axis.visibleRange.max) {
                    axis.visibleRange.max = duplicateTempInterval + axis.visibleRange.interval;
                }
            }
            axis.triggerRangeRender(this.chart, axis.visibleRange.min, axis.visibleRange.max, axis.visibleRange.interval);
        };
        Double3D.prototype.calculateVisibleLabels = function (axis, chart) {
            axis.visibleLabels = [];
            var tempInterval = axis.visibleRange.min;
            var labelStyle;
            var format = this.getFormat(axis);
            var isCustom = format.match('{value}') !== null;
            var intervalDigits = 0;
            var formatDigits = 0;
            if (axis.labelFormat && axis.labelFormat.indexOf('n') > -1) {
                formatDigits = parseInt(axis.labelFormat.substring(1, axis.labelFormat.length), 10);
            }
            axis.format = chart.intl.getNumberFormat({
                format: isCustom ? '' : format,
                useGrouping: chart.useGroupingSeparator
            });
            axis.startLabel = axis.format(axis.visibleRange.min);
            axis.endLabel = axis.format(axis.visibleRange.max);
            if (axis.visibleRange.interval && (axis.visibleRange.interval + '').indexOf('.') >= 0) {
                intervalDigits = (axis.visibleRange.interval + '').split('.')[1].length;
            }
            var duplicateTempInterval;
            for (; (tempInterval <= axis.visibleRange.max) && (duplicateTempInterval !== tempInterval); tempInterval += axis.visibleRange.interval) {
                duplicateTempInterval = tempInterval;
                labelStyle = (ej2_base_1.extend({}, ej2_base_1.getValue('properties', axis.labelStyle), null, true));
                Eif (helper_2.withIn(tempInterval, axis.visibleRange)) {
                    helper_1.triggerLabelRender(chart, tempInterval, this.formatValue(axis, isCustom, format, tempInterval), labelStyle, axis);
                }
            }
            if (tempInterval && (tempInterval + '').indexOf('.') >= 0 && (tempInterval + '').split('.')[1].length > 10) {
                tempInterval = (tempInterval + '').split('.')[1].length > (formatDigits || intervalDigits) ?
                    +tempInterval.toFixed(formatDigits || intervalDigits) : tempInterval;
                if (tempInterval <= axis.visibleRange.max) {
                    helper_1.triggerLabelRender(chart, tempInterval, this.formatValue(axis, isCustom, format, tempInterval), labelStyle, axis);
                }
            }
            Eif (axis.getMaxLabelWidth) {
                axis.getMaxLabelWidth(this.chart);
            }
        };
        Double3D.prototype.getFormat = function (axis) {
            if (axis.labelFormat) {
                if (axis.labelFormat.indexOf('p') === 0 && axis.labelFormat.indexOf('{value}') === -1 && axis.isStack100) {
                    return '{value}%';
                }
                return axis.labelFormat;
            }
            return axis.isStack100 ? '{value}%' : '';
        };
        Double3D.prototype.formatValue = function (axis, isCustom, format, tempInterval) {
            var labelValue = !(tempInterval % 1) ? tempInterval : Number(tempInterval.toLocaleString().split(',').join(''));
            return isCustom ? format.replace('{value}', axis.format(labelValue))
                : format ? axis.format(tempInterval) : axis.format(labelValue);
        };
        Double3D.prototype.getModuleName = function () {
            return 'Double3D';
        };
        return Double3D;
    }());
    exports.Double3D = Double3D;
});