Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
Object.keys(upspec).forEach(function(key) {
let specVal = upspec[key],
origVal = up[key],
origScale = origVal.scale;
if (!isObject(specVal)) {
// signalRef resolved to literal
specVal = upspec[key] = {value: specVal};
}
// Use the origVal to determine if scale/fields have been set in case
// specVal was replaced above (e.g., scale + signal).
if (origScale) {
specVal.scale = name(getInVis(state, 'scales.' + origScale + '.name'));
count = counts.scales[origScale] || (counts.scales[origScale] = duplicate(SCALE_COUNT));
count.marks[id] = true;
}
if (origVal.group) {
specVal.field = {group: origVal.group};
delete specVal.group;
}
exporter.scale = function(state: State, internal: boolean, id: number) {
const scale = getInVis(state, 'scales.' + id).toJS(),
spec = clean(duplicate(scale), internal);
counts.scales[id] = counts.scales[id] || duplicate(SCALE_COUNT);
if (!scale.domain && scale._domain && scale._domain.length) {
spec.domain = dataRef(state, scale, scale._domain);
}
if (!scale.range && scale._range && scale._range.length) {
spec.range = dataRef(state, scale, scale._range);
}
// TODO: Sorting multiple datasets?
const sortOrder = isObject(spec.domain) && spec.domain._sortOrder;
if (sortOrder) {
spec.reverse = sortOrder === ORDER.DESC ? !spec.reverse : !!spec.reserve;
}
return spec;
};
Object.keys(def).forEach(function(key) {
if (!isObject(def[key])) {
// signalRef resolved to literal
def[key] = {value: def[key]};
}
});
});
function clean(spec, internal: boolean) {
let cleanKey;
for (const [key, prop] of Object.entries(spec)) {
cleanKey = key.startsWith('_');
cleanKey = cleanKey || prop === null || prop === undefined || (prop as any)._disabled;
if (cleanKey) {
delete spec[key];
} else if (key === 'name' && isString(prop)) {
spec[key] = name(prop);
} else if (isObject(prop)) {
if ((prop as any).signal && !internal) {
// Render signals to their value
spec[key] = signalLookup((prop as any).signal);
} else {
// Recurse
spec[key] = clean(spec[key], internal);
}
}
}
return spec;
}