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

100% Statements 150/150
99.12% Branches 112/113
100% Functions 17/17
100% Lines 150/150
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   12639×   18039× 18039× 18039×   18037× 18037× 52150× 52150× 52150× 17890×   34260×   18037×   11076× 11076× 11076× 11076×   13125× 1771×   11354× 1236×   13125× 1697×   11428× 1276×   13125× 210×   13125× 13125×   10800× 10800× 10800× 10800×   13700× 13700× 13700× 13700× 12019× 17292× 17292× 140×   17152× 17152×   2250×   1682×     17152× 8996× 1026×     7970×     17152× 8156× 1038×     7118×           17152× 11839×   17152× 12267×     10800× 10800× 10800× 10800× 9307× 9307× 9307× 204×   9103× 4782×     4321×     10800× 10800×   9685× 9685× 9685×   204× 204× 204× 204× 204× 176× 176×   204×   4782× 4782× 4782× 4782× 4782× 1324× 1324× 1324× 1324× 45×   1324× 1324×       3458× 3458× 46×     4782× 4782× 4782× 542×   4782× 4726×   4782× 4782× 3408× 3408×   4782×   12577×       12577× 1796× 1796×       12577×   10882× 10882× 10882× 2360×   10882× 10882× 10882×       10882× 10882× 10882× 92458× 90548×     10882× 10800×     11154× 1217×   9937×   91558×          
define(["require", "exports", "../../common/utils/helper", "../utils/double-range", "../../common/utils/helper", "@syncfusion/ej2-base"], function (require, exports, helper_1, double_range_1, helper_2, ej2_base_1) {
    "use strict";
    Object.defineProperty(exports, "__esModule", { value: true });
    var Double = (function () {
        function Double(chart) {
            this.chart = chart;
        }
        Double.prototype.calculateNumericNiceInterval = function (axis, delta, size) {
            var actualDesiredIntervalsCount = helper_1.getActualDesiredIntervalsCount(size, axis);
            var niceInterval = delta / actualDesiredIntervalsCount;
            if (!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;
        };
        Double.prototype.getActualRange = function (axis, size) {
            this.initializeDoubleRange(axis);
            axis.actualRange.interval = axis.interval || this.calculateNumericNiceInterval(axis, axis.doubleRange.delta, size);
            axis.actualRange.min = axis.doubleRange.start;
            axis.actualRange.max = axis.doubleRange.end;
        };
        Double.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 double_range_1.DoubleRange(this.min, this.max);
            axis.actualRange = {};
        };
        Double.prototype.calculateRangeAndInterval = function (size, axis) {
            this.calculateRange(axis, size);
            this.getActualRange(axis, size);
            this.applyRangePadding(axis, size);
            this.calculateVisibleLabels(axis, this.chart);
        };
        Double.prototype.calculateRange = function (axis, size) {
            var series;
            this.min = null;
            this.max = null;
            if (!helper_1.setRange(axis)) {
                for (var _i = 0, _a = axis.series; _i < _a.length; _i++) {
                    var series_1 = _a[_i];
                    if (!series_1.visible) {
                        continue;
                    }
                    this.paddingInterval = 0;
                    if (((series_1.type.indexOf('Column') > -1 || series_1.type.indexOf('Histogram') > -1) && axis.orientation === 'Horizontal')
                        || (series_1.type.indexOf('Bar') > -1 && axis.orientation === 'Vertical')) {
                        if ((series_1.xAxis.valueType === 'Double' || series_1.xAxis.valueType === 'DateTime')
                            && series_1.xAxis.rangePadding === 'Auto') {
                            this.paddingInterval = helper_1.getMinPointsDelta(series_1.xAxis, axis.series) / 2;
                        }
                    }
                    if (axis.orientation === 'Horizontal') {
                        if (this.chart.requireInvertedAxis) {
                            this.findMinMax(series_1.yMin, series_1.yMax);
                        }
                        else {
                            this.findMinMax(series_1.xMin - this.paddingInterval, series_1.xMax + this.paddingInterval);
                        }
                    }
                    if (axis.orientation === 'Vertical') {
                        if (this.chart.requireInvertedAxis) {
                            this.findMinMax(series_1.xMin - this.paddingInterval, series_1.xMax + this.paddingInterval);
                        }
                        else {
                            this.findMinMax(series_1.yMin, series_1.yMax);
                        }
                    }
                }
            }
        };
        Double.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;
            }
        };
        Double.prototype.applyRangePadding = function (axis, size) {
            var range;
            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);
                }
                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);
        };
        Double.prototype.updateActualRange = function (axis, minimum, maximum, interval) {
            axis.actualRange.min = axis.minimum != null ? axis.minimum : minimum;
            axis.actualRange.max = axis.maximum != null ? axis.maximum : maximum;
            axis.actualRange.interval = axis.interval != null ? axis.interval : interval;
        };
        Double.prototype.findAdditional = function (axis, start, end, interval) {
            var minimum;
            var maximum;
            minimum = Math.floor(start / interval) * interval;
            maximum = Math.ceil(end / interval) * interval;
            if (axis.rangePadding === 'Additional') {
                minimum -= interval;
                maximum += interval;
            }
            this.updateActualRange(axis, minimum, maximum, interval);
        };
        Double.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 / 20);
                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) / 2);
                if (minimum % interval > 0) {
                    minimum -= (minimum % interval);
                }
            }
            maximum = (end > 0) ? (end + (end - startValue) / 20) : (end - (end - startValue) / 20);
            remaining = interval - (maximum % interval);
            if ((0.365 * interval) >= remaining) {
                maximum += interval;
            }
            if (maximum % interval > 0) {
                maximum = (maximum + interval) - (maximum % interval);
            }
            axis.doubleRange = new double_range_1.DoubleRange(minimum, maximum);
            if (minimum === 0) {
                interval = this.calculateNumericNiceInterval(axis, axis.doubleRange.delta, size);
                maximum = Math.ceil(maximum / interval) * interval;
            }
            this.updateActualRange(axis, minimum, maximum, interval);
        };
        Double.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.zoomFactor < 1 || axis.zoomPosition > 0) {
                axis.calculateVisibleRange(size);
                axis.visibleRange.interval = (axis.enableAutoIntervalOnZooming && axis.valueType !== 'Category') ?
                    this.calculateNumericNiceInterval(axis, axis.doubleRange.delta, size)
                    : axis.visibleRange.interval;
            }
            axis.triggerRangeRender(this.chart, axis.visibleRange.min, axis.visibleRange.max, axis.visibleRange.interval);
        };
        Double.prototype.calculateVisibleLabels = function (axis, chart) {
            axis.visibleLabels = [];
            var tempInterval = axis.visibleRange.min;
            if (axis.zoomFactor < 1 || axis.zoomPosition > 0 || this.paddingInterval) {
                tempInterval = axis.visibleRange.min - (axis.visibleRange.min % axis.visibleRange.interval);
            }
            var format = this.getFormat(axis);
            var isCustom = format.match('{value}') !== null;
            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);
            for (; tempInterval <= axis.visibleRange.max; tempInterval += axis.visibleRange.interval) {
                if (helper_2.withIn(tempInterval, axis.visibleRange)) {
                    helper_1.triggerLabelRender(chart, tempInterval, this.formatValue(axis, isCustom, format, tempInterval), axis.labelStyle, axis);
                }
            }
            if (axis.getMaxLabelWidth) {
                axis.getMaxLabelWidth(this.chart);
            }
        };
        Double.prototype.getFormat = function (axis) {
            if (axis.labelFormat) {
                return axis.labelFormat;
            }
            return axis.isStack100 ? '{value}%' : '';
        };
        Double.prototype.formatValue = function (axis, isCustom, format, tempInterval) {
            return isCustom ? format.replace('{value}', axis.format(tempInterval))
                : axis.format(tempInterval);
        };
        return Double;
    }());
    exports.Double = Double;
});