Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
export function normalize(channelDef: ChannelDef, channel: Channel): ChannelDef {
if (isString(channelDef) || isNumber(channelDef) || isBoolean(channelDef)) {
const primitiveType = isString(channelDef) ? 'string' : isNumber(channelDef) ? 'number' : 'boolean';
log.warn(log.message.primitiveChannelDef(channel, primitiveType, channelDef));
return {value: channelDef};
}
// If a fieldDef contains a field, we need type.
if (isFieldDef(channelDef)) {
return normalizeFieldDef(channelDef, channel);
} else if (hasConditionalFieldDef(channelDef)) {
return {
...channelDef,
// Need to cast as normalizeFieldDef normally return FieldDef, but here we know that it is definitely Condition
condition: normalizeFieldDef(channelDef.condition, channel) as Conditional>
};
}
return channelDef;
export function normalize(channelDef, channel) {
if (isString(channelDef) || isNumber(channelDef) || isBoolean(channelDef)) {
const primitiveType = isString(channelDef) ? 'string' : isNumber(channelDef) ? 'number' : 'boolean';
log.warn(log.message.primitiveChannelDef(channel, primitiveType, channelDef));
return { value: channelDef };
}
// If a fieldDef contains a field, we need type.
if (isFieldDef(channelDef)) {
return normalizeFieldDef(channelDef, channel);
}
else if (hasConditionalFieldDef(channelDef)) {
return Object.assign({}, channelDef, {
// Need to cast as normalizeFieldDef normally return FieldDef, but here we know that it is definitely Condition
condition: normalizeFieldDef(channelDef.condition, channel) });
}
return channelDef;
}
export function normalizeFieldDef(fieldDef, channel) {
// if fielddef is a repeat, just include it in the stack by
!f ||
// otherwise, the field must be different from x and y fields.
(f !== dimensionField && f !== stackedField)
) {
sc.push({channel, fieldDef});
}
});
}
return sc;
}, []);
// Automatically determine offset
let offset: StackOffset;
if (stackedFieldDef.stack !== undefined) {
if (isBoolean(stackedFieldDef.stack)) {
offset = stackedFieldDef.stack ? 'zero' : null;
} else {
offset = stackedFieldDef.stack;
}
} else if (stackBy.length > 0 && contains(STACK_BY_DEFAULT_MARKS, mark)) {
// Bar and Area with sum ops are automatically stacked by default
offset = 'zero';
}
if (!offset || !isStackOffset(offset)) {
return null;
}
if (isAggregate(encoding) && stackBy.length === 0) {
return null;
}
export function binToString(bin) {
if (isBoolean(bin)) {
bin = normalizeBin(bin, undefined);
}
return ('bin' +
keys(bin)
.map(p => varName(`_${p}_${bin[p]}`))
.join(''));
}
/**
export function normalizeBin(bin: BinParams | boolean | 'binned', channel?: Channel) {
if (isBoolean(bin)) {
return {maxbins: autoMaxBins(channel)};
} else if (bin === 'binned') {
return {
binned: true
};
} else if (!bin.maxbins && !bin.step) {
return {...bin, maxbins: autoMaxBins(channel)};
} else {
return bin;
}
}
const {clip, color, opacity} = markDef;
const mark = markDef.type;
if (markDef[part] || (markDef[part] === undefined && compositeMarkConfig[part])) {
return [
{
...partBaseSpec,
mark: {
...(compositeMarkConfig[part] as MarkConfig),
...(clip ? {clip} : {}),
...(color ? {color} : {}),
...(opacity ? {opacity} : {}),
...(isMarkDef(partBaseSpec.mark) ? partBaseSpec.mark : {type: partBaseSpec.mark}),
style: `${mark}-${part}`,
...(isBoolean(markDef[part]) ? {} : (markDef[part] as MarkConfig))
}
}
];
}
return [];
}
export function partLayerMixins(markDef, part, compositeMarkConfig, partBaseSpec) {
const { clip, color, opacity } = markDef;
const mark = markDef.type;
if (markDef[part] || (markDef[part] === undefined && compositeMarkConfig[part])) {
return [
Object.assign({}, partBaseSpec, { mark: Object.assign({}, compositeMarkConfig[part], (clip ? { clip } : {}), (color ? { color } : {}), (opacity ? { opacity } : {}), (isMarkDef(partBaseSpec.mark) ? partBaseSpec.mark : { type: partBaseSpec.mark }), { style: `${mark}-${part}` }, (isBoolean(markDef[part]) ? {} : markDef[part])) })
];
}
return [];
}
export function compositeMarkContinuousAxis(spec, orient, compositeMark) {
export function normalizeBin(bin, channel) {
if (isBoolean(bin)) {
return { maxbins: autoMaxBins(channel) };
}
else if (bin === 'binned') {
return {
binned: true
};
}
else if (!bin.maxbins && !bin.step) {
return Object.assign({}, bin, { maxbins: autoMaxBins(channel) });
}
else {
return bin;
}
}
const COMPATIBLE = { compatible: true };
export function binToString(bin: BinParams | true) {
if (isBoolean(bin)) {
bin = normalizeBin(bin, undefined);
}
return (
'bin' +
keys(bin)
.map(p => (isSelectionExtent(bin[p]) ? varName(`_${p}_${Object.entries(bin[p])}`) : varName(`_${p}_${bin[p]}`)))
.join('')
);
}