Code coverage report for src/compile/filter.js

Statements: 74.19% (23 / 31)      Branches: 42.86% (6 / 14)      Functions: 100% (3 / 3)      Lines: 74.19% (23 / 31)      Ignored: none     

All files » src/compile/ » filter.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    1   1   1                 1 2   2 2     2 4   4 4 4   4   4                 4   4 4 4               4           2       1 2 6                  
'use strict';
 
require('../globals');
 
var filter = module.exports = {};
 
var BINARY = {
  '>':  true,
  '>=': true,
  '=':  true,
  '!=': true,
  '<':  true,
  '<=': true
};
 
filter.addFilters = function(rawTable, encoding) {
  var filters = encoding.filter();  // apply filters to raw data before aggregation
 
  Eif (!rawTable.transform)
    rawTable.transform = [];
 
  // add custom filters
  for (var i in filters) {
    var filter = filters[i];
 
    var condition = '';
    var operator = filter.operator;
    var operands = filter.operands;
 
    var d = 'd.' + (encoding._vega2 ? '' : 'data.');
 
    Iif (BINARY[operator]) {
      // expects a field and a value
      if (operator === '=') {
        operator = '==';
      }
 
      var op1 = operands[0];
      var op2 = operands[1];
      condition = d + op1 + operator + op2;
    } else Eif (operator === 'notNull') {
      // expects a number of fields
      for (var j in operands) {
        condition += d + operands[j] + '!==null';
        Iif (j < operands.length - 1) {
          condition += ' && ';
        }
      }
    } else {
      console.warn('Unsupported operator: ', operator);
    }
 
    rawTable.transform.push({
      type: 'filter',
      test: condition
    });
  }
 
  return rawTable;
};
 
// remove less than 0 values if we use log function
filter.filterLessThanZero = function(dataTable, encoding) {
  encoding.forEach(function(field, encType) {
    Iif (encoding.scale(encType).type === 'log') {
      dataTable.transform.push({
        type: 'filter',
        test: 'd.' + encoding.field(encType) + '>0'
      });
    }
  });
};