Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
// TODO support array of f._aggrs too
assignAggrQ(i, hasAggr, autoMode, f._aggregate);
} else if (f._raw) {
assignAggrQ(i, hasAggr, autoMode, undefined);
} else if (f._bin) {
assignBinQ(i, hasAggr, autoMode);
} else {
opt.aggrList.forEach(function(a) {
if (!opt.consistentAutoQ || autoMode === AUTO || autoMode === a) {
assignAggrQ(i, hasAggr, a /*assign autoMode*/, a);
}
});
if ((!opt.consistentAutoQ || util.isin(autoMode, [AUTO, 'bin', 'cast', 'autocast'])) && !hasNorO) {
// Constraint: Bin a field only if its cardinality is above certain threshold
var highCardinality = vlFieldDef.cardinality(f, stats) > opt.minCardinalityForBin;
var isAuto = opt.genDimQ === QuantitativeDimensionType.AUTO,
genBin = opt.genDimQ === QuantitativeDimensionType.BIN || (isAuto && highCardinality),
genCast = opt.genDimQ === QuantitativeDimensionType.CAST || (isAuto && !highCardinality);
if (genBin && util.isin(autoMode, [AUTO, 'bin', 'autocast'])) {
assignBinQ(i, hasAggr, isAuto ? 'autocast' : 'bin');
}
if (genCast && util.isin(autoMode, [AUTO, 'cast', 'autocast'])) {
tf[i].type = Type.ORDINAL;
assignField(i + 1, hasAggr, isAuto ? 'autocast' : 'cast');
tf[i].type = Type.QUANTITATIVE;
}
}
}
}export function color(encoding: Encoding, fieldDef: FieldDef, stats, opt: SpecOption) {
// Don't use color if omitMultipleRetinalEncodings is true and we already have other retinal encoding
if (!retinalEncRules(encoding, fieldDef, stats, opt)) {
return false;
}
// Color must be either measure or dimension with cardinality lower than the max cardinality
return isMeasure(fieldDef) ||
cardinality(fieldDef, stats) <= opt.maxCardinalityForColor;
}if (isDimension(fieldDef) ||
(fieldDef.type === TEMPORAL /* TODO: add && current constraint make it a dimension */)) {
// If the field can serve as dimension
// FIXME vega-lite's isDimension is designed to work with FieldDef, not SchemaField
// Therefore, we should augment vega-lite's isDimension
hasSelectedDimension = true;
} else {
hasSelectedMeasure = true;
}
} else if (fieldDef.selected !== false && !vlFieldDef.isCount(fieldDef)) {
// Constraint: Do not add high cardinality O/N
if (vlFieldDef.isDimension(fieldDef) &&
!opt.maxCardinalityForAutoAddOrdinal &&
vlFieldDef.cardinality(fieldDef, stats, 15) > opt.maxCardinalityForAutoAddOrdinal
) {
return;
}
fieldsToAdd.push(fieldDef);
}
});export function shape(encoding: Encoding, fieldDef: FieldDef, stats, opt: SpecOption) {
if (!retinalEncRules(encoding, fieldDef, stats, opt)) {
return false;
}
// TODO: remove this because we can only bin quantitative, and we don't support quantitative for shape anyway
if (opt.omitShapeWithBin && fieldDef.bin && fieldDef.type === Type.QUANTITATIVE) {
return false;
}
if (opt.omitShapeWithTimeDimension && fieldDef.timeUnit && fieldDef.type === Type.TEMPORAL) {
return false;
}
// TODO: omit shape with ordinal
return cardinality(fieldDef, stats) <= opt.maxCardinalityForShape;
}export let dimensionScore:any = function(fieldDef, channel, mark, stats, opt){
var cardinality = vlFieldDef.cardinality(fieldDef, stats);
switch (channel) {
case vlChannel.X:
if (fieldDef.type === Type.NOMINAL || fieldDef.type === Type.ORDINAL) {
return D.pos - D.minor;
}
return D.pos;
case vlChannel.Y:
if (fieldDef.type === Type.NOMINAL || fieldDef.type === Type.ORDINAL) {
return D.pos - D.minor; // prefer ordinal on y
}
if (fieldDef.type === Type.TEMPORAL) {
return D.Y_T; // time should not be on Y
}
return D.pos - D.minor;function facetRule(fieldDef, stats, opt: SpecOption) {
return cardinality(fieldDef, stats) <= opt.maxCardinalityForFacets;
}