Code coverage report for src/compile/style.js

Statements: 62.07% (18 / 29)      Branches: 62.5% (15 / 24)      Functions: 100% (3 / 3)      Lines: 62.07% (18 / 29)      Ignored: none     

All files » src/compile/ » 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    1   1   1 2         1 2       2   2 2             2   6       4                                   2 2   2   2     2     2      
'use strict';
 
require('../globals');
 
var vlfield = require('../field');
 
module.exports = function(encoding, stats) {
  return {
    opacity: estimateOpacity(encoding, stats),
  };
};
 
function estimateOpacity(encoding,stats) {
  Iif (!stats) {
    return 1;
  }
 
  var numPoints = 0;
 
  Eif (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(field, encType) {
 
      if (encType !== ROW && encType !== COL &&
          !((encType === X || encType === Y) &&
          vlfield.isOrdinalScale(field))
        ) {
        numPoints *= encoding.cardinality(encType, stats);
      }
    });
 
  } else { // raw plot
    numPoints = stats.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;
  Iif (numPoints < 20) {
    opacity = 1;
  } else Iif (numPoints < 200) {
    opacity = 0.7;
  } else Iif (numPoints < 1000 || encoding.is('tick')) {
    opacity = 0.6;
  } else {
    opacity = 0.3;
  }
 
  return opacity;
}