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

100% Statements 99/99
100% Branches 71/71
100% Functions 10/10
100% Lines 95/95
9 statements, 5 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        1529×   1371× 1371× 1371× 1371× 1371× 1371× 1371× 1371× 1371×   39× 39×   27× 27×   62× 62×   15× 15×   22× 22×   12× 12×   24× 24×     1161× 1161× 719× 719×   442× 442× 95× 95×   347× 347× 136× 136×   211× 211×   209× 209× 51× 51×   158× 158× 10× 10×   148× 148× 24× 24×   124× 124× 124×   210×   1277× 1277× 1277× 33×   1244× 788×   456× 67×   389× 178×   211× 13×   198× 87×   111× 25×   86× 46×     40×   1244×        
/* istanbul ignore next */ 
var __extends = (this && this.__extends) || (function () {
    var 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 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 / 365) * 4, size);
                    if (interval >= 1 && !isChart) {
                        axis.actualIntervalType = 'Quarter';
                        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) {
            var skeleton;
            var intervalType = axis.actualIntervalType;
            if (axis.skeleton) {
                return axis.skeleton;
            }
            if (intervalType === 'Years') {
                skeleton = axis.isChart ? 'yMMM' : 'y';
            }
            else if (intervalType === 'Quarter') {
                skeleton = 'yMMM';
            }
            else if (intervalType === 'Months') {
                skeleton = axis.isChart ? 'MMMd' : 'MMM';
            }
            else if (intervalType === 'Weeks') {
                skeleton = 'MEd';
            }
            else if (intervalType === 'Days') {
                skeleton = axis.isChart ? 'yMd' : 'MMMd';
            }
            else if (intervalType === 'Hours') {
                skeleton = axis.isChart ? 'EHm' : 'h';
            }
            else if (intervalType === 'Minutes') {
                skeleton = axis.isChart ? 'Hms' : 'hm';
            }
            else {
                skeleton = axis.isChart ? 'Hms' : 'hms';
            }
            return skeleton;
        };
        return NiceInterval;
    }(double_axis_1.Double));
    exports.NiceInterval = NiceInterval;
});