How to use the vega-util.peek function in vega-util

To help you get started, we’ve selected a few vega-util 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 / vega / packages / vega-parser / src / parsers / encode / rule.js View on Github external
export default function(channel, rules, scope, params, fields) {
  var code = '';

  rules.forEach(function(rule) {
    var value = entry(channel, rule, scope, params, fields);
    code += rule.test
      ? expression(rule.test, scope, params, fields) + '?' + value + ':'
      : value;
  });

  // if no else clause, terminate with null (vega/vega#1366)
  if (peek(code) === ':') {
    code += 'null';
  }

  return set('o', channel, code);
}
github vega / vega / packages / vega-encode / src / LegendEntries.js View on Github external
index:    items.length,
        label:    `\u2026${values.length-items.length} entries`,
        value:    ellipsis,
        offset:   offset,
        size:     size(ellipsis, _)
      }));
    }
  }

  else if (type === Gradient) {
    domain = scale.domain(),
    fraction = scaleFraction(scale, domain[0], peek(domain));

    // if automatic label generation produces 2 or fewer values,
    // use the domain end points instead (fixes vega/vega#1364)
    if (values.length < 3 && !_.values && domain[0] !== peek(domain)) {
      values = [domain[0], peek(domain)];
    }

    items = values.map(function(value, index) {
      return ingest({
        index: index,
        label: format(value, index, values),
        value: value,
        perc:  fraction(value)
      });
    });
  }

  else {
    size = values.length - 1;
    fraction = labelFraction(scale);
github vega / vega / packages / vega-encode / src / LegendEntries.js View on Github external
label:    `\u2026${values.length-items.length} entries`,
        value:    ellipsis,
        offset:   offset,
        size:     size(ellipsis, _)
      }));
    }
  }

  else if (type === Gradient) {
    domain = scale.domain(),
    fraction = scaleFraction(scale, domain[0], peek(domain));

    // if automatic label generation produces 2 or fewer values,
    // use the domain end points instead (fixes vega/vega#1364)
    if (values.length < 3 && !_.values && domain[0] !== peek(domain)) {
      values = [domain[0], peek(domain)];
    }

    items = values.map(function(value, index) {
      return ingest({
        index: index,
        label: format(value, index, values),
        value: value,
        perc:  fraction(value)
      });
    });
  }

  else {
    size = values.length - 1;
    fraction = labelFraction(scale);
github vega / vega / packages / vega-selections / src / selectionVisitor.js View on Github external
export function selectionVisitor(name, args, scope, params) {
  if (args[0].type !== Literal) error('First argument to selection functions must be a string literal.');

  const data = args[0].value,
        op = args.length >= 2 && peek(args).value,
        field = 'unit',
        indexName = IndexPrefix + field,
        dataName = DataPrefix + data;

  // eslint-disable-next-line no-prototype-builtins
  if (op === Intersect && !hasOwnProperty(params, indexName)) {
    params[indexName] = scope.getData(data).indataRef(scope, field);
  }

  // eslint-disable-next-line no-prototype-builtins
  if (!hasOwnProperty(params, dataName)) {
    params[dataName] = scope.getData(data).tuplesRef();
  }
}
github vega / vega / packages / vega-encode / src / ticks.js View on Github external
export function validTicks(scale, ticks, count) {
  var range = scale.range(),
      lo = Math.floor(range[0]),
      hi = Math.ceil(peek(range));

  if (lo > hi) {
    range = hi;
    hi = lo;
    lo = range;
  }

  ticks = ticks.filter(function(v) {
    v = scale(v);
    return lo <= v && v <= hi;
  });

  if (count > 0 && ticks.length > 1) {
    var endpoints = [ticks[0], peek(ticks)];
    while (ticks.length > count && ticks.length >= 3) {
      ticks = ticks.filter(function(_, i) { return !(i % 2); });
github vega / vega / packages / vega-encode / src / ticks.js View on Github external
lo = Math.floor(range[0]),
      hi = Math.ceil(peek(range));

  if (lo > hi) {
    range = hi;
    hi = lo;
    lo = range;
  }

  ticks = ticks.filter(function(v) {
    v = scale(v);
    return lo <= v && v <= hi;
  });

  if (count > 0 && ticks.length > 1) {
    var endpoints = [ticks[0], peek(ticks)];
    while (ticks.length > count && ticks.length >= 3) {
      ticks = ticks.filter(function(_, i) { return !(i % 2); });
    }
    if (ticks.length < 3) {
      ticks = endpoints;
    }
  }

  return ticks;
}
github vega / vega / packages / vega-scale / src / scales / scaleBinOrdinal.js View on Github external
scale.tickFormat = function(count, specifier) {
    return tickFormat(domain[0], peek(domain), count == null ? 10 : count, specifier);
  };
github vega / vega / packages / vega-encode / src / labels.js View on Github external
export function labelFraction(scale) {
  var domain = scale.domain(),
      count = domain.length - 1,
      lo = +domain[0],
      hi = +peek(domain),
      span = hi - lo;

  if (scale.type === Threshold) {
    var adjust = count ? span / count : 0.1;
    lo -= adjust;
    hi += adjust;
    span = hi - lo;
  }

  return function(value) {
    return (value - lo) / span;
  };
}
github vega / vega / packages / vega-parser / src / Scope.js View on Github external
prototype.lookup = function() {
  return peek(this._lookup);
};