Code coverage report for src/compiler/style.js

Statements: 96.77% (30 / 31)      Branches: 96.15% (25 / 26)      Functions: 100% (3 / 3)      Lines: 96.77% (30 / 31)      Ignored: none     

All files » src/compiler/ » style.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    1   1   1 36         1 36       36   36 21             21   54       36             15 2   13     13 13 1   13 1   13     34 34 18 16 8 8 5   3     34      
'use strict';
 
require('../globals');
 
var vlEncDef = require('../encdef');
 
module.exports = function(encoding, stats) {
  return {
    opacity: estimateOpacity(encoding, stats),
  };
};
 
function estimateOpacity(encoding,stats) {
  Iif (!stats) {
    return 1;
  }
 
  var numPoints = 0;
 
  if (encoding.isAggregate()) { // aggregate plot
    numPoints = 1;
 
    //  get number of points in each "cell"
    //  by calculating product of cardinality
    //  for each non faceting and non-ordinal X / Y fields
    //  note that ordinal x,y are not include since we can
    //  consider that ordinal x are subdividing the cell into subcells anyway
    encoding.forEach(function(encDef, encType) {
 
      if (encType !== ROW && encType !== COL &&
          !((encType === X || encType === Y) &&
          vlEncDef.isOrdinalScale(encDef))
        ) {
        numPoints *= encoding.cardinality(encType, stats);
      }
    });
 
  } else { // raw plot
 
    // TODO: error handling
    if (!stats['*'])
      return 1;
 
    numPoints = stats['*'].max;  // count
 
    // small multiples divide number of points
    var numMultiples = 1;
    if (encoding.has(ROW)) {
      numMultiples *= encoding.cardinality(ROW, stats);
    }
    if (encoding.has(COL)) {
      numMultiples *= encoding.cardinality(COL, stats);
    }
    numPoints /= numMultiples;
  }
 
  var opacity = 0;
  if (numPoints <= 25) {
    opacity = 1;
  } else if (numPoints < 200) {
    opacity = 0.8;
  } else if (numPoints < 1000 || encoding.is('tick')) {
    opacity = 0.7;
  } else {
    opacity = 0.3;
  }
 
  return opacity;
}