Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
options.fields.forEach(function (fieldOption: FieldOption) {
// get the fieldDef in vlSpec that matches the fieldOption
const fieldDef = getFieldDef(vl.spec.fieldDefs(vlSpec), fieldOption);
// supplement the fieldOption with fieldDef and config
const supplementedFieldOption = supplementFieldOption(fieldOption, fieldDef, vlSpec.config, normalizedVlSpec);
supplementedFields.push(supplementedFieldOption);
});
}
vl.fieldDef.field(fieldDef) : fieldOption.field;
// If a fieldDef is a (TIMEUNIT)T, we check if the original T is present in the vlSpec.
// If only (TIMEUNIT)T is present in vlSpec, we set `removeOriginalTemporalField` to T,
// which will cause function removeDuplicateTimeFields() to remove T and only keep (TIMEUNIT)T
// in item data.
// If both (TIMEUNIT)T and T are in vlSpec, we set `removeOriginalTemporalField` to undefined,
// which will leave both T and (TIMEUNIT)T in item data.
// Note: user should never have to provide this boolean in options
if (fieldDef.type === TEMPORAL && fieldDef.timeUnit) {
// in most cases, if it's a (TIMEUNIT)T, we remove original T
var originalTemporalField = fieldDef.field;
supplementedFieldOption.removeOriginalTemporalField = originalTemporalField;
// handle corner case: if T is present in vlSpec, then we keep both T and (TIMEUNIT)T
var fieldDefs = vl.spec.fieldDefs(vlSpec);
for (var i = 0; i < fieldDefs.length; i++) {
if (fieldDefs[i].field === originalTemporalField && !fieldDefs[i].timeUnit) {
supplementedFieldOption.removeOriginalTemporalField = undefined;
break;
}
}
}
// supplement title
if (!config.countTitle) config.countTitle = vl.config.defaultConfig.countTitle; // use vl default countTitle
supplementedFieldOption.title = fieldOption.title ?
fieldOption.title : vl.fieldDef.title(fieldDef, config);
// supplement formatType
supplementedFieldOption.formatType = fieldOption.formatType ?
supplementedFieldOption.field = vl.fieldDef.vgField(fieldDef) || fieldOption.field;
// If a fieldDef is a (TIMEUNIT)T, we check if the original T is present in the vlSpec.
// If only (TIMEUNIT)T is present in vlSpec, we set `removeOriginalTemporalField` to T,
// which will cause function removeDuplicateTimeFields() to remove T and only keep (TIMEUNIT)T
// in item data.
// If both (TIMEUNIT)T and T are in vlSpec, we set `removeOriginalTemporalField` to undefined,
// which will leave both T and (TIMEUNIT)T in item data.
// Note: user should never have to provide this boolean in options
if (fieldDef.type === TEMPORAL && fieldDef.timeUnit) {
// in most cases, if it's a (TIMEUNIT)T, we remove original T
const originalTemporalField = fieldDef.field;
supplementedFieldOption.removeOriginalTemporalField = originalTemporalField;
// handle corner case: if T is present in vlSpec, then we keep both T and (TIMEUNIT)T
const fieldDefs = vl.spec.fieldDefs(vlSpec);
for (const items of fieldDefs) {
if (items.field === originalTemporalField && !items.timeUnit) {
supplementedFieldOption.removeOriginalTemporalField = undefined;
break;
}
}
}
// supplement title
if (!config.countTitle) {
config.countTitle = vl.config.defaultConfig.countTitle; // use vl default countTitle
}
let defaultTitle = vl.fieldDef.title(fieldDef, config);
if (isPositionFieldDef(fieldDef)) {
if (fieldDef.axis && fieldDef.axis.title) {
defaultTitle = fieldDef.axis.title;
options.fields.forEach(function (fieldOption) {
// get the fieldDef in vlSpec that matches the fieldOption
var fieldDef = getFieldDef(vl.spec.fieldDefs(vlSpec), fieldOption);
// supplement the fieldOption with fieldDef and config
var supplementedFieldOption = supplementFieldOption(fieldOption, fieldDef, vlSpec);
supplementedFields.push(supplementedFieldOption);
})
}