Code coverage report for src/compiler/layout.js

Statements: 98.39% (61 / 62)      Branches: 94.83% (55 / 58)      Functions: 100% (6 / 6)      Lines: 98.39% (61 / 62)      Ignored: none     

All files » src/compiler/ » layout.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  1 1 1 1 1 42 42 42   1 1 1 42 42 42   42 42 39 14     25       3 1     2     42 38 6     32       4   42 42 5 5   42 2 2   42                   1 41 41   1 65 65 13   52 28   24 4   20 20       20       1 42 84 84 37   47   40 28         84 65     19     42    
/// <reference path="../../typings/d3-format.d.ts"/>
var d3_format = require('d3-format');
var util_1 = require('../util');
var consts_1 = require('../consts');
var time = require('./time');
function default_1(encoding, stats) {
    var layout = box(encoding, stats);
    layout = offset(encoding, stats, layout);
    return layout;
}
Object.defineProperty(exports, "__esModule", { value: true });
exports.default = default_1;
function box(encoding, stats) {
    var hasRow = encoding.has(consts_1.Enctype.ROW), hasCol = encoding.has(consts_1.Enctype.COL), hasX = encoding.has(consts_1.Enctype.X), hasY = encoding.has(consts_1.Enctype.Y), marktype = encoding.marktype();
    var xCardinality = hasX && encoding.isDimension(consts_1.Enctype.X) ? encoding.cardinality(consts_1.Enctype.X, stats) : 1, yCardinality = hasY && encoding.isDimension(consts_1.Enctype.Y) ? encoding.cardinality(consts_1.Enctype.Y, stats) : 1;
    var useSmallBand = xCardinality > encoding.config('largeBandMaxCardinality') ||
        yCardinality > encoding.config('largeBandMaxCardinality');
    var cellWidth, cellHeight, cellPadding = encoding.config('cellPadding');
    if (hasX) {
        if (encoding.isOrdinalScale(consts_1.Enctype.X)) {
            cellWidth = (xCardinality + encoding.padding(consts_1.Enctype.X)) * encoding.bandWidth(consts_1.Enctype.X, useSmallBand);
        }
        else {
            cellWidth = hasCol || hasRow ? encoding.encDef(consts_1.Enctype.COL).width : encoding.config('singleWidth');
        }
    }
    else {
        if (marktype === consts_1.Enctype.TEXT) {
            cellWidth = encoding.config('textCellWidth');
        }
        else {
            cellWidth = encoding.bandWidth(consts_1.Enctype.X);
        }
    }
    if (hasY) {
        if (encoding.isOrdinalScale(consts_1.Enctype.Y)) {
            cellHeight = (yCardinality + encoding.padding(consts_1.Enctype.Y)) * encoding.bandWidth(consts_1.Enctype.Y, useSmallBand);
        }
        else {
            cellHeight = hasCol || hasRow ? encoding.encDef(consts_1.Enctype.ROW).height : encoding.config('singleHeight');
        }
    }
    else {
        cellHeight = encoding.bandWidth(consts_1.Enctype.Y);
    }
    var width = cellWidth, height = cellHeight;
    if (hasCol) {
        var colCardinality = encoding.cardinality(consts_1.Enctype.COL, stats);
        width = cellWidth * ((1 + cellPadding) * (colCardinality - 1) + 1);
    }
    if (hasRow) {
        var rowCardinality = encoding.cardinality(consts_1.Enctype.ROW, stats);
        height = cellHeight * ((1 + cellPadding) * (rowCardinality - 1) + 1);
    }
    return {
        cellWidth: cellWidth,
        cellHeight: cellHeight,
        cellPadding: cellPadding,
        width: width,
        height: height,
        x: { useSmallBand: useSmallBand },
        y: { useSmallBand: useSmallBand }
    };
}
function getMaxNumberLength(encoding, et, fieldStats) {
    var format = encoding.numberFormat(et);
    return d3_format.format(format)(fieldStats.max).length;
}
function getMaxLength(encoding, stats, et) {
    var encDef = encoding.encDef(et), fieldStats = stats[encDef.name];
    if (encDef.bin) {
        return getMaxNumberLength(encoding, et, fieldStats);
    }
    if (encoding.isType(et, consts_1.Type.Q)) {
        return getMaxNumberLength(encoding, et, fieldStats);
    }
    else if (encoding.isType(et, consts_1.Type.T)) {
        return time.maxLength(encoding.encDef(et).timeUnit, encoding);
    }
    else Eif (encoding.isTypes(et, [consts_1.Type.N, consts_1.Type.O])) {
        Iif (fieldStats.type === 'number') {
            return getMaxNumberLength(encoding, et, fieldStats);
        }
        else {
            return Math.min(fieldStats.max, encoding.axis(et).labelMaxLength || Infinity);
        }
    }
}
function offset(encoding, stats, layout) {
    [consts_1.Enctype.X, consts_1.Enctype.Y].forEach(function (et) {
        var extraOffset = et === consts_1.Enctype.X ? 20 : 22, maxLength;
        if (encoding.isDimension(et) || encoding.isType(et, consts_1.Type.T)) {
            maxLength = getMaxLength(encoding, stats, et);
        }
        else if (encoding.isType(et, consts_1.Type.Q) ||
            encoding.encDef(et).aggregate === 'count') {
            if (et === consts_1.Enctype.Y) {
                maxLength = getMaxLength(encoding, stats, et);
            }
        }
        else {
        }
        if (maxLength) {
            util_1.setter(layout, [et, 'axisTitleOffset'], encoding.config('characterWidth') * maxLength + extraOffset);
        }
        else {
            util_1.setter(layout, [et, 'axisTitleOffset'], encoding.config('characterWidth') * 3 + extraOffset);
        }
    });
    return layout;
}
//# sourceMappingURL=layout.js.map