How to use the vega-lite/src/fielddef.isDimension function in vega-lite

To help you get started, we’ve selected a few vega-lite examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github vega / compass / src / gen / encodings.ts View on Github external
function assignField(i) {
    // If all fields are assigned, save
    if (i === fieldDefs.length) {
      // at the minimal all chart should have x, y, geo, text or arc
      if (rule.encoding(tmpEncoding, stats, opt)) {
        encodings.push(duplicate(tmpEncoding));
      }
      return;
    }

    // Otherwise, assign i-th field
    var fieldDef = fieldDefs[i];
    for (var j in opt.channelList) {
      var channel = opt.channelList[j],
        isDim = isDimension(fieldDef);

      const supportedRole = getSupportedRole(channel);

      // TODO: support "multiple" assignment
      if (
        // encoding not used
        !(channel in tmpEncoding) &&
        // channel support the assigned role
        ((isDim && supportedRole.dimension) || (!isDim && supportedRole.measure)) &&
        // the field satisfies the channel's rule
        rule.channel[channel](tmpEncoding, fieldDef, stats, opt)
      ) {
        tmpEncoding[channel] = fieldDef;
        assignField(i + 1);
        delete tmpEncoding[channel];
      }
github vega / compass / src / gen / marks.ts View on Github external
export function tick(encoding: Encoding, stats, opt: SpecOption) {
    // jshint unused:false
    if (encoding.x || encoding.y) {
      if(isAggregate(encoding)) return false;

      var xIsDim = isDimension(encoding.x),
        yIsDim = isDimension(encoding.y);

      return (!xIsDim && (!encoding.y || yIsDim)) ||
        (!yIsDim && (!encoding.x || xIsDim));
    }
    return false;
  }
github vega / compass / src / gen / encodings.ts View on Github external
function xyPlotRules(encoding: Encoding, stats, opt: SpecOption) {
    if (encoding.row || encoding.column) { // have facet(s)
      if (opt.omitNonTextAggrWithAllDimsOnFacets) {
        // remove all aggregated charts with all dims on facets (row, column)
        if (isAggrWithAllDimOnFacets(encoding)) { return false; }
      }
    }

    var isDimX = isDimension(encoding.x),
      isDimY = isDimension(encoding.y);

    // If both x and y are dimension, and the plot is not aggregated,
    // there might be occlusion.
    if (opt.omitRawWithXYBothDimension && isDimX && isDimY && !isAggregate(encoding)) {
      // FIXME actually check if there would be occlusion #90
      return false;
    }

    if (opt.omitTranspose) {
      if (isDimX !== isDimY) { // dim x mea
        // create horizontal histogram for ordinal
        if ((encoding.y.type === Type.NOMINAL || encoding.y.type === Type.ORDINAL) && isMeasure(encoding.x)) {
          return true;
        }

        // vertical histogram for binned Q and T
github vega / compass / src / gen / marks.ts View on Github external
export function point(encoding: Encoding, stats, opt: SpecOption) {
    if(!facetsRule(encoding, stats, opt)) return false;
    if (encoding.x && encoding.y) {
      // have both x & y ==> scatter plot / bubble plot

      var xIsDim = isDimension(encoding.x),
        yIsDim = isDimension(encoding.y);

      // For OxO
      if (xIsDim && yIsDim) {
        // TODO: revise if we need his
        // shape doesn't work with both x, y as ordinal
        if (encoding.shape) {
          return false;
        }

        // TODO(kanitw): check that there is quant at least ...
        if (encoding.color && isDimension(encoding.color)) {
          return false;
        }
      }
github vega / compass / src / gen / marks.ts View on Github external
export function point(encoding: Encoding, stats, opt: SpecOption) {
    if(!facetsRule(encoding, stats, opt)) return false;
    if (encoding.x && encoding.y) {
      // have both x & y ==> scatter plot / bubble plot

      var xIsDim = isDimension(encoding.x),
        yIsDim = isDimension(encoding.y);

      // For OxO
      if (xIsDim && yIsDim) {
        // TODO: revise if we need his
        // shape doesn't work with both x, y as ordinal
        if (encoding.shape) {
          return false;
        }

        // TODO(kanitw): check that there is quant at least ...
        if (encoding.color && isDimension(encoding.color)) {
          return false;
        }
      }

    } else { // plot with one axis = dot plot
github vega / compass / src / gen / aggregates.ts View on Github external
tf.forEach(function(f) {
        if (vlFieldDef.isDimension(f)) {
          hasDimension = true;
        } else {
          hasMeasure = true;
          if (!f.aggregate) { hasRaw = true; }
        }
      });
      // Constraint: Omit Aggregate Plot with measure only
github vega / compass / src / gen / marks.ts View on Github external
}



    // FIXME actually check if there would be occlusion #90
    // need to aggregate on either x or y

    var aggEitherXorY =
      (!encoding.x || encoding.x.aggregate === undefined) !== // xor
      (!encoding.y || encoding.y.aggregate === undefined);


    if (aggEitherXorY) {
      var eitherXorYisDimOrNull =
        (!encoding.x || isDimension(encoding.x)) !== // xor
        (!encoding.y || isDimension(encoding.y));

      if (eitherXorYisDimOrNull) {
        var aggregate = encoding.x.aggregate || encoding.y.aggregate;

        // TODO: revise
        return !(opt.omitStackedAverage && aggregate ==='mean' && encoding.color);
      }
    }

    return false;
  }
github vega / compass / src / rank / rankEncodings.ts View on Github external
scores = mappings.map(function(m) {
        var roleScore = vlFieldDef.isDimension(m.fieldDef) ?
                          dimensionScore : measureScore;

        var score = roleScore(m.fieldDef, m.channel, spec.mark, stats, opt);

        return !selected || selected[m.fieldDef.field] ? score : Math.pow(score, 0.125);
      });
github vega / compass / src / gen / encodings.ts View on Github external
function isAggrWithAllDimOnFacets(encoding) {
    var hasAggr = false, hasOtherO = false;
    for (var c in encoding) {
      const channel: Channel = c as any;
      var fieldDef = encoding[channel];
      if (fieldDef.aggregate) {
        hasAggr = true;
      }
      if (isDimension(fieldDef) && (channel !== ROW && channel !== COLUMN)) {
        hasOtherO = true;
      }
      if (hasAggr && hasOtherO) { break; }
    }

    return hasAggr && !hasOtherO;
  };