本文整理汇总了TypeScript中vega-util.isNumber函数的典型用法代码示例。如果您正苦于以下问题:TypeScript isNumber函数的具体用法?TypeScript isNumber怎么用?TypeScript isNumber使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了isNumber函数的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: getBoxPlotType
export function getBoxPlotType(extent: number | 'min-max') {
if (isNumber(extent)) {
return 'tukey';
}
// Ham: If we ever want to, we could add another extent syntax `{kIQR: number}` for the original [Q1-k*IQR, Q3+k*IQR] whisker and call this boxPlotType = `kIQR`. However, I'm not exposing this for now.
return extent;
}
示例2: 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';
}
}
});
示例3: getRangeStep
function getRangeStep(model: UnitModel, channel: 'x' | 'y'): number | SignalRef {
const scaleCmpt = model.getScaleComponent(channel);
if (!scaleCmpt) {
return undefined;
}
const scaleType = scaleCmpt.get('type');
const fieldDef = model.fieldDef(channel);
if (hasDiscreteDomain(scaleType)) {
const range = scaleCmpt && scaleCmpt.get('range');
if (range && isVgRangeStep(range) && isNumber(range.step)) {
return range.step;
// TODO: support the case without range step
}
} else if (fieldDef && fieldDef.bin && isBinning(fieldDef.bin)) {
const binSignal = model.getName(vgField(fieldDef, {suffix: 'bins'}));
// TODO: extract this to be range step signal
const sizeType = getSizeType(channel);
const sizeSignal = model.getName(sizeType);
return new SignalRefWrapper(() => {
const updatedName = model.getSignalName(binSignal);
const binCount = `(${updatedName}.stop - ${updatedName}.start) / ${updatedName}.step`;
return `${model.getSignalName(sizeSignal)} / (${binCount})`;
});
}
return undefined;
}
示例4: getXYRangeStep
function getXYRangeStep(model: UnitModel) {
const xyRangeSteps: number[] = [];
const xScale = model.getScaleComponent('x');
const xRange = xScale && xScale.get('range');
if (xRange && isVgRangeStep(xRange) && isNumber(xRange.step)) {
xyRangeSteps.push(xRange.step);
}
const yScale = model.getScaleComponent('y');
const yRange = yScale && yScale.get('range');
if (yRange && isVgRangeStep(yRange) && isNumber(yRange.step)) {
xyRangeSteps.push(yRange.step);
}
return xyRangeSteps;
}
示例5: 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;
}
示例6: normalizeQuarter
function normalizeQuarter(q: number | string) {
if (isNumber(q)) {
if (q > 4) {
log.warn(log.message.invalidTimeUnit('quarter', q));
}
// We accept 1-based quarter, so need to readjust to 0-based quarter
return (q - 1) + '';
} else {
// Invalid quarter
throw new Error(log.message.invalidTimeUnit('quarter', q));
}
}
示例7: sizeRangeMax
function sizeRangeMax(mark: Mark, xyRangeSteps: (number | SignalRef)[], config: Config): number | SignalRef {
const scaleConfig = config.scale;
switch (mark) {
case 'bar':
case 'tick':
if (config.scale.maxBandSize !== undefined) {
return config.scale.maxBandSize;
}
const min = minXYRangeStep(xyRangeSteps, config.scale);
if (isNumber(min)) {
return min - 1;
} else {
return new SignalRefWrapper(() => `${min.signal} - 1`);
}
case 'line':
case 'trail':
case 'rule':
return config.scale.maxStrokeWidth;
case 'text':
return config.scale.maxFontSize;
case 'point':
case 'square':
case 'circle':
if (config.scale.maxSize) {
return config.scale.maxSize;
}
const pointStep = minXYRangeStep(xyRangeSteps, scaleConfig);
if (isNumber(pointStep)) {
return Math.pow(MAX_SIZE_RANGE_STEP_RATIO * pointStep, 2);
} else {
return new SignalRefWrapper(() => `pow(${MAX_SIZE_RANGE_STEP_RATIO} * ${pointStep.signal}, 2)`);
}
}
/* istanbul ignore next: should never reach here */
// sizeRangeMax not implemented for the mark
throw new Error(log.message.incompatibleChannel('size', mark));
}
示例8: defaultSizeRef
function defaultSizeRef(
markDef: MarkDef,
sizeChannel: 'width' | 'height',
scaleName: string,
scale: ScaleComponent,
config: Config
): VgValueRef {
const markPropOrConfig = getFirstDefined(
markDef[sizeChannel],
markDef.size,
getMarkConfig('size', markDef, config, {vgChannel: sizeChannel})
);
if (markPropOrConfig !== undefined) {
return {value: markPropOrConfig};
}
if (scale) {
const scaleType = scale.get('type');
if (scaleType === 'point' || scaleType === 'band') {
if (config.bar.discreteBandSize !== undefined) {
return {value: config.bar.discreteBandSize};
}
if (scaleType === ScaleType.POINT) {
const scaleRange = scale.get('range');
if (isVgRangeStep(scaleRange) && isNumber(scaleRange.step)) {
return {value: scaleRange.step - 1};
}
log.warn(log.message.BAR_WITH_POINT_SCALE_AND_RANGESTEP_NULL);
} else {
// BAND
return ref.bandRef(scaleName);
}
} else {
// continuous scale
return {value: config.bar.continuousBandSize};
}
}
// No Scale
const value = getFirstDefined(
// No scale is like discrete bar (with one item)
config.bar.discreteBandSize,
config.scale.rangeStep ? config.scale.rangeStep - 1 : undefined,
// If somehow default rangeStep is set to null or undefined, use 20 as back up
20
);
return {value};
}
示例9: extractCompositionLayout
export function extractCompositionLayout(
spec: NormalizedSpec,
specType: SpecType,
config: Config
): GenericCompositionLayoutWithColumns {
const compositionConfig = config[specType];
const layout: GenericCompositionLayoutWithColumns = {};
// Apply config first
const {spacing: spacingConfig, columns} = compositionConfig;
if (spacingConfig !== undefined) {
layout.spacing = spacingConfig;
}
if (columns !== undefined) {
if (
(isFacetSpec(spec) && !isFacetMapping(spec.facet)) ||
(isRepeatSpec(spec) && isArray(spec.repeat)) ||
isConcatSpec(spec)
) {
layout.columns = columns;
}
}
// Then copy properties from the spec
for (const prop of COMPOSITION_LAYOUT_PROPERTIES) {
if (spec[prop] !== undefined) {
if (prop === 'spacing') {
const spacing = spec[prop];
layout[prop] = isNumber(spacing)
? spacing
: {
row: spacing.row || spacingConfig,
column: spacing.column || spacingConfig
};
} else {
layout[prop] = spec[prop];
}
}
}
return layout;
}
示例10: normalizeMonth
function normalizeMonth(m: string | number) {
if (isNumber(m)) {
// We accept 1-based month, so need to readjust to 0-based month
return (m - 1) + '';
} else {
const lowerM = m.toLowerCase();
const monthIndex = MONTHS.indexOf(lowerM);
if (monthIndex !== -1) {
return monthIndex + ''; // 0 for january, ...
}
const shortM = lowerM.substr(0, 3);
const shortMonthIndex = SHORT_MONTHS.indexOf(shortM);
if (shortMonthIndex !== -1) {
return shortMonthIndex + '';
}
// Invalid month
throw new Error(log.message.invalidTimeUnit('month', m));
}
}