Code coverage report for src/compile/legend.js

Statements: 68.18% (15 / 22)      Branches: 31.03% (9 / 29)      Functions: 100% (2 / 2)      Lines: 68.18% (15 / 22)      Ignored: none     

All files » src/compile/ » 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    1   1   1   1 2     2 2           2             2                       2     1 2   2   2                 2    
'use strict';
 
require('../globals');
 
var time = require('./time');
 
var legend = module.exports = {};
 
legend.defs = function(encoding) {
  var defs = [];
  // TODO: support alpha
 
  Eif (encoding.has(COLOR) && encoding.legend(COLOR)) {
    defs.push(legend.def(COLOR, encoding, {
      fill: COLOR,
      orient: 'right'
    }));
  }
 
  Iif (encoding.has(SIZE) && encoding.legend(SIZE)) {
    defs.push(legend.def(SIZE, encoding, {
      size: SIZE,
      orient: defs.length === 1 ? 'left' : 'right'
    }));
  }
 
  Iif (encoding.has(SHAPE) && encoding.legend(SHAPE)) {
    if (defs.length === 2) {
      // TODO: fix this
      console.error('Vega-lite currently only supports two legends');
      return defs;
    }
    defs.push(legend.def(SHAPE, encoding, {
      shape: SHAPE,
      orient: defs.length === 1 ? 'left' : 'right'
    }));
  }
 
  return defs;
};
 
legend.def = function(name, encoding, props) {
  var def = props, timeUnit;
 
  def.title = encoding.fieldTitle(name);
 
  Iif (encoding.isType(name, T) && (timeUnit = encoding.timeUnit(name)) &&
    time.hasScale(timeUnit)) {
    var properties = def.properties = def.properties || {},
      labels = properties.labels = properties.labels || {},
      text = labels.text = labels.text || {};
 
    text.scale = 'time-'+ timeUnit;
  }
 
  return def;
};