How to use the vega-dataflow.stableCompare function in vega-dataflow

To help you get started, we’ve selected a few vega-dataflow 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-transforms / src / Collect.js View on Github external
prototype.transform = function(_, pulse) {
  var out = pulse.fork(pulse.ALL),
      list = SortedList(tupleid, this.value, out.materialize(out.ADD).add),
      sort = _.sort,
      mod = pulse.changed() || (sort &&
            (_.modified('sort') || pulse.modified(sort.fields)));

  out.visit(out.REM, list.remove);

  this.modified(mod);
  this.value = out.source = list.data(stableCompare(sort), mod);

  // propagate tree root if defined
  if (pulse.source && pulse.source.root) {
    this.value.root = pulse.source.root;
  }

  return out;
};
github vega / vega / packages / vega-encode / src / Stack.js View on Github external
prototype.transform = function(_, pulse) {
  var as = _.as || DefOutput,
      y0 = as[0],
      y1 = as[1],
      sort = stableCompare(_.sort),
      field = _.field || one,
      stack = _.offset === Center ? stackCenter
            : _.offset === Normalize ? stackNormalize
            : stackZero,
      groups, i, n, max;

  // partition, sum, and sort the stack groups
  groups = partition(pulse.source, _.groupby, sort, field);

  // compute stack layouts per group
  for (i=0, n=groups.length, max=groups.max; i
github vega / vega / packages / vega-transforms / src / DotBin.js View on Github external
prototype.transform = function(_, pulse) {
  if (this.value && !(_.modified() || pulse.changed())) {
    return pulse; // early exit
  }

  const source = pulse.materialize(pulse.SOURCE).source,
        groups = partition(pulse.source, _.groupby, identity),
        smooth = _.smooth || false,
        field = _.field,
        step = _.step || autostep(source, field),
        sort = stableCompare((a, b) => field(a) - field(b)),
        as = _.as || Output,
        n = groups.length;

  // compute dotplot bins per group
  let min = Infinity, max = -Infinity, i = 0, j;
  for (; i max) max = v;
      g[++j][as] = v;
    }
  }

  this.value = {
github vega / vega / packages / vega-transforms / src / Window.js View on Github external
prototype.transform = function(_, pulse) {
  var self = this,
      state = self.state,
      mod = _.modified(),
      cmp = stableCompare(_.sort),
      i, n;

  this.stamp = pulse.stamp;

  // initialize window state
  if (!state || mod) {
    state = self.state = new WindowState(_);
  }

  // retrieve group for a tuple
  var key = groupkey(_.groupby);
  function group(t) { return self.group(key(t)); }

  // partition input tuples
  if (mod || pulse.modified(state.inputs)) {
    self.value = {};
github vega / vega / packages / vega-encode / src / SortItems.js View on Github external
prototype.transform = function(_, pulse) {
  var mod = _.modified('sort')
         || pulse.changed(pulse.ADD)
         || pulse.modified(_.sort.fields)
         || pulse.modified('datum');

  if (mod) pulse.source.sort(stableCompare(_.sort));

  this.modified(mod);
  return pulse;
};
github vega / vega / packages / vega-transforms / src / Values.js View on Github external
prototype.transform = function(_, pulse) {
  var run = !this.value
    || _.modified('field')
    || _.modified('sort')
    || pulse.changed()
    || (_.sort && pulse.modified(_.sort.fields));

  if (run) {
    this.value = (_.sort
      ? pulse.source.slice().sort(stableCompare(_.sort))
      : pulse.source).map(_.field);
  }
};