Code coverage report for src/compiler/compiler.js

Statements: 95.38% (62 / 65)      Branches: 85% (34 / 40)      Functions: 80% (4 / 5)      Lines: 95.38% (62 / 65)      Ignored: none     

All files » src/compiler/ » compiler.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      1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 42   1   1     1   1 42 3 3 6 6             42 42                                       42 42     42 42 42 42 9   42 42 42 4   42 10 10 4   10   42 43   42 42 6 6 4       36 36 36 34   36 33   36 36   36 13     42   1    
/**
 * Module for compiling Vega-lite spec into Vega spec.
 */
var util_1 = require('../util');
var Encoding_1 = require('../Encoding');
var scale = require('./scale');
var time = require('./time');
var axis_1 = require('./axis');
var legend_1 = require('./legend');
var marks_1 = require('./marks');
var data_1 = require('./data');
var facet_1 = require('./facet');
var layout_1 = require('./layout');
var stack_1 = require('./stack');
var style_1 = require('./style');
var subfacet_1 = require('./subfacet');
var consts_1 = require('../consts');
function compile(spec, stats, theme) {
    return compileEncoding(Encoding_1.default.fromSpec(spec, theme), stats);
}
exports.compile = compile;
;
function shorthand(shorthand, stats, config, theme) {
    return compileEncoding(Encoding_1.default.fromShorthand(shorthand, config, theme), stats);
}
exports.shorthand = shorthand;
;
function compileEncoding(encoding, stats) {
    if (!stats) {
        Eif (encoding.hasValues()) {
            stats = util_1.summary(encoding.data().values).reduce(function (s, p) {
                s[p.field] = p;
                return s;
            }, {});
        }
        else {
            console.error('No stats provided and data is not embedded.');
        }
    }
    var layout = layout_1.default(encoding, stats);
    var output = {
        width: layout.width,
        height: layout.height,
        padding: 'auto',
        data: data_1.default(encoding),
        marks: [{
                name: 'cell',
                type: 'group',
                properties: {
                    enter: {
                        width: layout.cellWidth ?
                            { value: layout.cellWidth } :
                            { field: { group: 'width' } },
                        height: layout.cellHeight ?
                            { value: layout.cellHeight } :
                            { field: { group: 'height' } }
                    }
                }
            }]
    };
    var timeScales = time.scales(encoding);
    Iif (timeScales.length > 0) {
        output.scales = timeScales;
    }
    var group = output.marks[0];
    var styleCfg = style_1.default(encoding, stats), mdefs = group.marks = marks_1.default(encoding, layout, styleCfg), mdef = mdefs[mdefs.length - 1];
    var stack = encoding.stack();
    if (stack) {
        stack_1.default(encoding, mdef, stack);
    }
    var lineType = marks_1.getMark(encoding.marktype()).line;
    var details = encoding.details();
    if (details.length > 0 && lineType) {
        subfacet_1.default(group, mdef, details);
    }
    if (lineType && encoding.config('autoSortLine')) {
        var f = (encoding.isMeasure(consts_1.Enctype.X) && encoding.isDimension(consts_1.Enctype.Y)) ? consts_1.Enctype.Y : consts_1.Enctype.X;
        if (!mdef.from) {
            mdef.from = {};
        }
        mdef.from.transform = [{ type: 'sort', by: '-' + encoding.fieldRef(f) }];
    }
    var singleScaleNames = [].concat.apply([], mdefs.map(function (markProps) {
        return scale.names(markProps.properties.update);
    }));
    var legends = legend_1.default(encoding, styleCfg);
    if (encoding.has(consts_1.Enctype.ROW) || encoding.has(consts_1.Enctype.COL)) {
        output = facet_1.default(group, encoding, layout, output, singleScaleNames, stats);
        if (legends.length > 0) {
            output.legends = legends;
        }
    }
    else {
        group.scales = scale.defs(singleScaleNames, encoding, layout, stats);
        var axes = [];
        if (encoding.has(consts_1.Enctype.X)) {
            axes.push(axis_1.default(consts_1.Enctype.X, encoding, layout, stats));
        }
        if (encoding.has(consts_1.Enctype.Y)) {
            axes.push(axis_1.default(consts_1.Enctype.Y, encoding, layout, stats));
        }
        Eif (axes.length > 0) {
            group.axes = axes;
        }
        if (legends.length > 0) {
            group.legends = legends;
        }
    }
    return output;
}
exports.compileEncoding = compileEncoding;
;
//# sourceMappingURL=compiler.js.map