说明
typescript vega-lite/build/src/compile/scale/type scaletype示例是从最受好评的开源项目中提取的实现代码,你可以参考下面示例的使用方式。
编程语言: TypeScript
命名空间/包名称: vega-lite/build/src/compile/scale/type
示例#1
文件:
encoding.ts
项目:
herrstucki/compassql
export function scaleType(fieldQ: FieldQuery) {
const scale: ScaleQuery = fieldQ.scale === true || fieldQ.scale === SHORT_WILDCARD ? {} : fieldQ.scale || {};
const {type, channel, timeUnit, bin} = fieldQ;
// HACK: All of markType, and scaleConfig only affect
// sub-type of ordinal to quantitative scales (point or band)
// Currently, most of scaleType usage in CompassQL doesn't care about this subtle difference.
// Thus, instead of making this method requiring the global mark,
// we will just call it with mark = undefined .
// Thus, currently, we will always get a point scale unless a CompassQuery specifies band.
const markType: Mark = undefined;
const scaleConfig = {};
if (isWildcard(scale.type) || isWildcard(type) || isWildcard(channel) || isWildcard(bin)) {
return undefined;
}
// If scale type is specified, then use scale.type
if (scale.type) {
return scale.type;
}
let rangeStep: number = undefined;
// Note: Range step currently does not matter as we don't pass mark into compileScaleType anyway.
// However, if we pass mark, we could use a rule like the following.
// I also have few test cases listed in encoding.test.ts
// if (channel === 'x' || channel === 'y') {
// if (isWildcard(scale.rangeStep)) {
// if (isShortWildcard(scale.rangeStep)) {
// return undefined;
// } else if (scale.rangeStep.enum) {
// const e = scale.rangeStep.enum;
// // if enumerated value contains enum then we can't be sure
// if (contains(e, undefined) || contains(e, null)) {
// return undefined;
// }
// rangeStep = e[0];
// }
// }
// }
// if type is fixed and it's not temporal, we can ignore time unit.
if (type === 'temporal' && isWildcard(timeUnit)) {
return undefined;
}
// if type is fixed and it's not quantitative, we can ignore bin
if (type === 'quantitative' && isWildcard(bin)) {
return undefined;
}
let vegaLiteType: VLType = type === ExpandedType.KEY ? 'nominal': type;
const fieldDef = {type: vegaLiteType, timeUnit: timeUnit as TimeUnit, bin: bin as BinParams};
return compileScaleType(scale.type, channel, fieldDef, markType, rangeStep, scaleConfig);
}
示例#2
文件:
encoding.ts
项目:
uwdata/compassql
export function scaleType(fieldQ: FieldQuery) {
const scale: ScaleQuery = fieldQ.scale === true || fieldQ.scale === SHORT_WILDCARD ? {} : fieldQ.scale || {};
const {type, channel, timeUnit, bin} = fieldQ;
// HACK: All of markType, and scaleConfig only affect
// sub-type of ordinal to quantitative scales (point or band)
// Currently, most of scaleType usage in CompassQL doesn't care about this subtle difference.
// Thus, instead of making this method requiring the global mark,
// we will just call it with mark = undefined .
// Thus, currently, we will always get a point scale unless a CompassQuery specifies band.
const markType: Mark = undefined;
const scaleConfig = {};
if (isWildcard(scale.type) || isWildcard(type) || isWildcard(channel) || isWildcard(bin)) {
return undefined;
}
// If scale type is specified, then use scale.type
if (scale.type) {
return scale.type;
}
// if type is fixed and it's not temporal, we can ignore time unit.
if (type === 'temporal' && isWildcard(timeUnit)) {
return undefined;
}
// if type is fixed and it's not quantitative, we can ignore bin
if (type === 'quantitative' && isWildcard(bin)) {
return undefined;
}
let vegaLiteType: VLType = type === ExpandedType.KEY ? 'nominal': type;
const fieldDef = {type: vegaLiteType, timeUnit: timeUnit as TimeUnit, bin: bin as BinParams};
return compileScaleType(scale.type, channel, fieldDef, markType, scaleConfig);
}