本文整理匯總了TypeScript中vega-util.isArray函數的典型用法代碼示例。如果您正苦於以下問題:TypeScript isArray函數的具體用法?TypeScript isArray怎麽用?TypeScript isArray使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了isArray函數的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。
示例1: getSort
export function getSort(model: UnitModel) {
const {encoding, stack, mark, markDef} = model;
const order = encoding.order;
if (!isArray(order) && isValueDef(order)) {
return undefined;
} else if ((isArray(order) || isFieldDef(order)) && !stack) {
// Sort by the order field if it is specified and the field is not stacked. (For stacked field, order specify stack order.)
return sortParams(order, {expr: 'datum'});
} else if (isPathMark(mark)) {
// For both line and area, we sort values based on dimension by default
const dimensionChannelDef = encoding[markDef.orient === 'horizontal' ? 'y' : 'x'];
if (isFieldDef(dimensionChannelDef)) {
const s = dimensionChannelDef.sort;
const sortField = isSortField(s) ?
vgField({
// FIXME: this op might not already exist?
// FIXME: what if dimensionChannel (x or y) contains custom domain?
aggregate: isAggregate(model.encoding) ? s.op : undefined,
field: s.field
}, {expr: 'datum'}) :
vgField(dimensionChannelDef, {
// For stack with imputation, we only have bin_mid
binSuffix: model.stack && model.stack.impute ? 'mid' : undefined,
expr: 'datum'
});
return {
field: sortField,
order: 'descending'
};
}
return undefined;
}
return undefined;
}
示例2: keys
return keys(encoding).reduce((normalizedEncoding: Encoding<string>, channel: Channel | string) => {
if (!isChannel(channel)) {
// Drop invalid channel
log.warn(log.message.invalidEncodingChannel(channel));
return normalizedEncoding;
}
if (!markChannelCompatible(encoding, channel, mark)) {
// Drop unsupported channel
log.warn(log.message.incompatibleChannel(channel, mark));
return normalizedEncoding;
}
// Drop line's size if the field is aggregated.
if (channel === 'size' && mark === 'line') {
const fieldDef = getTypedFieldDef(encoding[channel]);
if (fieldDef && fieldDef.aggregate) {
log.warn(log.message.LINE_WITH_VARYING_SIZE);
return normalizedEncoding;
}
}
// Drop color if either fill or stroke is specified
if (channel === 'color' && ('fill' in encoding || 'stroke' in encoding)) {
log.warn(log.message.droppingColor('encoding', {fill: 'fill' in encoding, stroke: 'stroke' in encoding}));
return normalizedEncoding;
}
const channelDef = encoding[channel];
if (
channel === 'detail' ||
(channel === 'order' && !isArray(channelDef) && !isValueDef(channelDef)) ||
(channel === 'tooltip' && isArray(channelDef))
) {
if (channelDef) {
// Array of fieldDefs for detail channel (or production rule)
normalizedEncoding[channel] = (isArray(channelDef) ? channelDef : [channelDef]).reduce(
(defs: FieldDef<string>[], fieldDef: FieldDef<string>) => {
if (!isFieldDef(fieldDef)) {
log.warn(log.message.emptyFieldDef(fieldDef, channel));
} else {
defs.push(normalizeFieldDef(fieldDef, channel));
}
return defs;
},
[]
);
}
} else {
if (channel === 'tooltip' && channelDef === null) {
// Preserve null so we can use it to disable tooltip
normalizedEncoding[channel] = null;
} else if (!isFieldDef(channelDef) && !isValueDef(channelDef) && !isConditionalDef(channelDef)) {
log.warn(log.message.emptyFieldDef(channelDef, channel));
return normalizedEncoding;
}
normalizedEncoding[channel] = normalize(channelDef as ChannelDef, channel);
}
return normalizedEncoding;
}, {});
示例3: mergeTitleComponent
export function mergeTitleComponent(v1: Explicit<AxisTitleComponent>, v2: Explicit<AxisTitleComponent>) {
if (isArray(v1.value) && isArray(v2.value)) {
return {
explicit: v1.explicit,
value: mergeTitleFieldDefs(v1.value, v2.value)
};
} else if (!isArray(v1.value) && !isArray(v2.value)) {
return {
explicit: v1.explicit, // keep the old explicit
value: mergeTitle(v1.value, v2.value)
};
}
/* istanbul ignore next: Condition should not happen -- only for warning in development. */
throw new Error('It should never reach here');
}
示例4:
export function filterTooltipWithAggregatedField<F extends Field>(
oldEncoding: Encoding<F>
): {
customTooltipWithoutAggregatedField?: TextFieldDefWithCondition<F> | TextValueDefWithCondition<F> | TextFieldDef<F>[];
filteredEncoding: Encoding<F>;
} {
const {tooltip, ...filteredEncoding} = oldEncoding;
if (!tooltip) {
return {filteredEncoding: oldEncoding};
}
let customTooltipWithAggregatedField: TextFieldDefWithCondition<F> | TextValueDefWithCondition<F> | TextFieldDef<F>[];
let customTooltipWithoutAggregatedField:
| TextFieldDefWithCondition<F>
| TextValueDefWithCondition<F>
| TextFieldDef<F>[];
if (isArray(tooltip)) {
tooltip.forEach((t: TextFieldDef<F>) => {
if (t.aggregate) {
if (!customTooltipWithAggregatedField) {
customTooltipWithAggregatedField = [];
}
(customTooltipWithAggregatedField as TextFieldDef<F>[]).push(t);
} else {
if (!customTooltipWithoutAggregatedField) {
customTooltipWithoutAggregatedField = [];
}
(customTooltipWithoutAggregatedField as TextFieldDef<F>[]).push(t);
}
});
if (customTooltipWithAggregatedField) {
(filteredEncoding as Encoding<F>).tooltip = customTooltipWithAggregatedField;
}
} else {
if (tooltip['aggregate']) {
(filteredEncoding as Encoding<F>).tooltip = tooltip;
} else {
customTooltipWithoutAggregatedField = tooltip;
}
}
if (isArray(customTooltipWithoutAggregatedField) && customTooltipWithoutAggregatedField.length === 1) {
customTooltipWithoutAggregatedField = customTooltipWithoutAggregatedField[0];
}
return {customTooltipWithoutAggregatedField, filteredEncoding};
}
示例5: tooltip
export function tooltip(model: UnitModel, opt: {reactiveGeom?: boolean} = {}) {
const {encoding, markDef, config} = model;
const channelDef = encoding.tooltip;
if (isArray(channelDef)) {
return {tooltip: ref.tooltipForEncoding({tooltip: channelDef}, config, opt)};
} else {
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;
});
}
}
示例6: wrapCondition
export function wrapCondition(
model: UnitModel, channelDef: ChannelDef<string>, vgChannel: string,
refFn: (cDef: ChannelDef<string>) => VgValueRef
): VgEncodeEntry {
const condition = channelDef && channelDef.condition;
const valueRef = refFn(channelDef);
if (condition) {
const conditions = isArray(condition) ? condition : [condition];
const vgConditions = conditions.map((c) => {
const conditionValueRef = refFn(c);
const test = isConditionalSelection(c) ? selectionPredicate(model, c.selection) : expression(model, c.test);
return {
test,
...conditionValueRef
};
});
return {
[vgChannel]: [
...vgConditions,
...(valueRef !== undefined ? [valueRef] : [])
]
};
} else {
return valueRef !== undefined ? {[vgChannel]: valueRef} : {};
}
}
示例7: sortParams
export function sortParams(orderDef: OrderFieldDef<string> | OrderFieldDef<string>[], fieldRefOption?: FieldRefOption): VgSort {
return (isArray(orderDef) ? orderDef : [orderDef]).reduce((s, orderChannelDef) => {
s.field.push(vgField(orderChannelDef, fieldRefOption));
s.order.push(orderChannelDef.sort || 'ascending');
return s;
}, {field:[], order: []});
}
示例8: keys
return keys(encoding).reduce((details, channel) => {
switch (channel) {
// x, y, x2, y2, lat, long, lat1, long2, order, tooltip, href, cursor should not cause lines to group
case 'x':
case 'y':
case 'order':
case 'tooltip':
case 'href':
case 'x2':
case 'y2':
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':
return details;
case 'detail':
case 'key':
const channelDef = encoding[channel];
if (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':
case 'stroke':
case 'opacity':
// TODO strokeDashOffset:
/* tslint:enable */
const fieldDef = getFieldDef<string>(encoding[channel]);
if (fieldDef && !fieldDef.aggregate) {
details.push(vgField(fieldDef, {}));
}
return details;
default:
throw new Error(`Bug: Channel ${channel} unimplemented for line mark`);
}
}, []);
示例9: constructor
/**
* @param model The facet model.
* @param name The name that this facet source will have.
* @param data The source data for this facet data.
*/
public constructor(
parent: DataFlowNode,
public readonly model: FacetModel,
public readonly name: string,
public data: string
) {
super(parent);
for (const channel of FACET_CHANNELS) {
const fieldDef = model.facet[channel];
if (fieldDef) {
const {bin, sort} = fieldDef;
this[channel] = {
name: model.getName(`${channel}_domain`),
fields: [vgField(fieldDef), ...(isBinning(bin) ? [vgField(fieldDef, {binSuffix: 'end'})] : [])],
...(isSortField(sort)
? {sortField: sort}
: isArray(sort)
? {sortIndexField: sortArrayIndexField(fieldDef, channel)}
: {})
};
}
}
this.childModel = model.child;
}
示例10: formatValue
export function formatValue(value: any, valueToHtml: (value: any) => string, maxDepth: number): string {
if (isArray(value)) {
return `[${value.map(v => valueToHtml(isString(v) ? v : stringify(v, maxDepth))).join(', ')}]`;
}
if (isObject(value)) {
let content = '';
const { title, ...rest } = value as any;
if (title) {
content += `<h2>${valueToHtml(title)}</h2>`;
}
const keys = Object.keys(rest);
if (keys.length > 0) {
content += '<table>';
for (const key of keys) {
let val = (rest as any)[key];
if (isObject(val)) {
val = stringify(val, maxDepth);
}
content += `<tr><td class="key">${valueToHtml(key)}:</td><td class="value">${valueToHtml(val)}</td></tr>`;
}
content += `</table>`;
}
return content || '{}'; // show empty object if there are no properties
}
return valueToHtml(value);
}