all files / chart3d/axis/ date-time-axis.js

92.57% Statements 187/202
87.38% Branches 90/103
100% Functions 22/22
92.46% Lines 184/199
11 statements, 6 functions, 9 branches Ignored     
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          196×   406× 406× 406× 406×   406×       406× 406× 406×   402× 46×   406×   402× 46×   406×   406× 406× 406× 406× 404×       406× 406×   406× 406× 406× 406× 406× 406× 402× 402× 402× 402× 402× 386× 386×   16× 16×                                           406× 406× 406× 406× 406×                                                   406×           406×   406×   406× 406× 406× 406× 402×   406× 4027× 4027×         4027× 4027× 4027× 3637× 3637× 406×   3637×   4027× 4027× 4027×       406× 54×         406× 406×     8070× 8070×     8064× 8064×   8070× 8070× 8070×   6860× 6860×   64× 64×   826× 826×   198× 198×   92× 92×   30× 30×         402× 402×   332× 332× 332×         48× 48× 48×     12× 12× 12×                 4177×          
/* istanbul ignore next */ 
var __extends = (this && this.__extends) || (function () {
    var extendStatics = function (d, b) {
        extendStatics = Object.setPrototypeOf ||
            ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
            function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
        return extendStatics(d, b);
    };
    return function (d, b) {
        extendStatics(d, b);
        function __() { this.constructor = d; }
        d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
    };
})();
define(["require", "exports", "../../common/utils/helper", "../utils/doubleRange", "../../common/utils/helper", "@syncfusion/ej2-data", "../axis/axis-helper", "@syncfusion/ej2-base"], function (require, exports, helper_1, doubleRange_1, helper_2, ej2_data_1, axis_helper_1, ej2_base_1) {
    "use strict";
    Object.defineProperty(exports, "__esModule", { value: true });
    var DateTime3D = (function (_super) {
        __extends(DateTime3D, _super);
        function DateTime3D(chart) {
            return _super.call(this, chart) || this;
        }
        DateTime3D.prototype.calculateRangeAndInterval = function (size, axis) {
            this.calculateRange(axis);
            this.getActualRange(axis, size);
            this.applyRangePadding(axis, size);
            this.calculateVisibleLabels(axis, this.chart);
        };
        DateTime3D.prototype.getActualRange = function (axis, size) {
            var option = {
                skeleton: 'full',
                type: 'dateTime'
            };
            var dateParser = this.chart.intl.getDateParser(option);
            var dateFormatter = this.chart.intl.getDateFormat(option);
            if ((axis.minimum) !== null) {
                this.min = Date.parse(dateParser(dateFormatter(new Date(ej2_data_1.DataUtil.parse.parseJson({ val: axis.minimum }).val))));
            }
            else if (this.min === null || this.min === Number.POSITIVE_INFINITY) {
                this.min = Date.parse(dateParser(dateFormatter(new Date(1970, 1, 1))));
            }
            if ((axis.maximum) !== null) {
                this.max = Date.parse(dateParser(dateFormatter(new Date(ej2_data_1.DataUtil.parse.parseJson({ val: axis.maximum }).val))));
            }
            else if (this.max === null || this.max === Number.NEGATIVE_INFINITY) {
                this.max = Date.parse(dateParser(dateFormatter(new Date(1970, 5, 1))));
            }
            if (this.min === this.max) {
                this.max = this.max + 2592000000;
                this.min = this.min - 2592000000;
            }
            axis.actualRange = {};
            axis.doubleRange = new doubleRange_1.DoubleRange(this.min, this.max);
            var datetimeInterval = this.calculateDateTimeNiceInterval(axis, size, axis.doubleRange.start, axis.doubleRange.end);
            if (!axis.interval) {
                axis.actualRange.interval = datetimeInterval;
            }
            else {
                axis.actualRange.interval = axis.interval;
            }
            axis.actualRange.min = axis.doubleRange.start;
            axis.actualRange.max = axis.doubleRange.end;
        };
        DateTime3D.prototype.applyRangePadding = function (axis, size) {
            this.min = (axis.actualRange.min);
            this.max = (axis.actualRange.max);
            var minimum;
            var maximum;
            var interval = axis.actualRange.interval;
            if (!helper_1.setRange(axis)) {
                var rangePadding = axis.getRangePadding(this.chart);
                minimum = new Date(this.min);
                maximum = new Date(this.max);
                var intervalType = axis.actualIntervalType;
                if (rangePadding === 'None') {
                    this.min = minimum.getTime();
                    this.max = maximum.getTime();
                }
                else Eif (rangePadding === 'Additional' || rangePadding === 'Round') {
                    switch (intervalType) {
                        case 'Years':
                            this.getYear(minimum, maximum, rangePadding, interval);
                            break;
                        case 'Months':
                            this.getMonth(minimum, maximum, rangePadding, interval);
                            break;
                        case 'Days':
                            this.getDay(minimum, maximum, rangePadding, interval);
                            break;
                        case 'Hours':
                            this.getHour(minimum, maximum, rangePadding, interval);
                            break;
                        case 'Minutes': {
                            var minute = (minimum.getMinutes() / interval) * interval;
                            var endMinute = maximum.getMinutes() + (minimum.getMinutes() - minute);
                            Eif (rangePadding === 'Round') {
                                this.min = (new Date(minimum.getFullYear(), minimum.getMonth(), minimum.getDate(), minimum.getHours(), minute, 0)).getTime();
                                this.max = (new Date(maximum.getFullYear(), maximum.getMonth(), maximum.getDate(), maximum.getHours(), endMinute, 59)).getTime();
                            }
                            else {
                                this.min = (new Date(minimum.getFullYear(), minimum.getMonth(), minimum.getDate(), minimum.getHours(), minute + (-interval), 0)).getTime();
                                this.max = (new Date(maximum.getFullYear(), maximum.getMonth(), maximum.getDate(), maximum.getHours(), endMinute + (interval), 0)).getTime();
                            }
                            break;
                        }
                        case 'Seconds': {
                            var second = (minimum.getSeconds() / interval) * interval;
                            var endSecond = maximum.getSeconds() + (minimum.getSeconds() - second);
                            Eif (rangePadding === 'Round') {
                                this.min = (new Date(minimum.getFullYear(), minimum.getMonth(), minimum.getDate(), minimum.getHours(), minimum.getMinutes(), second, 0)).getTime();
                                this.max = (new Date(maximum.getFullYear(), maximum.getMonth(), maximum.getDate(), maximum.getHours(), maximum.getMinutes(), endSecond, 0)).getTime();
                            }
                            else {
                                this.min = (new Date(minimum.getFullYear(), minimum.getMonth(), minimum.getDate(), minimum.getHours(), minimum.getMinutes(), second + (-interval), 0)).getTime();
                                this.max = (new Date(maximum.getFullYear(), maximum.getMonth(), maximum.getDate(), maximum.getHours(), maximum.getMinutes(), endSecond + (interval), 0)).getTime();
                            }
                            break;
                        }
                    }
                }
            }
            axis.actualRange.min = (axis.minimum != null) ? this.min : this.min;
            axis.actualRange.max = (axis.maximum != null) ? this.max : this.max;
            axis.actualRange.delta = (axis.actualRange.max - axis.actualRange.min);
            axis.doubleRange = new doubleRange_1.DoubleRange(axis.actualRange.min, axis.actualRange.max);
            this.calculateVisibleRange(size, axis);
        };
        DateTime3D.prototype.getYear = function (minimum, maximum, rangePadding, interval) {
            var startYear = minimum.getFullYear();
            var endYear = maximum.getFullYear();
            Iif (rangePadding === 'Additional') {
                this.min = (new Date(startYear - interval, 1, 1, 0, 0, 0)).getTime();
                this.max = (new Date(endYear + interval, 1, 1, 0, 0, 0)).getTime();
            }
            else {
                this.min = new Date(startYear, 0, 0, 0, 0, 0).getTime();
                this.max = new Date(endYear, 11, 30, 23, 59, 59).getTime();
            }
        };
        DateTime3D.prototype.getMonth = function (minimum, maximum, rangePadding, interval) {
            var month = minimum.getMonth();
            var endMonth = maximum.getMonth();
            Eif (rangePadding === 'Round') {
                this.min = (new Date(minimum.getFullYear(), month, 0, 0, 0, 0)).getTime();
                this.max = (new Date(maximum.getFullYear(), endMonth, new Date(maximum.getFullYear(), maximum.getMonth(), 0).getDate(), 23, 59, 59)).getTime();
            }
            else {
                this.min = (new Date(minimum.getFullYear(), month + (-interval), 1, 0, 0, 0)).getTime();
                this.max = (new Date(maximum.getFullYear(), endMonth + (interval), endMonth === 2 ? 28 : 30, 0, 0, 0)).getTime();
            }
        };
        DateTime3D.prototype.getDay = function (minimum, maximum, rangePadding, interval) {
            var day = minimum.getDate();
            var endDay = maximum.getDate();
            Eif (rangePadding === 'Round') {
                this.min = (new Date(minimum.getFullYear(), minimum.getMonth(), day, 0, 0, 0)).getTime();
                this.max = (new Date(maximum.getFullYear(), maximum.getMonth(), endDay, 23, 59, 59)).getTime();
            }
            else {
                this.min = (new Date(minimum.getFullYear(), minimum.getMonth(), day + (-interval), 0, 0, 0)).getTime();
                this.max = (new Date(maximum.getFullYear(), maximum.getMonth(), endDay + (interval), 0, 0, 0)).getTime();
            }
        };
        DateTime3D.prototype.getHour = function (minimum, maximum, rangePadding, interval) {
            var hour = (minimum.getHours() / interval) * interval;
            var endHour = maximum.getHours() + (minimum.getHours() - hour);
            Eif (rangePadding === 'Round') {
                this.min = (new Date(minimum.getFullYear(), minimum.getMonth(), minimum.getDate(), hour, 0, 0)).getTime();
                this.max = (new Date(maximum.getFullYear(), maximum.getMonth(), maximum.getDate(), endHour, 59, 59)).getTime();
            }
            else {
                this.min = (new Date(minimum.getFullYear(), minimum.getMonth(), minimum.getDate(), hour + (-interval), 0, 0)).getTime();
                this.max = (new Date(maximum.getFullYear(), maximum.getMonth(), maximum.getDate(), endHour + (interval), 0, 0)).getTime();
            }
        };
        DateTime3D.prototype.calculateVisibleRange = function (size, axis) {
            axis.visibleRange = {
                min: axis.actualRange.min,
                max: axis.actualRange.max,
                interval: axis.actualRange.interval,
                delta: axis.actualRange.delta
            };
            axis.dateTimeInterval = this.increaseDateTimeInterval(axis, axis.visibleRange.min, axis.visibleRange.interval).getTime()
                - axis.visibleRange.min;
            axis.triggerRangeRender(this.chart, axis.visibleRange.min, axis.visibleRange.max, axis.visibleRange.interval);
        };
        DateTime3D.prototype.calculateVisibleLabels = function (axis, chart) {
            axis.visibleLabels = [];
            var tempInterval = axis.visibleRange.min;
            var labelStyle;
            if (!helper_1.setRange(axis)) {
                tempInterval = this.alignRangeStart(axis, tempInterval, axis.visibleRange.interval).getTime();
            }
            while (tempInterval <= axis.visibleRange.max) {
                labelStyle = (ej2_base_1.extend({}, ej2_base_1.getValue('properties', axis.labelStyle), null, true));
                axis.format = chart.intl.getDateFormat({
                    format: this.findCustomFormats(axis) || '',
                    type: helper_2.firstToLowerCase(axis.skeletonType),
                    skeleton: this.getSkeleton(axis)
                });
                axis.startLabel = axis.format(new Date(axis.visibleRange.min));
                axis.endLabel = axis.format(new Date(axis.visibleRange.max));
                if (helper_2.withIn(tempInterval, axis.visibleRange)) {
                    var interval = this.increaseDateTimeInterval(axis, tempInterval, axis.visibleRange.interval).getTime();
                    if (interval > axis.visibleRange.max) {
                        axis.endLabel = axis.format(new Date(tempInterval));
                    }
                    helper_1.triggerLabelRender(chart, tempInterval, axis.format(new Date(tempInterval)), labelStyle, axis);
                }
                var actualInterval = tempInterval;
                tempInterval = this.increaseDateTimeInterval(axis, tempInterval, axis.visibleRange.interval).getTime();
                Iif (actualInterval === tempInterval) {
                    break;
                }
            }
            if ((axis.actualIntervalType === 'Months' || axis.actualIntervalType === 'Days')) {
                axis.format = chart.intl.getDateFormat({
                    format: axis.labelFormat || (axis.actualIntervalType === 'Months' && !axis.skeleton ? 'y MMM' : ''),
                    type: helper_2.firstToLowerCase(axis.skeletonType), skeleton: axis.skeleton || (axis.actualIntervalType === 'Days' ? 'MMMd' : '')
                });
            }
            Eif (axis.getMaxLabelWidth) {
                axis.getMaxLabelWidth(this.chart);
            }
        };
        DateTime3D.prototype.increaseDateTimeInterval = function (axis, value, interval) {
            var result = new Date(value);
            if (axis.interval) {
                axis.isIntervalInDecimal = (interval % 1) === 0;
                axis.visibleRange.interval = interval;
            }
            else {
                interval = Math.ceil(interval);
                axis.visibleRange.interval = interval;
            }
            var intervalType = axis.actualIntervalType;
            Eif (axis.isIntervalInDecimal) {
                switch (intervalType) {
                    case 'Years':
                        result.setFullYear(result.getFullYear() + interval);
                        return result;
                    case 'Months':
                        result.setMonth(result.getMonth() + interval);
                        return result;
                    case 'Days':
                        result.setDate(result.getDate() + interval);
                        return result;
                    case 'Hours':
                        result.setHours(result.getHours() + interval);
                        return result;
                    case 'Minutes':
                        result.setMinutes(result.getMinutes() + interval);
                        return result;
                    case 'Seconds':
                        result.setSeconds(result.getSeconds() + interval);
                        return result;
                }
            }
            return result;
        };
        DateTime3D.prototype.alignRangeStart = function (axis, sDate, intervalSize) {
            var sResult = new Date(sDate);
            switch (axis.actualIntervalType) {
                case 'Years': {
                    var year = Math.floor(Math.floor(sResult.getFullYear() / intervalSize) * intervalSize);
                    sResult = new Date(year, sResult.getMonth(), sResult.getDate(), 0, 0, 0);
                    return sResult;
                }
                case 'Months': {
                    var month = Math.floor(Math.floor((sResult.getMonth()) / intervalSize) * intervalSize);
                    sResult = new Date(sResult.getFullYear(), month, sResult.getDate(), 0, 0, 0);
                    return sResult;
                }
                case 'Days': {
                    var day = Math.floor(Math.floor((sResult.getDate()) / intervalSize) * intervalSize);
                    sResult = new Date(sResult.getFullYear(), sResult.getMonth(), day, 0, 0, 0);
                    return sResult;
                }
                case 'Hours': {
                    var hour = Math.floor(Math.floor((sResult.getHours()) / intervalSize) * intervalSize);
                    sResult = new Date(sResult.getFullYear(), sResult.getMonth(), sResult.getDate(), hour, 0, 0);
                    return sResult;
                }
                case 'Minutes': {
                    var minutes = Math.floor(Math.floor((sResult.getMinutes()) / intervalSize) * intervalSize);
                    sResult = new Date(sResult.getFullYear(), sResult.getMonth(), sResult.getDate(), sResult.getHours(), minutes, 0, 0);
                    return sResult;
                }
                case 'Seconds': {
                    var seconds = Math.floor(Math.floor((sResult.getSeconds()) / intervalSize) * intervalSize);
                    sResult = new Date(sResult.getFullYear(), sResult.getMonth(), sResult.getDate(), sResult.getHours(), sResult.getMinutes(), seconds, 0);
                    return sResult;
                }
            }
            return sResult;
        };
        DateTime3D.prototype.getModuleName = function () {
            return 'DateTime3D';
        };
        DateTime3D.prototype.destroy = function () {
        };
        return DateTime3D;
    }(axis_helper_1.NiceIntervals));
    exports.DateTime3D = DateTime3D;
});