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

94.74% Statements 108/114
85.98% Branches 92/107
100% Functions 12/12
94.55% Lines 104/110
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          2841×   2768× 2768× 2768× 2768× 2768× 2768× 2768× 2768× 2768×   273× 273×   59× 59×   91× 91×   22× 22×   30× 30×   19× 19×   33× 33×   15× 15×   2226× 2226× 997× 997×   1229× 1229× 911× 911×   318× 318×   314× 314× 125× 125×   189× 189× 13× 13×   176× 176× 24× 24×   152× 152× 152×   542×   18549× 18549× 18549× 286×   18263× 10245×       10245×     8018× 277×   7741× 6011×       6011×     1730× 214×   1516× 831×       831×     685× 167×       167×     518× 325×       325×       193×       193×     18263×   17904× 17904× 4702×   17904×        
/* 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", "../axis/double-axis"], function (require, exports, double_axis_1) {
    "use strict";
    Object.defineProperty(exports, "__esModule", { value: true });
    var NiceInterval = (function (_super) {
        __extends(NiceInterval, _super);
        function NiceInterval() {
            return _super !== null && _super.apply(this, arguments) || this;
        }
        NiceInterval.prototype.calculateDateTimeNiceInterval = function (axis, size, start, end, isChart) {
            if (isChart === void 0) { isChart = true; }
            var oneDay = 24 * 60 * 60 * 1000;
            var startDate = new Date(start);
            var endDate = new Date(end);
            var totalDays = (Math.abs((startDate.getTime() - endDate.getTime()) / (oneDay)));
            var interval;
            axis.actualIntervalType = axis.intervalType;
            var type = axis.intervalType;
            switch (type) {
                case 'Years':
                    interval = this.calculateNumericNiceInterval(axis, totalDays / 365, size);
                    break;
                case 'Quarter':
                    interval = this.calculateNumericNiceInterval(axis, (totalDays / 365) * 4, size);
                    break;
                case 'Months':
                    interval = this.calculateNumericNiceInterval(axis, totalDays / 30, size);
                    break;
                case 'Weeks':
                    interval = this.calculateNumericNiceInterval(axis, totalDays / 7, size);
                    break;
                case 'Days':
                    interval = this.calculateNumericNiceInterval(axis, totalDays, size);
                    break;
                case 'Hours':
                    interval = this.calculateNumericNiceInterval(axis, totalDays * 24, size);
                    break;
                case 'Minutes':
                    interval = this.calculateNumericNiceInterval(axis, totalDays * 24 * 60, size);
                    break;
                case 'Seconds':
                    interval = this.calculateNumericNiceInterval(axis, totalDays * 24 * 60 * 60, size);
                    break;
                case 'Auto':
                    interval = this.calculateNumericNiceInterval(axis, totalDays / 365, size);
                    if (interval >= 1) {
                        axis.actualIntervalType = 'Years';
                        return interval;
                    }
                    interval = this.calculateNumericNiceInterval(axis, totalDays / 30, size);
                    if (interval >= 1) {
                        axis.actualIntervalType = 'Months';
                        return interval;
                    }
                    interval = this.calculateNumericNiceInterval(axis, totalDays / 7, size);
                    if (interval >= 1 && !isChart) {
                        axis.actualIntervalType = 'Weeks';
                        return interval;
                    }
                    interval = this.calculateNumericNiceInterval(axis, totalDays, size);
                    if (interval >= 1) {
                        axis.actualIntervalType = 'Days';
                        return interval;
                    }
                    interval = this.calculateNumericNiceInterval(axis, totalDays * 24, size);
                    if (interval >= 1) {
                        axis.actualIntervalType = 'Hours';
                        return interval;
                    }
                    interval = this.calculateNumericNiceInterval(axis, totalDays * 24 * 60, size);
                    if (interval >= 1) {
                        axis.actualIntervalType = 'Minutes';
                        return interval;
                    }
                    interval = this.calculateNumericNiceInterval(axis, totalDays * 24 * 60 * 60, size);
                    axis.actualIntervalType = 'Seconds';
                    return interval;
            }
            return interval;
        };
        NiceInterval.prototype.getSkeleton = function (axis, currentValue, previousValue, isBlazor) {
            var skeleton;
            var intervalType = axis.actualIntervalType;
            if (axis.skeleton) {
                return axis.skeleton;
            }
            if (intervalType === 'Years') {
                Iif (isBlazor) {
                    skeleton = axis.isChart ? (axis.valueType === 'DateTime' ? 'y' : 'y') : 'y';
                }
                else {
                    skeleton = axis.isChart ? ((axis.valueType === 'DateTime' && axis.isIntervalInDecimal) ? 'y' : 'yMMM') : 'y';
                }
            }
            else if (intervalType === 'Quarter') {
                skeleton = isBlazor ? 'y' : 'yMMM';
            }
            else if (intervalType === 'Months') {
                Iif (isBlazor) {
                    skeleton = axis.isChart ? 'm' : 'm';
                }
                else {
                    skeleton = axis.isChart ? 'MMMd' : 'MMM';
                }
            }
            else if (intervalType === 'Weeks') {
                skeleton = isBlazor ? 'm' : 'MEd';
            }
            else if (intervalType === 'Days') {
                Iif (isBlazor) {
                    skeleton = 'd';
                }
                else {
                    skeleton = axis.isChart ? (axis.valueType === 'DateTime' ? 'MMMd' : 'yMd') : 'MMMd';
                }
            }
            else if (intervalType === 'Hours') {
                Iif (isBlazor) {
                    skeleton = 't';
                }
                else {
                    skeleton = axis.isChart ? (axis.valueType === 'DateTime' ? 'Hm' : 'EHm') : 'h';
                }
            }
            else if (intervalType === 'Minutes') {
                Iif (isBlazor) {
                    skeleton = 'T';
                }
                else {
                    skeleton = axis.isChart ? 'Hms' : 'hm';
                }
            }
            else {
                Iif (isBlazor) {
                    skeleton = 'T';
                }
                else {
                    skeleton = axis.isChart ? 'Hms' : 'hms';
                }
            }
            return skeleton;
        };
        NiceInterval.prototype.findCustomFormats = function (axis) {
            var labelFormat = axis.labelFormat ? axis.labelFormat : '';
            if (axis.isChart && !axis.skeleton && axis.actualIntervalType === 'Months' && !labelFormat) {
                labelFormat = axis.valueType === 'DateTime' ? 'MMM yyyy' : 'yMMM';
            }
            return labelFormat;
        };
        return NiceInterval;
    }(double_axis_1.Double));
    exports.NiceInterval = NiceInterval;
});