本文整理匯總了TypeScript中vega-util.isObject函數的典型用法代碼示例。如果您正苦於以下問題:TypeScript isObject函數的具體用法?TypeScript isObject怎麽用?TypeScript isObject使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了isObject函數的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。
示例1: 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);
}
示例2: getPointOverlay
function getPointOverlay(markDef: MarkDef, markConfig: LineConfig, encoding: Encoding<Field>): MarkConfig {
if (markDef.point === 'transparent') {
return {opacity: 0};
} else if (markDef.point) { // truthy : true or object
return isObject(markDef.point) ? markDef.point : {};
} else if (markDef.point !== undefined) { // false or null
return null;
} else { // undefined (not disabled)
if (markConfig.point || encoding.shape) {
// enable point overlay if config[mark].point is truthy or if encoding.shape is provided
return isObject(markConfig.point) ? markConfig.point : {};
}
// markDef.point is defined as falsy
return null;
}
}
示例3: 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;
});
示例4: stripAndRedirectConfig
export function stripAndRedirectConfig(config: Config) {
config = duplicate(config);
for (const prop of VL_ONLY_CONFIG_PROPERTIES) {
delete config[prop];
}
// Remove Vega-Lite only axis/legend config
if (config.axis) {
for (const prop of VL_ONLY_GUIDE_CONFIG) {
delete config.axis[prop];
}
}
if (config.legend) {
for (const prop of VL_ONLY_GUIDE_CONFIG) {
delete config.legend[prop];
}
}
// Remove Vega-Lite only generic mark config
if (config.mark) {
for (const prop of VL_ONLY_MARK_CONFIG_PROPERTIES) {
delete config.mark[prop];
}
}
for (const markType of MARK_STYLES) {
// Remove Vega-Lite-only mark config
for (const prop of VL_ONLY_MARK_CONFIG_PROPERTIES) {
delete config[markType][prop];
}
// Remove Vega-Lite only mark-specific config
const vlOnlyMarkSpecificConfigs = VL_ONLY_ALL_MARK_SPECIFIC_CONFIG_PROPERTY_INDEX[markType];
if (vlOnlyMarkSpecificConfigs) {
for (const prop of vlOnlyMarkSpecificConfigs) {
delete config[markType][prop];
}
}
// Redirect mark config to config.style so that mark config only affect its own mark type
// without affecting other marks that share the same underlying Vega marks.
// For example, config.rect should not affect bar marks.
redirectConfig(config, markType);
}
// Redirect config.title -- so that title config do not
// affect header labels, which also uses `title` directive to implement.
redirectConfig(config, 'title', 'group-title');
// Remove empty config objects
for (const prop in config) {
if (isObject(config[prop]) && keys(config[prop]).length === 0) {
delete config[prop];
}
}
return keys(config).length > 0 ? config : undefined;
}
示例5: normalizeBoxPlot
//.........這裏部分代碼省略.........
endPositionPrefix: 'upper_whisker',
extraEncoding: whiskerTooltipEncoding
}),
...makeBoxPlotExtent({
partName: 'ticks',
mark: endTick,
positionPrefix: 'lower_whisker',
extraEncoding: whiskerTooltipEncoding
}),
...makeBoxPlotExtent({
partName: 'ticks',
mark: endTick,
positionPrefix: 'upper_whisker',
extraEncoding: whiskerTooltipEncoding
})
];
// ## Box Layers
// TODO: support hiding certain mark parts
const boxLayers: NormalizedUnitSpec[] = [
...(boxPlotType !== 'tukey' ? whiskerLayers : []),
...makeBoxPlotBox({
partName: 'box',
mark: {type: 'bar', ...(sizeValue ? {size: sizeValue} : {})},
positionPrefix: 'lower_box',
endPositionPrefix: 'upper_box',
extraEncoding: fiveSummaryTooltipEncoding
}),
...makeBoxPlotMidTick({
partName: 'median',
mark: {
type: 'tick',
...(isObject(config.boxplot.median) && config.boxplot.median.color ? {color: config.boxplot.median.color} : {}),
...(sizeValue ? {size: sizeValue} : {}),
orient: ticksOrient
},
positionPrefix: 'mid_box',
extraEncoding: fiveSummaryTooltipEncoding
})
];
// ## Filtered Layers
let filteredLayersMixins: NormalizedUnitSpec | NormalizedLayerSpec;
if (boxPlotType !== 'min-max') {
const lowerBoxExpr = `datum["lower_box_${continuousAxisChannelDef.field}"]`;
const upperBoxExpr = `datum["upper_box_${continuousAxisChannelDef.field}"]`;
const iqrExpr = `(${upperBoxExpr} - ${lowerBoxExpr})`;
const lowerWhiskerExpr = `${lowerBoxExpr} - ${extent} * ${iqrExpr}`;
const upperWhiskerExpr = `${upperBoxExpr} + ${extent} * ${iqrExpr}`;
const fieldExpr = `datum["${continuousAxisChannelDef.field}"]`;
const joinaggregateTransform: JoinAggregateTransform = {
joinaggregate: boxParamsQuartiles(continuousAxisChannelDef.field),
groupby
};
let filteredWhiskerSpec: NormalizedLayerSpec = undefined;
if (boxPlotType === 'tukey') {
filteredWhiskerSpec = {
transform: [
{
filter: `(${lowerWhiskerExpr} <= ${fieldExpr}) && (${fieldExpr} <= ${upperWhiskerExpr})`
},
示例6: parseSingleChannelDomain
function parseSingleChannelDomain(
scaleType: ScaleType,
domain: Domain,
model: UnitModel,
channel: ScaleChannel | 'x2' | 'y2'
): VgNonUnionDomain[] {
const fieldDef = model.fieldDef(channel);
if (domain && domain !== 'unaggregated' && !isSelectionDomain(domain)) {
// explicit value
const {type, timeUnit} = fieldDef;
if (type === 'temporal' || timeUnit) {
return mapDomainToDataSignal<number | string | boolean | DateTime>(domain, type, timeUnit);
}
return [domain];
}
const stack = model.stack;
if (stack && channel === stack.fieldChannel) {
if (stack.offset === 'normalize') {
return [[0, 1]];
}
const data = model.requestDataName(MAIN);
return [
{
data,
field: model.vgField(channel, {suffix: 'start'})
},
{
data,
field: model.vgField(channel, {suffix: 'end'})
}
];
}
const sort: undefined | true | VgSortField = isScaleChannel(channel)
? domainSort(model, channel, scaleType)
: undefined;
if (domain === 'unaggregated') {
const data = model.requestDataName(MAIN);
const {field} = fieldDef;
return [
{
data,
field: vgField({field, aggregate: 'min'})
},
{
data,
field: vgField({field, aggregate: 'max'})
}
];
} else if (isBinning(fieldDef.bin)) {
if (hasDiscreteDomain(scaleType)) {
if (scaleType === 'bin-ordinal') {
// we can omit the domain as it is inferred from the `bins` property
return [];
}
// ordinal bin scale takes domain from bin_range, ordered by bin start
// This is useful for both axis-based scale (x/y) and legend-based scale (other channels).
return [
{
// If sort by aggregation of a specified sort field, we need to use RAW table,
// so we can aggregate values for the scale independently from the main aggregation.
data: util.isBoolean(sort) ? model.requestDataName(MAIN) : model.requestDataName(RAW),
// Use range if we added it and the scale does not support computing a range as a signal.
field: model.vgField(channel, binRequiresRange(fieldDef, channel) ? {binSuffix: 'range'} : {}),
// we have to use a sort object if sort = true to make the sort correct by bin start
sort:
sort === true || !isObject(sort)
? {
field: model.vgField(channel, {}),
op: 'min' // min or max doesn't matter since we sort by the start of the bin range
}
: sort
}
];
} else {
// continuous scales
if (isBinning(fieldDef.bin)) {
const signalName = model.getName(vgField(fieldDef, {suffix: 'bins'}));
return [
new SignalRefWrapper(() => {
const signal = model.getSignalName(signalName);
return `[${signal}.start, ${signal}.stop]`;
})
];
} else {
return [
{
data: model.requestDataName(MAIN),
field: model.vgField(channel, {})
}
];
}
}
} else if (sort) {
//.........這裏部分代碼省略.........
示例7: isBinParams
export function isBinParams(bin: BinParams | boolean | 'binned'): bin is BinParams {
return isObject(bin);
}