How to use the vega-util.constant 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-transforms / src / Window.js View on Github external
function processPartition(list, state, cmp, _) {
  var sort = _.sort,
      range = sort && !_.ignorePeers,
      frame = _.frame || [null, 0],
      data = list.data(cmp), // use cmp for stable sort
      n = data.length,
      i = 0,
      b = range ? bisector(sort) : null,
      w = {
        i0: 0, i1: 0, p0: 0, p1: 0, index: 0,
        data: data, compare: sort || constant(-1)
      };

  for (state.init(); i
github vega / vega / packages / vega-geo / src / Heatmap.js View on Github external
source.forEach(t => {
    const v = field(t);

    // build proxy data object
    const o = extend({}, t, obj);
    // set maximum value if not globally shared
    if (!shared) o.$max = max(v.values || []);

    // generate canvas image
    // optimize color/opacity if not pixel-dependent
    t[as] = toCanvas(v, o,
      color.dep ? color : constant(color(o)),
      opacity.dep ? opacity : constant(opacity(o))
    );
  });
github vega / vega / packages / vega-geo / src / Heatmap.js View on Github external
source.forEach(t => {
    const v = field(t);

    // build proxy data object
    const o = extend({}, t, obj);
    // set maximum value if not globally shared
    if (!shared) o.$max = max(v.values || []);

    // generate canvas image
    // optimize color/opacity if not pixel-dependent
    t[as] = toCanvas(v, o,
      color.dep ? color : constant(color(o)),
      opacity.dep ? opacity : constant(opacity(o))
    );
  });
github vega / vega-dataflow / src / encode / LegendEntries.js View on Github external
prototype.transform = function(_, pulse) {
  if (this.value != null && !_.modified()) {
    return pulse.StopPropagation;
  }

  var out = pulse.fork(),
      items = this.value,
      size  = _.size,
      scale = _.scale,
      count = _.count == null ? 5 : _.count,
      format = _.format || tickFormat(scale, count, _.formatSpecifier),
      values = _.values || tickValues(scale, count),
      total = 0;

  if (!isFunction(size)) size = constant(size || 8);
  if (items) out.rem = items;

  items = values.map(function(value, index) {
    var t = ingest({
      index: index,
      label: format(value),
      size:  size(value),
      total: Math.round(total),
      value: value
    });
    total += t.size;
    return t;
  });

  return (out.source = out.add = this.value = items), out;
};
github vega / vega / src / view / events-extend.js View on Github external
function xy(item) {
    if (!item) return point;
    if (isString(item)) item = group(item);

    var p = point.slice();
    while (item) {
      p[0] -= item.x || 0;
      p[1] -= item.y || 0;
      item = item.mark && item.mark.group;
    }
    return p;
  }

  return {
    view:  constant(view),
    item:  constant(item || {}),
    group: group,
    xy:    xy,
    x:     function(item) { return xy(item)[0]; },
    y:     function(item) { return xy(item)[1]; }
  };
}
github vega / vega / packages / vega-view / src / events-extend.js View on Github external
function xy(item) {
    if (!item) return point;
    if (isString(item)) item = group(item);

    var p = point.slice();
    while (item) {
      p[0] -= item.x || 0;
      p[1] -= item.y || 0;
      item = item.mark && item.mark.group;
    }
    return p;
  }

  return {
    view:  constant(view),
    item:  constant(item || {}),
    group: group,
    xy:    xy,
    x:     function(item) { return xy(item)[0]; },
    y:     function(item) { return xy(item)[1]; }
  };
}
github vega / vega / packages / vega-view / src / events-extend.js View on Github external
function xy(item) {
    if (!item) return point;
    if (isString(item)) item = group(item);

    var p = point.slice();
    while (item) {
      p[0] -= item.x || 0;
      p[1] -= item.y || 0;
      item = item.mark && item.mark.group;
    }
    return p;
  }

  return {
    view:  constant(view),
    item:  constant(item || {}),
    group: group,
    xy:    xy,
    x:     function(item) { return xy(item)[0]; },
    y:     function(item) { return xy(item)[1]; }
  };
}
github vega / vega / packages / vega-dataflow / src / dataflow / on.js View on Github external
function onStream(df, stream, target, update, params, options) {
  var opt = extend({}, options, SKIP), func, op;

  if (!isFunction(target)) target = constant(target);

  if (update === undefined) {
    func = function(e) {
      df.touch(target(e));
    };
  } else if (isFunction(update)) {
    op = new Operator(null, update, params, false);
    func = function(e) {
      var v, t = target(e);
      op.evaluate(e);
      isChangeSet(v = op.value) ? df.pulse(t, v, options) : df.update(t, v, opt);
    };
  } else {
    func = function(e) {
      df.update(target(e), update, opt);
    };
github vega / vega / src / view / events-extend.js View on Github external
function xy(item) {
    if (!item) return point;
    if (isString(item)) item = group(item);

    var p = point.slice();
    while (item) {
      p[0] -= item.x || 0;
      p[1] -= item.y || 0;
      item = item.mark && item.mark.group;
    }
    return p;
  }

  return {
    view:  constant(view),
    item:  constant(item || {}),
    group: group,
    xy:    xy,
    x:     function(item) { return xy(item)[0]; },
    y:     function(item) { return xy(item)[1]; }
  };
}