Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
): ShelfFunction | Wildcard {
// FIXME make this a parameter
const config = DEFAULT_QUERY_CONFIG;
const {aggregate, bin, hasFn, timeUnit} = fieldQParts;
let fns: ShelfFunction[] = [];
let fn: ShelfFunction;
let hasUndefinedInEnum = false;
if (bin) {
if (isWildcard(bin)) {
const bins = isShortWildcard(bin) ? [true, false] : bin.enum;
fns = fns.concat(contains(bins, true) ? ['bin'] : []);
hasUndefinedInEnum = hasUndefinedInEnum || contains(bins, false);
} else if (bin) {
fn = 'bin';
}
}
if (aggregate) {
if (isWildcard(aggregate)) {
const aggregates = isShortWildcard(aggregate) ? config.enum.aggregate : aggregate.enum;
fns = fns.concat(
// We already filter composite aggregate function so it is fine to cast here
// as the only thing left would be AggregateOp (but TS would not know that)
aggregates.filter(excludeUndefined) as AggregateOp[]
);
hasUndefinedInEnum = hasUndefinedInEnum || contains(aggregates, undefined);
} else if (!fn) {
fn = aggregate;fieldQParts: FieldQueryFunctionMixins
): ShelfFunction | Wildcard {
// FIXME make this a parameter
const config = DEFAULT_QUERY_CONFIG;
const {aggregate, bin, hasFn, timeUnit} = fieldQParts;
let fns: ShelfFunction[] = [];
let fn: ShelfFunction;
let hasUndefinedInEnum = false;
if (bin) {
if (isWildcard(bin)) {
const bins = isShortWildcard(bin) ? [true, false] : bin.enum;
fns = fns.concat(contains(bins, true) ? ['bin'] : []);
hasUndefinedInEnum = hasUndefinedInEnum || contains(bins, false);
} else if (bin) {
fn = 'bin';
}
}
if (aggregate) {
if (isWildcard(aggregate)) {
const aggregates = isShortWildcard(aggregate) ? config.enum.aggregate : aggregate.enum;
fns = fns.concat(
// We already filter composite aggregate function so it is fine to cast here
// as the only thing left would be AggregateOp (but TS would not know that)
aggregates.filter(excludeUndefined) as AggregateOp[]
);
hasUndefinedInEnum = hasUndefinedInEnum || contains(aggregates, undefined);
} else if (!fn) {// as the only thing left would be AggregateOp (but TS would not know that)
aggregates.filter(excludeUndefined) as AggregateOp[]
);
hasUndefinedInEnum = hasUndefinedInEnum || contains(aggregates, undefined);
} else if (!fn) {
fn = aggregate;
} else {
throw Error(`Invalid field with function ${fn} and ${aggregate}`);
}
}
if (timeUnit) {
if (isWildcard(timeUnit)) {
const timeUnits = isShortWildcard(timeUnit) ? config.enum.timeUnit : timeUnit.enum;
fns = fns.concat(timeUnits.filter(excludeUndefined));
hasUndefinedInEnum = hasUndefinedInEnum || contains(timeUnits, undefined);
} else if (!fn) {
fn = timeUnit;
} else {
throw Error(`Invalid field with function ${fn} and ${timeUnit}`);
}
}
if (fn) {
return fn;
}
if (hasUndefinedInEnum && !hasFn) {
// prepend undefined
fns.unshift(undefined);
}function getSupportedScaleTypes(channel: Channel, fieldDef: ShelfFieldDef): string[] {
switch (fieldDef.type) {
case ExpandedType.QUANTITATIVE:
if (contains([Channel.X, Channel.Y], channel)) {
return ["linear", "log", "pow", "sqrt"];
} else if (channel === Channel.COLOR) {
return ["linear", "pow", "sqrt", "log", "sequential"];
} else if (channel === Channel.SIZE) {
return ["linear", "pow", "sqrt", "log"];
} else {
return [];
}
case ExpandedType.ORDINAL:
case ExpandedType.NOMINAL:
if (contains([Channel.X, Channel.Y], channel)) {
return ["point", "band"];
} else if (channel === Channel.COLOR) {
return ["ordinal"];
} else if (channel === Channel.SIZE) {
return ["point", "band"];
} else {
return [];
}
case ExpandedType.TEMPORAL:
if (contains([Channel.X, Channel.Y], channel)) {
return ["time", "utc"];
} else if (channel === Channel.COLOR) {
return ["time", "utc", "sequential"];
} else if (channel === Channel.SIZE) {
return ["time", "utc"];export function isContinuous(fieldDef: ShelfFieldDef) {
return contains([ExpandedType.ORDINAL, ExpandedType.TEMPORAL, ExpandedType.QUANTITATIVE], fieldDef.type);
}const checkboxradios = supportedFns.map(f => (
<label>
<input value="{f" checked="{isWildcard(fn)" type="{fnIsWildcard">
{' '}
{f || '-'}
</label>
));
}
case ExpandedType.ORDINAL:
case ExpandedType.NOMINAL:
if (contains([Channel.X, Channel.Y], channel)) {
return ["point", "band"];
} else if (channel === Channel.COLOR) {
return ["ordinal"];
} else if (channel === Channel.SIZE) {
return ["point", "band"];
} else {
return [];
}
case ExpandedType.TEMPORAL:
if (contains([Channel.X, Channel.Y], channel)) {
return ["time", "utc"];
} else if (channel === Channel.COLOR) {
return ["time", "utc", "sequential"];
} else if (channel === Channel.SIZE) {
return ["time", "utc"];
} else {
return [];
}
default:
return [];
}
}