本文整理汇总了TypeScript中vega-util.isString函数的典型用法代码示例。如果您正苦于以下问题:TypeScript isString函数的具体用法?TypeScript isString怎么用?TypeScript isString使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了isString函数的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: getFieldFromDomain
export function getFieldFromDomain(domain: VgDomain): string {
if (isDataRefDomain(domain) && isString(domain.field)) {
return domain.field;
} else if (isDataRefUnionedDomain(domain)) {
let field;
for (const nonUnionDomain of domain.fields) {
if (isDataRefDomain(nonUnionDomain) && isString(nonUnionDomain.field)) {
if (!field) {
field = nonUnionDomain.field;
} else if (field !== nonUnionDomain.field) {
log.warn('Detected faceted independent scales that union domain of multiple fields from different data sources. We will use the first field. The result view size may be incorrect.');
return field;
}
}
}
log.warn('Detected faceted independent scales that union domain of identical fields from different source detected. We will assume that this is the same field from a different fork of the same data source. However, if this is not case, the result view size maybe incorrect.');
return field;
} else if (isFieldRefUnionDomain(domain)) {
log.warn('Detected faceted independent scales that union domain of multiple fields from the same data source. We will use the first field. The result view size may be incorrect.');
const field = domain.fields[0];
return isString(field) ? field : undefined;
}
return undefined;
}
示例2: canUseUnaggregatedDomain
export function canUseUnaggregatedDomain(
fieldDef: TypedFieldDef<string>,
scaleType: ScaleType
): {valid: boolean; reason?: string} {
const {aggregate, type} = fieldDef;
if (!aggregate) {
return {
valid: false,
reason: log.message.unaggregateDomainHasNoEffectForRawField(fieldDef)
};
}
if (isString(aggregate) && !SHARED_DOMAIN_OP_INDEX[aggregate]) {
return {
valid: false,
reason: log.message.unaggregateDomainWithNonSharedDomainOp(aggregate)
};
}
if (type === 'quantitative') {
if (scaleType === 'log') {
return {
valid: false,
reason: log.message.unaggregatedDomainWithLogScale(fieldDef)
};
}
}
return {valid: true};
}
示例3: forEachLeaf
forEachLeaf(transform.filter, filter => {
if (isFieldPredicate(filter)) {
// Automatically add a parse node for filters with filter objects
let val: string | number | boolean | DateTime = null;
// For EqualFilter, just use the equal property.
// For RangeFilter and OneOfFilter, all array members should have
// the same type, so we only use the first one.
if (isFieldEqualPredicate(filter)) {
val = filter.equal;
} else if (isFieldRangePredicate(filter)) {
val = filter.range[0];
} else if (isFieldOneOfPredicate(filter)) {
val = (filter.oneOf || filter['in'])[0];
} // else -- for filter expression, we can't infer anything
if (val) {
if (isDateTime(val)) {
parse[filter.field] = 'date';
} else if (isNumber(val)) {
parse[filter.field] = 'number';
} else if (isString(val)) {
parse[filter.field] = 'string';
}
}
if (filter.timeUnit) {
parse[filter.field] = 'date';
}
}
});
示例4: assemble
public assemble(): VgLookupTransform {
let foreign: Partial<VgLookupTransform>;
if (this.transform.from.fields) {
// lookup a few fields and add create a flat output
foreign = {
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 {
type: 'lookup',
from: this.secondary,
key: this.transform.from.key,
fields: [this.transform.lookup],
...foreign,
...(this.transform.default ? {default: this.transform.default} : {})
};
}
示例5: makeFromTransform
public static makeFromTransform(parent: DataFlowNode, stackTransform: StackTransform) {
const {stack, groupby, as, offset = 'zero'} = stackTransform;
const sortFields: string[] = [];
const sortOrder: VgComparatorOrder[] = [];
if (stackTransform.sort !== undefined) {
for (const sortField of stackTransform.sort) {
sortFields.push(sortField.field);
sortOrder.push(getFirstDefined(sortField.order, 'ascending'));
}
}
const sort: VgCompare = {
field: sortFields,
order: sortOrder
};
let normalizedAs: string[];
if (isValidAsArray(as)) {
normalizedAs = as;
} else if (isString(as)) {
normalizedAs = [as, as + '_end'];
} else {
normalizedAs = [stackTransform.stack + '_start', stackTransform.stack + '_end'];
}
return new StackNode(parent, {
stackField: stack,
groupby,
offset,
sort,
facetby: [],
as: normalizedAs
});
}
示例6: wrapCondition
return wrapCondition(model, channelDef, 'tooltip', cDef => {
// use valueRef based on channelDef first
const tooltipRefFromChannelDef = ref.text(cDef, model.config, opt.reactiveGeom ? 'datum.datum' : 'datum');
if (tooltipRefFromChannelDef) {
return tooltipRefFromChannelDef;
}
if (cDef === null) {
// Allow using encoding.tooltip = null to disable tooltip
return undefined;
}
// If tooltipDef does not exist, then use value from markDef or config
const markTooltip = getFirstDefined(markDef.tooltip, getMarkConfig('tooltip', markDef, config));
if (isString(markTooltip)) {
return {value: markTooltip};
} else if (isObject(markTooltip)) {
// `tooltip` is `{fields: 'encodings' | 'fields'}`
if (markTooltip.content === 'encoding') {
return ref.tooltipForEncoding(encoding, config, opt);
} else {
return {signal: 'datum'};
}
}
return undefined;
});
示例7: logicalExpr
return logicalExpr(filterOp, (predicate: Predicate) => {
if (isString(predicate)) {
return predicate;
} else if (isSelectionPredicate(predicate)) {
return selectionPredicate(model, predicate.selection, node);
} else { // Filter Object
return fieldFilterExpression(predicate);
}
});
示例8: normalize
export function normalize(channelDef: ChannelDef, channel: Channel): ChannelDef<any> {
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<FieldDef>
condition: normalizeFieldDef(channelDef.condition, channel) as Conditional<TypedFieldDef<string>>
};
}
return channelDef;
}
示例9: parseUnitSelection
export function parseUnitSelection(model: UnitModel, selDefs: Dict<SelectionDef>) {
const selCmpts: Dict<SelectionComponent<any /* this has to be "any" so typing won't fail in test files*/>> = {};
const selectionConfig = model.config.selection;
if (selDefs) {
selDefs = duplicate(selDefs); // duplicate to avoid side effects to original spec
}
for (let name in selDefs) {
if (!selDefs.hasOwnProperty(name)) {
continue;
}
const selDef = selDefs[name];
const {fields, encodings, ...cfg} = selectionConfig[selDef.type]; // Project transform applies its defaults.
// Set default values from config if a property hasn't been specified,
// or if it is true. E.g., "translate": true should use the default
// event handlers for translate. However, true may be a valid value for
// a property (e.g., "nearest": true).
for (const key in cfg) {
// A selection should contain either `encodings` or `fields`, only use
// default values for these two values if neither of them is specified.
if ((key === 'encodings' && selDef.fields) || (key === 'fields' && selDef.encodings)) {
continue;
}
if (key === 'mark') {
selDef[key] = {...cfg[key], ...selDef[key]};
}
if (selDef[key] === undefined || selDef[key] === true) {
selDef[key] = cfg[key] || selDef[key];
}
}
name = varName(name);
const selCmpt = (selCmpts[name] = {
...selDef,
name: name,
events: isString(selDef.on) ? parseSelector(selDef.on, 'scope') : selDef.on
} as any);
forEachTransform(selCmpt, txCompiler => {
if (txCompiler.parse) {
txCompiler.parse(model, selDef, selCmpt);
}
});
}
return selCmpts;
}
示例10: return
return ({
partName,
mark,
positionPrefix,
endPositionPrefix = undefined,
extraEncoding = {}
}: {
partName: keyof P;
mark: Mark | MarkDef;
positionPrefix: string;
endPositionPrefix?: string;
extraEncoding?: Encoding<string>;
}) => {
const title =
axis && axis.title !== undefined
? undefined
: continuousAxisChannelDef.title !== undefined
? continuousAxisChannelDef.title
: continuousAxisChannelDef.field;
return partLayerMixins<P>(compositeMarkDef, partName, compositeMarkConfig, {
mark, // TODO better remove this method and just have mark as a parameter of the method
encoding: {
[continuousAxis]: {
field: positionPrefix + '_' + continuousAxisChannelDef.field,
type: continuousAxisChannelDef.type,
...(title ? {title} : {}),
...(scale ? {scale} : {}),
...(axis ? {axis} : {})
},
...(isString(endPositionPrefix)
? {
[continuousAxis + '2']: {
field: endPositionPrefix + '_' + continuousAxisChannelDef.field,
type: continuousAxisChannelDef.type
}
}
: {}),
...sharedEncoding,
...extraEncoding
}
});
};