Code coverage report for src/compiler/time.js

Statements: 80% (72 / 90)      Branches: 44.29% (31 / 70)      Functions: 100% (14 / 14)      Lines: 79.55% (70 / 88)      Ignored: none     

All files » src/compiler/ » time.js
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  1 1 1 1 1 8 8               8 8 8             1   1 6 6   1   1 7               3 3 31       4         1   1 8 8   1 1   3 3   8 31   4   1   1 43 103 103 5 5 1   103   43   1   1 12                 12   1   1 1 1 5 5 1             4   1 1 4     4   1 1 8 8           2   6   1     1 5     1   4   1    
/// <reference path="../../typings/d3-time-format.d.ts"/>
var d3_time_format_1 = require('d3-time-format');
var util = require('../util');
var consts_1 = require('../consts');
var LONG_DATE = new Date(Date.UTC(2014, 8, 17));
function cardinality(encDef, stats, filterNull, type) {
    var timeUnit = encDef.timeUnit;
    switch (timeUnit) {
        case 'seconds': return 60;
        case 'minutes': return 60;
        case 'hours': return 24;
        case 'day': return 7;
        case 'date': return 31;
        case 'month': return 12;
        case 'year':
            var stat = stats[encDef.name], yearstat = stats['year_' + encDef.name];
            Eif (!yearstat) {
                return null;
            }
            return yearstat.distinct -
                (stat.missing > 0 && filterNull[type] ? 1 : 0);
    }
    return null;
}
exports.cardinality = cardinality;
;
function formula(timeUnit, fieldRef) {
    var fn = 'utc' + timeUnit;
    return fn + '(' + fieldRef + ')';
}
exports.formula = formula;
;
function maxLength(timeUnit, encoding) {
    switch (timeUnit) {
        case 'seconds':
        case 'minutes':
        case 'hours':
        case 'date':
            return 2;
        case 'month':
        case 'day':
            var rng = range(timeUnit, encoding);
            Eif (rng) {
                return Math.max.apply(null, rng.map(function (r) { return r.length; }));
            }
            return 2;
        case 'year':
            return 4;
    }
    var timeFormat = encoding.config('timeFormat');
    return d3_time_format_1.utcFormat(timeFormat)(LONG_DATE).length;
}
exports.maxLength = maxLength;
;
function range(timeUnit, encoding) {
    var labelLength = encoding.config('timeScaleLabelLength'), scaleLabel;
    switch (timeUnit) {
        case 'day':
            scaleLabel = encoding.config('dayScaleLabel');
            break;
        case 'month':
            scaleLabel = encoding.config('monthScaleLabel');
            break;
    }
    if (scaleLabel) {
        return labelLength ? scaleLabel.map(function (s) { return s.substr(0, labelLength); }) : scaleLabel;
    }
    return;
}
exports.range = range;
;
function scales(encoding) {
    var scales = encoding.reduce(function (scales, encDef) {
        var timeUnit = encDef.timeUnit;
        if (encDef.type === consts_1.Type.T && timeUnit && !scales[timeUnit]) {
            var scaleDef = scale.def(encDef.timeUnit, encoding);
            if (scaleDef)
                scales[timeUnit] = scaleDef;
        }
        return scales;
    }, {});
    return util.vals(scales);
}
exports.scales = scales;
;
function isOrdinalFn(timeUnit) {
    switch (timeUnit) {
        case 'seconds':
        case 'minutes':
        case 'hours':
        case 'day':
        case 'date':
        case 'month':
            return true;
    }
    return false;
}
exports.isOrdinalFn = isOrdinalFn;
;
var scale;
(function (scale) {
    function def(timeUnit, encoding) {
        var rangeDef = range(timeUnit, encoding);
        if (rangeDef) {
            return {
                name: 'time-' + timeUnit,
                type: 'ordinal',
                domain: scale.domain(timeUnit),
                range: rangeDef
            };
        }
        return null;
    }
    scale.def = def;
    function type(timeUnit, name) {
        Iif (name === consts_1.Enctype.COLOR) {
            return 'linear';
        }
        return isOrdinalFn(timeUnit) || name === consts_1.Enctype.COL || name === consts_1.Enctype.ROW ? 'ordinal' : 'linear';
    }
    scale.type = type;
    function domain(timeUnit, name) {
        var isColor = name === consts_1.Enctype.COLOR;
        switch (timeUnit) {
            case 'seconds':
            case 'minutes': return isColor ? [0, 59] : util.range(0, 60);
            case 'hours': return isColor ? [0, 23] : util.range(0, 24);
            case 'day': return isColor ? [0, 6] : util.range(0, 7);
            case 'date': return isColor ? [1, 31] : util.range(1, 32);
            case 'month': return isColor ? [0, 11] : util.range(0, 12);
        }
        return null;
    }
    scale.domain = domain;
})(scale = exports.scale || (exports.scale = {}));
;
function hasScale(timeUnit) {
    switch (timeUnit) {
        case 'day':
        case 'month':
            return true;
    }
    return false;
}
exports.hasScale = hasScale;
;
//# sourceMappingURL=time.js.map