Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
function getTopLevelProperties(
inputSpec: TopLevel,
autosize: AutoSizeType | AutoSizeParams,
config: Config,
model: Model
) {
const width = model.component.layoutSize.get('width');
const height = model.component.layoutSize.get('height');
if (autosize === undefined) {
autosize = {type: 'pad'};
} else if (isString(autosize)) {
autosize = {type: autosize};
}
if (width && height && isFitType(autosize.type)) {
if (width === 'step' && height === 'step') {
log.warn(log.message.droppingFit());
autosize.type = 'pad';
} else if (width === 'step' || height === 'step') {
// effectively XOR, because else if
// get step dimension
const sizeType = width === 'step' ? 'width' : 'height';
// log that we're dropping fit for respective channel
log.warn(log.message.droppingFit(getPositionScaleChannel(sizeType)));
// setting type to inverse fit (so if we dropped fit-x, type is now fit-y)
const inverseSizeType = sizeType === 'width' ? 'height' : 'width';
assemble() {
let foreign;
if (this.transform.from.fields) {
// lookup a few fields and add create a flat output
foreign = Object.assign({ values: this.transform.from.fields }, (this.transform.as ? { as: this.transform.as instanceof Array ? this.transform.as : [this.transform.as] } : {}));
}
else {
// lookup full record and nest it
let asName = this.transform.as;
if (!isString(asName)) {
log.warn(log.message.NO_FIELDS_NEEDS_AS);
asName = '_lookup';
}
foreign = {
as: [asName]
};
}
return Object.assign({ type: 'lookup', from: this.secondary, key: this.transform.from.key, fields: [this.transform.lookup] }, foreign, (this.transform.default ? { default: this.transform.default } : {}));
}
}
export function fieldInvalidPredicate(field, invalid = true) {
field = isString(field) ? field : vgField(field, { expr: 'datum' });
const op = invalid ? '||' : '&&';
const eq = invalid ? '===' : '!==';
return `${field} ${eq} null ${op} ${invalid ? '' : '!'}isNaN(${field})`;
}
// TODO: we need to find a way to refactor these so that scaleName is a part of scale
function fieldKey(field) {
return isString(field) ? field : null;
}
async function loadOpts(opt: EmbedOptions, loader: Loader): Promise> {
const config: Config = isString(opt.config) ? JSON.parse(await loader.load(opt.config)) : opt.config ?? {};
const patch: PatchFunc | Operation[] = isString(opt.patch) ? JSON.parse(await loader.load(opt.patch)) : opt.patch;
return {
...(opt as any),
...(patch ? { patch } : {}),
...(config ? { config } : {})
};
}
export function fieldInvalidPredicate(field: FieldName | FieldDef, invalid = true) {
return fieldValidPredicate(isString(field) ? field : vgField(field, {expr: 'datum'}), !invalid);
}
compare: p => (value => {
let cmp = value;
if (cmp && isFunction(cmp.toObject)) {
cmp = cmp.toObject();
}
if (isString(cmp)) cmp = array(cmp);
if (isArray(cmp)) cmp = toCompareObject(cmp);
return isObject(cmp) && !isFunction(cmp)
? isFunction(cmp.accessor)
? accessor(cmp.accessor, cmp.fields)
: compare(cmp.fields, cmp.orders)
: error(`Unrecognized comparator value for parameter: ${p.name}.`);
}),
function _normalizeAutoSize(autosize) {
return isString(autosize) ? { type: autosize } : autosize || {};
}
export function normalizeAutoSize(topLevelAutosize, configAutosize, isUnitOrLayer) {