当前位置: 首页>>代码示例>>TypeScript>>正文


TypeScript fielddef.cardinality函数代码示例

本文整理汇总了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);
    }
  });
开发者ID:sguzwf,项目名称:compass,代码行数:27,代码来源:projections.ts

示例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;
    }
开发者ID:mchally,项目名称:ExploringDataViz,代码行数:10,代码来源:encodings.ts

示例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;
};
开发者ID:mchally,项目名称:ExploringDataViz,代码行数:49,代码来源:rankEncodings.ts

示例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;
    }
开发者ID:sguzwf,项目名称:compass,代码行数:15,代码来源:encodings.ts

示例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;
        }
      }
    }
  }
开发者ID:mchally,项目名称:ExploringDataViz,代码行数:44,代码来源:aggregates.ts

示例6: facetRule

 function facetRule(fieldDef, stats, opt: SpecOption) {
   return cardinality(fieldDef, stats) <= opt.maxCardinalityForFacets;
 }
开发者ID:mchally,项目名称:ExploringDataViz,代码行数:3,代码来源:marks.ts


注:本文中的vega-lite/src/fielddef.cardinality函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。