Code coverage report for src/compiler/legend.js

Statements: 88.46% (46 / 52)      Branches: 73.17% (30 / 41)      Functions: 100% (4 / 4)      Lines: 88.46% (46 / 52)      Ignored: none     

All files » src/compiler/ » legend.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 921 1 1 1 42 42 14       42 2       42 1       42   1 1   1 17 17 17 17 17         17   1   1 17 17       9 9 9         5                   5 2     3   5 5   5     3   17 17 17   17     1 19 19 1 18   1    
var util_1 = require('../util');
var consts_1 = require('../consts');
var time = require('./time');
function default_1(encoding, styleCfg) {
    var defs = [];
    if (encoding.has(consts_1.Enctype.COLOR) && encoding.encDef(consts_1.Enctype.COLOR).legend) {
        defs.push(def(consts_1.Enctype.COLOR, encoding, {
            fill: consts_1.Enctype.COLOR
        }, styleCfg));
    }
    if (encoding.has(consts_1.Enctype.SIZE) && encoding.encDef(consts_1.Enctype.SIZE).legend) {
        defs.push(def(consts_1.Enctype.SIZE, encoding, {
            size: consts_1.Enctype.SIZE
        }, styleCfg));
    }
    if (encoding.has(consts_1.Enctype.SHAPE) && encoding.encDef(consts_1.Enctype.SHAPE).legend) {
        defs.push(def(consts_1.Enctype.SHAPE, encoding, {
            shape: consts_1.Enctype.SHAPE
        }, styleCfg));
    }
    return defs;
}
Object.defineProperty(exports, "__esModule", { value: true });
exports.default = default_1;
;
function def(name, encoding, def, styleCfg) {
    var timeUnit = encoding.encDef(name).timeUnit;
    def.title = title(name, encoding);
    def.orient = encoding.encDef(name).legend.orient;
    def = style(name, encoding, def, styleCfg);
    Iif (encoding.isType(name, consts_1.Type.T) &&
        timeUnit &&
        time.hasScale(timeUnit)) {
        util_1.setter(def, ['properties', 'labels', 'text', 'scale'], 'time-' + timeUnit);
    }
    return def;
}
exports.def = def;
;
function style(name, e, def, styleCfg) {
    var symbols = util_1.getter(def, ['properties', 'symbols']), marktype = e.marktype();
    switch (marktype) {
        case 'bar':
        case 'tick':
        case 'text':
            symbols.stroke = { value: 'transparent' };
            symbols.shape = { value: 'square' };
            break;
        case 'circle':
        case 'square':
            symbols.shape = { value: marktype };
        case 'point':
            Iif (e.encDef(consts_1.Enctype.SHAPE).filled) {
                if (e.has(consts_1.Enctype.COLOR) && name === consts_1.Enctype.COLOR) {
                    symbols.fill = { scale: consts_1.Enctype.COLOR, field: 'data' };
                }
                else {
                    symbols.fill = { value: e.value(consts_1.Enctype.COLOR) };
                }
                symbols.stroke = { value: 'transparent' };
            }
            else {
                if (e.has(consts_1.Enctype.COLOR) && name === consts_1.Enctype.COLOR) {
                    symbols.stroke = { scale: consts_1.Enctype.COLOR, field: 'data' };
                }
                else {
                    symbols.stroke = { value: e.value(consts_1.Enctype.COLOR) };
                }
                symbols.fill = { value: 'transparent' };
                symbols.strokeWidth = { value: e.config('strokeWidth') };
            }
            break;
        case 'line':
        case 'area':
            break;
    }
    var opacity = e.encDef(consts_1.Enctype.COLOR).opacity || styleCfg.opacity;
    Eif (opacity) {
        symbols.opacity = { value: opacity };
    }
    return def;
}
;
function title(name, encoding) {
    var leg = encoding.encDef(name).legend;
    if (leg.title)
        return leg.title;
    return encoding.fieldTitle(name);
}
exports.title = title;
;
//# sourceMappingURL=legend.js.map