Code coverage report for src/compiler/legend.js

Statements: 87.5% (42 / 48)      Branches: 73.17% (30 / 41)      Functions: 100% (4 / 4)      Lines: 87.23% (41 / 47)      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 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109    1   1         1   1 36   36 13         36 2         36 1       36     1 16   16 16   16   16             16     1 16     16       8 8 8               5               5 2   3   5 5     5       3     16 16 16   16     1 18   18   17    
'use strict';
 
require('../globals');
 
var time = require('./time'),
  util = require('../util'),
  setter = util.setter,
  getter = util.getter;
 
var legend = module.exports = {};
 
legend.defs = function(encoding, style) {
  var defs = [];
 
  if (encoding.has(COLOR) && encoding.encDef(COLOR).legend) {
    defs.push(legend.def(COLOR, encoding, {
      fill: COLOR
    }, style));
  }
 
  if (encoding.has(SIZE) && encoding.encDef(SIZE).legend) {
    defs.push(legend.def(SIZE, encoding, {
      size: SIZE
    }, style));
  }
 
  if (encoding.has(SHAPE) && encoding.encDef(SHAPE).legend) {
    defs.push(legend.def(SHAPE, encoding, {
      shape: SHAPE
    }, style));
  }
  return defs;
};
 
legend.def = function(name, encoding, def, style) {
  var timeUnit = encoding.encDef(name).timeUnit;
 
  def.title = legend.title(name, encoding);
  def.orient = encoding.encDef(name).legend.orient;
 
  def = legend.style(name, encoding, def, style);
 
  Iif (encoding.isType(name, T) &&
    timeUnit &&
    time.hasScale(timeUnit)
  ) {
    setter(def, ['properties', 'labels', 'text', 'scale'], 'time-'+ timeUnit);
  }
 
  return def;
};
 
legend.style = function(name, e, def, style) {
  var symbols = 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};
      /* fall through */
    case 'point':
      // fill or stroke
      Iif (e.encDef(SHAPE).filled) {
        if (e.has(COLOR) && name === COLOR) {
          symbols.fill = {scale: COLOR, field: 'data'};
        } else {
          symbols.fill = {value: e.value(COLOR)};
        }
        symbols.stroke = {value: 'transparent'};
      } else {
        if (e.has(COLOR) && name === COLOR) {
          symbols.stroke = {scale: COLOR, field: 'data'};
        } else {
          symbols.stroke = {value: e.value(COLOR)};
        }
        symbols.fill = {value: 'transparent'};
        symbols.strokeWidth = {value: e.config('strokeWidth')};
      }
 
      break;
    case 'line':
    case 'area':
      // TODO use shape here after implementing #508
      break;
  }
 
  var opacity = e.encDef(COLOR).opacity || style.opacity;
  Eif (opacity) {
    symbols.opacity = {value: opacity};
  }
  return def;
};
 
legend.title = function(name, encoding) {
  var leg = encoding.encDef(name).legend;
 
  if (leg.title) return leg.title;
 
  return encoding.fieldTitle(name);
};