How to use the vega-lite/build/src/util.contains 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 / voyager / src / models / shelf / spec / function.ts View on Github external
): ShelfFunction | Wildcard {

  // FIXME make this a parameter
  const config = DEFAULT_QUERY_CONFIG;

  const {aggregate, bin, hasFn, timeUnit} = fieldQParts;

  let fns: ShelfFunction[] = [];
  let fn: ShelfFunction;
  let hasUndefinedInEnum = false;

  if (bin) {
    if (isWildcard(bin)) {
      const bins = isShortWildcard(bin) ? [true, false] : bin.enum;
      fns = fns.concat(contains(bins, true) ? ['bin'] : []);
      hasUndefinedInEnum = hasUndefinedInEnum || contains(bins, false);
    } else if (bin) {
      fn = 'bin';
    }
  }

  if (aggregate) {
    if (isWildcard(aggregate)) {
      const aggregates = isShortWildcard(aggregate) ? config.enum.aggregate : aggregate.enum;
      fns = fns.concat(
        // We already filter composite aggregate function so it is fine to cast here
        // as the only thing left would be AggregateOp (but TS would not know that)
        aggregates.filter(excludeUndefined) as AggregateOp[]
      );
      hasUndefinedInEnum = hasUndefinedInEnum || contains(aggregates, undefined);
    } else if (!fn) {
      fn = aggregate;
github vega / voyager / src / models / shelf / spec / function.ts View on Github external
fieldQParts: FieldQueryFunctionMixins
): ShelfFunction | Wildcard {

  // FIXME make this a parameter
  const config = DEFAULT_QUERY_CONFIG;

  const {aggregate, bin, hasFn, timeUnit} = fieldQParts;

  let fns: ShelfFunction[] = [];
  let fn: ShelfFunction;
  let hasUndefinedInEnum = false;

  if (bin) {
    if (isWildcard(bin)) {
      const bins = isShortWildcard(bin) ? [true, false] : bin.enum;
      fns = fns.concat(contains(bins, true) ? ['bin'] : []);
      hasUndefinedInEnum = hasUndefinedInEnum || contains(bins, false);
    } else if (bin) {
      fn = 'bin';
    }
  }

  if (aggregate) {
    if (isWildcard(aggregate)) {
      const aggregates = isShortWildcard(aggregate) ? config.enum.aggregate : aggregate.enum;
      fns = fns.concat(
        // We already filter composite aggregate function so it is fine to cast here
        // as the only thing left would be AggregateOp (but TS would not know that)
        aggregates.filter(excludeUndefined) as AggregateOp[]
      );
      hasUndefinedInEnum = hasUndefinedInEnum || contains(aggregates, undefined);
    } else if (!fn) {
github vega / voyager / src / models / shelf / spec / function.ts View on Github external
// as the only thing left would be AggregateOp (but TS would not know that)
        aggregates.filter(excludeUndefined) as AggregateOp[]
      );
      hasUndefinedInEnum = hasUndefinedInEnum || contains(aggregates, undefined);
    } else if (!fn) {
      fn = aggregate;
    } else {
      throw Error(`Invalid field with function ${fn} and ${aggregate}`);
    }
  }

  if (timeUnit) {
    if (isWildcard(timeUnit)) {
      const timeUnits = isShortWildcard(timeUnit) ? config.enum.timeUnit : timeUnit.enum;
      fns = fns.concat(timeUnits.filter(excludeUndefined));
      hasUndefinedInEnum = hasUndefinedInEnum || contains(timeUnits, undefined);
    } else if (!fn) {
      fn = timeUnit;
    } else {
      throw Error(`Invalid field with function ${fn} and ${timeUnit}`);
    }
  }

  if (fn) {
    return fn;
  }

  if (hasUndefinedInEnum && !hasFn) {
    // prepend undefined
    fns.unshift(undefined);
  }
github vega / voyager / src / components / encoding-pane / property-editor-schema.ts View on Github external
function getSupportedScaleTypes(channel: Channel, fieldDef: ShelfFieldDef): string[] {
  switch (fieldDef.type) {
    case ExpandedType.QUANTITATIVE:
      if (contains([Channel.X, Channel.Y], channel)) {
        return ["linear", "log", "pow", "sqrt"];
      } else if (channel === Channel.COLOR) {
        return ["linear", "pow", "sqrt", "log", "sequential"];
      } else if (channel === Channel.SIZE) {
        return ["linear", "pow", "sqrt", "log"];
      } else {
        return [];
      }

    case ExpandedType.ORDINAL:
    case ExpandedType.NOMINAL:
      if (contains([Channel.X, Channel.Y], channel)) {
        return ["point", "band"];
      } else if (channel === Channel.COLOR) {
        return ["ordinal"];
      } else if (channel === Channel.SIZE) {
        return ["point", "band"];
      } else {
        return [];
      }

    case ExpandedType.TEMPORAL:
      if (contains([Channel.X, Channel.Y], channel)) {
        return ["time", "utc"];
      } else if (channel === Channel.COLOR) {
        return ["time", "utc", "sequential"];
      } else if (channel === Channel.SIZE) {
        return ["time", "utc"];
github vega / voyager / src / components / encoding-pane / property-editor-schema.ts View on Github external
export function isContinuous(fieldDef: ShelfFieldDef) {
  return contains([ExpandedType.ORDINAL, ExpandedType.TEMPORAL, ExpandedType.QUANTITATIVE], fieldDef.type);
}
github vega / voyager / src / components / encoding-pane / function-picker.tsx View on Github external
const checkboxradios = supportedFns.map(f => (
      <label>
        <input value="{f" checked="{isWildcard(fn)" type="{fnIsWildcard">
        {' '}
        {f || '-'}
      </label>
    ));
github vega / voyager / src / components / encoding-pane / property-editor-schema.ts View on Github external
}

    case ExpandedType.ORDINAL:
    case ExpandedType.NOMINAL:
      if (contains([Channel.X, Channel.Y], channel)) {
        return ["point", "band"];
      } else if (channel === Channel.COLOR) {
        return ["ordinal"];
      } else if (channel === Channel.SIZE) {
        return ["point", "band"];
      } else {
        return [];
      }

    case ExpandedType.TEMPORAL:
      if (contains([Channel.X, Channel.Y], channel)) {
        return ["time", "utc"];
      } else if (channel === Channel.COLOR) {
        return ["time", "utc", "sequential"];
      } else if (channel === Channel.SIZE) {
        return ["time", "utc"];
      } else {
        return [];
      }

    default:
      return [];
  }
}