Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
function assignField(i, hasAggr, autoMode) {
if (i === fieldDefs.length) { // If all fields are assigned
checkAndPush();
return;
}
var f = fieldDefs[i];
// Otherwise, assign i-th field
switch (f.type) {
// TODO: "D", "G"
case Type.QUANTITATIVE:
assignQ(i, hasAggr, autoMode);
break;
case Type.TEMPORAL:
assignT(i, hasAggr, autoMode);
break;
case Type.ORDINAL:
/* falls through */
case Type.NOMINAL:
/* falls through */
default:
tf[i] = f;
assignField(i + 1, hasAggr, autoMode);
break;
}
}
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;
}
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;
}
}
}
}
function genScaleField(i: number, tmpFieldDefs: SchemaField[]) {
if (i === fieldDefs.length) {
// Done, emit result
output.push(duplicate(tmpFieldDefs));
return;
}
if (fieldDefs[i].type === Type.QUANTITATIVE && opt.rescaleQuantitative && !(fieldDefs[i].bin)) {
// if quantitative and we have rescaleQuantitative, generate different scales
opt.rescaleQuantitative.forEach(function(scaleType) {
// clone to prevent side effect on the original data
if (scaleType) {
let fieldDef = duplicate(fieldDefs[i]);
fieldDef.scale = fieldDef.scale || {};
fieldDef.scale.type = scaleType;
tmpFieldDefs.push(fieldDef);
genScaleField(i + 1, tmpFieldDefs);
} else {
tmpFieldDefs.push(fieldDefs[i]);
genScaleField(i + 1, tmpFieldDefs);
}
tmpFieldDefs.pop();
});
export function line(encoding: Encoding, stats, opt: SpecOption) {
if (!facetsRule(encoding, stats, opt)) return false;
// TODO(kanitw): add omitVerticalLine as config
// FIXME truly ordinal data is fine here too.
// Line chart should be only horizontal
// and use only temporal data
return encoding.x.type === Type.TEMPORAL && !!encoding.x.timeUnit &&
encoding.y.type === Type.QUANTITATIVE && !!encoding.y.aggregate;
}