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

97.73% Statements 86/88
96.67% Branches 58/60
100% Functions 12/12
97.65% Lines 83/85
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          399×   442× 442× 442× 442× 442× 442× 442× 442×   32× 32×             398× 398× 306× 306×   92× 92×   90× 90× 48× 48×   42× 42× 10× 10×   32× 32×       32× 32× 32×   44×   4093× 4093× 4093×   4091× 3435×   656× 34×   622× 418×   204× 104×   100× 50×     50×   4091×   4027× 4027× 32×   4027×        
/* 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 NiceIntervals = (function (_super) {
        __extends(NiceIntervals, _super);
        function NiceIntervals() {
            return _super !== null && _super.apply(this, arguments) || this;
        }
        NiceIntervals.prototype.calculateDateTimeNiceInterval = function (axis, size, start, end) {
            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 'Months':
                    interval = this.calculateNumericNiceInterval(axis, totalDays / 30, 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, 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);
                    Iif (interval >= 1) {
                        axis.actualIntervalType = 'Minutes';
                        return interval;
                    }
                    interval = this.calculateNumericNiceInterval(axis, totalDays * 24 * 60 * 60, size);
                    axis.actualIntervalType = 'Seconds';
                    return interval;
            }
            return interval;
        };
        NiceIntervals.prototype.getSkeleton = function (axis) {
            var skeleton;
            var intervalType = axis.actualIntervalType;
            if (axis.skeleton) {
                return axis.skeleton;
            }
            if (intervalType === 'Years') {
                skeleton = ((axis.valueType === 'DateTime' && axis.isIntervalInDecimal) ? 'y' : 'yMMM');
            }
            else if (intervalType === 'Months') {
                skeleton = 'MMMd';
            }
            else if (intervalType === 'Days') {
                skeleton = (axis.valueType === 'DateTime' ? 'MMMd' : 'yMd');
            }
            else if (intervalType === 'Hours') {
                skeleton = (axis.valueType === 'DateTime' ? 'Hm' : 'EHm');
            }
            else if (intervalType === 'Minutes') {
                skeleton = 'Hms';
            }
            else {
                skeleton = 'Hms';
            }
            return skeleton;
        };
        NiceIntervals.prototype.findCustomFormats = function (axis) {
            var labelFormat = axis.labelFormat ? axis.labelFormat : '';
            if (!axis.skeleton && axis.actualIntervalType === 'Months' && !labelFormat) {
                labelFormat = axis.valueType === 'DateTime' ? 'MMM yyyy' : 'yMMM';
            }
            return labelFormat;
        };
        return NiceIntervals;
    }(double_axis_1.Double3D));
    exports.NiceIntervals = NiceIntervals;
});