'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;
}
|