當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。