本文整理汇总了TypeScript中vega-lite/src/fielddef.cardinality函数的典型用法代码示例。如果您正苦于以下问题:TypeScript cardinality函数的具体用法?TypeScript cardinality怎么用?TypeScript cardinality使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了cardinality函数的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: if
fieldDefs.forEach(function(fieldDef, index){
// save indices for stable sort later
indices[fieldDef.field] = index;
if (fieldDef.selected) { // selected fields are included in selected
selected.push(fieldDef);
if (isDimension(fieldDef) ||
(fieldDef.type === TEMPORAL /* TODO: add && current constraint make it a dimension */)) {
// If the field can serve as dimension
// FIXME vega-lite's isDimension is designed to work with FieldDef, not SchemaField
// Therefore, we should augment vega-lite's isDimension
hasSelectedDimension = true;
} else {
hasSelectedMeasure = true;
}
} else if (fieldDef.selected !== false && !vlFieldDef.isCount(fieldDef)) {
if (vlFieldDef.isDimension(fieldDef) &&
!opt.maxCardinalityForAutoAddOrdinal &&
vlFieldDef.cardinality(fieldDef, stats, 15) > opt.maxCardinalityForAutoAddOrdinal
) {
return;
}
fieldsToAdd.push(fieldDef);
}
});
示例2: color
export function color(encoding: Encoding, fieldDef: FieldDef, stats, opt: SpecOption) {
// Don't use color if omitMultipleRetinalEncodings is true and we already have other retinal encoding
if (!retinalEncRules(encoding, fieldDef, stats, opt)) {
return false;
}
// Color must be either measure or dimension with cardinality lower than the max cardinality
return isMeasure(fieldDef) ||
cardinality(fieldDef, stats) <= opt.maxCardinalityForColor;
}
示例3: function
export let dimensionScore:any = function(fieldDef, channel, mark, stats, opt){
var cardinality = vlFieldDef.cardinality(fieldDef, stats);
switch (channel) {
case vlChannel.X:
if (fieldDef.type === Type.NOMINAL || fieldDef.type === Type.ORDINAL) {
return D.pos - D.minor;
}
return D.pos;
case vlChannel.Y:
if (fieldDef.type === Type.NOMINAL || fieldDef.type === Type.ORDINAL) {
return D.pos - D.minor; // prefer ordinal on y
}
if (fieldDef.type === Type.TEMPORAL) {
return D.Y_T; // time should not be on Y
}
return D.pos - D.minor;
case vlChannel.COLUMN:
if (mark === 'text') return D.facet_text;
// prefer column over row due to scrolling issues
return cardinality <= opt.maxGoodCardinalityForFacets ? D.facet_good :
cardinality <= opt.maxCardinalityForFacets ? D.facet_ok : D.facet_bad;
case vlChannel.ROW:
if (mark === 'text') return D.facet_text;
return (cardinality <= opt.maxGoodCardinalityForFacets ? D.facet_good :
cardinality <= opt.maxCardinalityForFacets ? D.facet_ok : D.facet_bad) - D.minor;
case vlChannel.COLOR:
var hasOrder = (fieldDef.bin && fieldDef.type=== Type.QUANTITATIVE) || (fieldDef.timeUnit && fieldDef.type=== Type.TEMPORAL);
// FIXME add stacking option once we have control ..
var isStacked = mark === Mark.BAR || mark === Mark.AREA;
// true ordinal on color is currently BAD (until we have good ordinal color scale support)
if (hasOrder) return D.color_bad;
// stacking gets lower score
if (isStacked) return D.color_stack;
return cardinality <= opt.maxGoodCardinalityForColor ? D.color_good: cardinality <= opt.maxCardinalityForColor ? D.color_ok : D.color_bad;
case vlChannel.SHAPE:
return cardinality <= opt.maxCardinalityForShape ? D.shape : TERRIBLE;
case vlChannel.DETAIL:
return D.detail;
}
return TERRIBLE;
};
示例4: shape
export function shape(encoding: Encoding, fieldDef: FieldDef, stats, opt: SpecOption) {
if (!retinalEncRules(encoding, fieldDef, stats, opt)) {
return false;
}
// TODO: revise if this should mainly be on ranking
if (opt.omitShapeWithBin && fieldDef.bin && fieldDef.type === Type.QUANTITATIVE) {
return false;
}
if (opt.omitShapeWithTimeDimension && fieldDef.timeUnit && fieldDef.type === Type.TEMPORAL) {
return false;
}
return cardinality(fieldDef, stats) <= opt.maxCardinalityForShape;
}
示例5: assignQ
function assignQ(i, hasAggr, autoMode) {
var f = fieldDefs[i],
canHaveAggr = hasAggr === true || hasAggr === null;
tf[i] = {field: f.field, type: f.type};
if (f.aggregate === AggregateOp.COUNT) { // if count is included in the selected fields
if (canHaveAggr) {
tf[i].aggregate = f.aggregate;
assignField(i + 1, true, autoMode);
}
} else if (f._aggregate) {
// TODO support array of f._aggrs too
assignAggrQ(i, hasAggr, autoMode, f._aggregate);
} else if (f._raw) {
assignAggrQ(i, hasAggr, autoMode, undefined);
} else if (f._bin) {
assignBinQ(i, hasAggr, autoMode);
} else {
opt.aggrList.forEach(function(a) {
if (!opt.consistentAutoQ || autoMode === AUTO || autoMode === a) {
assignAggrQ(i, hasAggr, a /*assign autoMode*/, a);
}
});
if ((!opt.consistentAutoQ || util.isin(autoMode, [AUTO, 'bin', 'cast', 'autocast'])) && !hasNorO) {
// Constraint: Bin a field only if its cardinality is above certain threshold
var highCardinality = vlFieldDef.cardinality(f, stats) > opt.minCardinalityForBin;
var isAuto = opt.genDimQ === QuantitativeDimensionType.AUTO,
genBin = opt.genDimQ === QuantitativeDimensionType.BIN || (isAuto && highCardinality),
genCast = opt.genDimQ === QuantitativeDimensionType.CAST || (isAuto && !highCardinality);
if (genBin && util.isin(autoMode, [AUTO, 'bin', 'autocast'])) {
assignBinQ(i, hasAggr, isAuto ? 'autocast' : 'bin');
}
if (genCast && util.isin(autoMode, [AUTO, 'cast', 'autocast'])) {
tf[i].type = Type.ORDINAL;
assignField(i + 1, hasAggr, isAuto ? 'autocast' : 'cast');
tf[i].type = Type.QUANTITATIVE;
}
}
}
}
示例6: facetRule
function facetRule(fieldDef, stats, opt: SpecOption) {
return cardinality(fieldDef, stats) <= opt.maxCardinalityForFacets;
}