Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
function replaceRepeater(mapping: EncodingOrFacet, repeater: RepeaterValue): EncodingOrFacet {
const out: EncodingOrFacet = {};
for (const channel in mapping) {
if (hasOwnProperty(mapping, channel)) {
const channelDef: ChannelDef> | ChannelDef>[] = mapping[channel];
if (isArray(channelDef)) {
// array cannot have condition
out[channel] = channelDef.map(cd => replaceRepeaterInChannelDef(cd, repeater)).filter(cd => cd);
} else {
const cd = replaceRepeaterInChannelDef(channelDef, repeater);
if (cd !== undefined) {
out[channel] = cd;
}
}
}
}
return out;
}
const outputName = facetSortFieldName(fieldDef, sort);
if (row && column) {
// For crossed facet, use pre-calculate field as it requires a different groupby
// For each calculated field, apply max and assign them to the same name as
// all values of the same group should be the same anyway.
fields.push(outputName);
ops.push('max');
as.push(outputName);
}
else {
fields.push(field);
ops.push(op);
as.push(outputName);
}
}
else if (isArray(sort)) {
const outputName = sortArrayIndexField(fieldDef, channel);
fields.push(outputName);
ops.push('max');
as.push(outputName);
}
}
}
const cross = !!row && !!column;
return Object.assign({ name,
data,
groupby }, (cross || fields.length
? {
aggregate: Object.assign({}, (cross ? { cross } : {}), (fields.length ? { fields, ops, as } : {}))
}
: {}));
}
private _initChildren(
spec: NormalizedRepeatSpec,
repeat: RepeatMapping | string[],
repeater: RepeaterValue,
config: Config
): Model[] {
const children: Model[] = [];
const row = (!isArray(repeat) && repeat.row) || [repeater ? repeater.row : null];
const column = (!isArray(repeat) && repeat.column) || [repeater ? repeater.column : null];
const repeatValues = (isArray(repeat) && repeat) || [repeater ? repeater.repeat : null];
// cross product
for (const repeatValue of repeatValues) {
for (const rowValue of row) {
for (const columnValue of column) {
const name =
(repeatValue ? `__repeat_repeat_${repeatValue}` : '') +
(rowValue ? `__repeat_row_${rowValue}` : '') +
(columnValue ? `__repeat_column_${columnValue}` : '');
const childRepeat = {
repeat: repeatValue,
row: rowValue,
column: columnValue
case 'latitude':
case 'longitude':
case 'latitude2':
case 'longitude2':
// TODO: case 'cursor':
// text, shape, shouldn't be a part of line/trail/area
case 'text':
case 'shape':
// tooltip fields should not be added to group by
case 'tooltip':
return details;
case 'detail':
case 'key':
const channelDef = encoding[channel];
if (isArray(channelDef) || isFieldDef(channelDef)) {
(isArray(channelDef) ? channelDef : [channelDef]).forEach(fieldDef => {
if (!fieldDef.aggregate) {
details.push(vgField(fieldDef, {}));
}
});
}
return details;
case 'size':
if (mark === 'trail') {
// For trail, size should not group trail lines.
return details;
}
// For line, it should group lines.
/* tslint:disable */
// intentional fall through
case 'color':
case 'fill':
if (fill) {
out.fill = { value: fill };
}
}
}
}
if (out.stroke) {
if (channel === 'stroke' || (!filled && channel === COLOR)) {
delete out.stroke;
}
else {
if (out.stroke['field']) {
// For others, remove stroke field
delete out.stroke;
}
else if (isArray(out.stroke)) {
const stroke = getFirstDefined(getFirstConditionValue(encoding.stroke || encoding.color), markDef.stroke, filled ? markDef.color : undefined);
if (stroke) {
out.stroke = { value: stroke };
}
}
}
}
if (channel !== SHAPE) {
const shape = getFirstConditionValue(encoding.shape) || markDef.shape;
if (shape) {
out.shape = { value: shape };
}
}
if (channel !== OPACITY) {
if (opacity) {
// only apply opacity if it is neither zero or undefined
getFirstConditionValue(encoding.fill ?? encoding.color) ?? markDef.fill ?? (filled && markDef.color);
if (fill) {
out.fill = {value: fill} as ColorValueRef;
}
}
}
}
if (out.stroke) {
if (channel === 'stroke' || (!filled && channel === COLOR)) {
delete out.stroke;
} else {
if (out.stroke['field']) {
// For others, remove stroke field
delete out.stroke;
} else if (isArray(out.stroke)) {
const stroke = getFirstDefined(
getFirstConditionValue(encoding.stroke || encoding.color),
markDef.stroke,
filled ? markDef.color : undefined
);
if (stroke) {
out.stroke = {value: stroke} as ColorValueRef;
}
}
}
}
if (channel !== OPACITY) {
if (condition) {
out.opacity = [{test: condition, value: opacity ?? 1}, {value: config.legend.unselectedOpacity}];
} else if (opacity) {
invert: function(name, range, group) {
var s = getScale(name, (group || this).context);
return !s ? undefined
: isArray(range) ? (s.invertRange || s.invert)(range)
: (s.invert || s.invertExtent)(range);
},
keys(axis).forEach(prop => {
const propType = AXIS_PROPERTY_TYPE[prop];
const propValue = axis[prop];
if (propType && propType !== kind && propType !== 'both') {
delete axis[prop];
} else if (isConditionalAxisValue(propValue)) {
const {vgProp, part} = CONDITIONAL_AXIS_PROP_INDEX[prop];
const {condition, value} = propValue;
const vgRef = [
...(isArray(condition) ? condition : [condition]).map(c => {
const {value: v, test} = c;
return {
test: expression(null, test),
value: v
};
}),
{value}
];
setAxisEncode(axis, part, vgProp, vgRef);
delete axis[prop];
}
});
function getSort(facetFieldDef, channel) {
const { sort } = facetFieldDef;
if (isSortField(sort)) {
return {
field: vgField(sort, { expr: 'datum' }),
order: sort.order || 'ascending'
};
}
else if (isArray(sort)) {
return {
field: sortArrayIndexField(facetFieldDef, channel, { expr: 'datum' }),
order: 'ascending'
};
}
else {
return {
field: vgField(facetFieldDef, { expr: 'datum' }),
order: sort || 'ascending'
};
}
}
export function assembleLabelTitle(facetFieldDef, channel, config) {
export function channelHasField(encoding: EncodingWithFacet, channel: Channel): boolean {
const channelDef = encoding && encoding[channel];
if (channelDef) {
if (isArray(channelDef)) {
return some(channelDef, fieldDef => !!fieldDef.field);
} else {
return isFieldDef(channelDef) || hasConditionalFieldDef(channelDef);
}
}
return false;
}