How to use vega-statistics - 10 common examples

To help you get started, we’ve selected a few vega-statistics 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 domoritz / line-density / demo / demo.ts View on Github external
let canvas;
  document.getElementById("regl").innerText = "";
  if ((document.getElementById("debug") as HTMLInputElement).checked) {
    canvas = document.createElement("canvas");
    document.getElementById("regl").appendChild(canvas);
  }

  const maxY = (data.data as Float32Array).reduce(
    (agg, val) => Math.max(agg, val),
    0
  );

  // compute nice bin boundaries
  const binConfigX = bin({ maxbins: binsx, extent: [0, points - 1] });
  const binConfigY = bin({ maxbins: binsy, extent: [0, maxY] });

  start = Date.now();
  compute(data, binConfigX, binConfigY, canvas).then(heatmapData => {
    document.getElementById("computetime").innerText = `${(Date.now() - start) /
      1000} seconds`;
    heatmap(heatmapData, binConfigX, binConfigY);
  });
}
github uwdata / errudite / ui / src / components / attr-manager / AttrBar.tsx View on Github external
extent.push(extent[0] === 1 ? extent[0] + 0.1 : extent[0] + 1);
            }
            // the performance distribution is always [0, 1]
            const binIdxes = d3.range(0, this.binCount - 2);
            const binFunction = d3.scaleQuantile()
                .domain(d3.merge([
                    this.flatCounts.correct.concat(this.flatCountsRewrite.correct) as number[], 
                    this.flatCounts.incorrect.concat(this.flatCountsRewrite.incorrect) as number[]]))
                .range(binIdxes);

            this.scale.attrScale_continue.domain(extent);
            let bins = d3.merge([
                [extent[0]],binFunction.quantiles(), 
                [extent[1]]]).filter(utils.uniques) as number[];            
            if ( (bins[bins.length-1] - bins[0] <= 1) || bins.length < this.binCount * 0.6) {
                const bins_ = vegaStat.bin({extent: extent, nice: false, maxbins: this.binCount });
                this.scale.bins = d3.range(bins_.start, bins_.stop + bins_.step, bins_.step);
            } else {
                //bins.push(extent[1] === 1 ? extent[1] + 0.1 : extent[1] + 1);
                this.scale.bins = bins;
            }
        } else {
            this.scale.bins = this.domain.slice();//this.attr.stats.map(s => s.value);
            this.scale.attrScale_discrete.domain(this.scale.bins as string[]);
        }
        /*
        if (this.props.attr.name === "groundtruths_length") {
            this.scale.attrScale_continue.domain([1, 20]);
            this.scale.bins = [1, 2, 3, 4, 5, 6, 7, 8, 20]
        }
        if (this.props.attr.name === "prediction_length") {
            this.scale.attrScale_continue.domain([1, 50]);
github domoritz / line-density / demo / demo.ts View on Github external
lineChart(data);

  let canvas;
  document.getElementById("regl").innerText = "";
  if ((document.getElementById("debug") as HTMLInputElement).checked) {
    canvas = document.createElement("canvas");
    document.getElementById("regl").appendChild(canvas);
  }

  const maxY = (data.data as Float32Array).reduce(
    (agg, val) => Math.max(agg, val),
    0
  );

  // compute nice bin boundaries
  const binConfigX = bin({ maxbins: binsx, extent: [0, points - 1] });
  const binConfigY = bin({ maxbins: binsy, extent: [0, maxY] });

  start = Date.now();
  compute(data, binConfigX, binConfigY, canvas).then(heatmapData => {
    document.getElementById("computetime").innerText = `${(Date.now() - start) /
      1000} seconds`;
    heatmap(heatmapData, binConfigX, binConfigY);
  });
}
github vega / vega / packages / vega-regression / src / Regression.js View on Github external
add = p => {
              const t = {};
              for (let i=0; i add([x, model.predict(x)]));
      } else {
        // otherwise return trend line sample points
        sampleCurve(model.predict, dom, 25, 200).forEach(add);
      }
    });
github vega / vega / packages / vega-transforms / src / DotBin.js View on Github external
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 = {
    start: min,
    stop: max,
    step: step
  };
  return pulse.reflow(true).modifies(as);
};
github vega / vega / packages / vega-transforms / src / Sample.js View on Github external
function update(t) {
    var p, idx;

    if (res.length < num) {
      res.push(t);
    } else {
      idx = ~~((cnt + 1) * random());
      if (idx < res.length && idx >= cap) {
        p = res[idx];
        if (map[tupleid(p)]) out.rem.push(p); // eviction
        res[idx] = t;
      }
    }
    ++cnt;
  }
github vega / vega-dataflow / src / transforms / Bin.js View on Github external
prototype._bins = function(_) {
  if (this.value && !_.modified()) {
    return this.value;
  }

  var field = _.field,
      bins  = bin(_),
      start = bins.start,
      stop  = bins.stop,
      step  = bins.step,
      a, d;

  if ((a = _.anchor) != null) {
    d = a - (start + step * Math.floor((a - start) / step));
    start += d;
    stop += d;
  }

  var f = function(t) {
    var v = field(t);
    if (v == null) {
      return null;
    } else {
github vega / vega / packages / vega-transforms / src / Bin.js View on Github external
prototype._bins = function(_) {
  if (this.value && !_.modified()) {
    return this.value;
  }

  var field = _.field,
      bins  = bin(_),
      step  = bins.step,
      start = bins.start,
      stop  = start + Math.ceil((bins.stop - start) / step) * step,
      a, d;

  if ((a = _.anchor) != null) {
    d = a - (start + step * Math.floor((a - start) / step));
    start += d;
    stop += d;
  }

  var f = function(t) {
    var v = field(t);
    return v == null ? null
      : v < start ? -Infinity
      : v > stop ? +Infinity
github vega / vega / packages / vega-transforms / src / KDE.js View on Github external
groups.forEach(g => {
      const density = randomKDE(g, bandwidth)[method],
            scale = _.counts ? g.length : 1,
            local = domain || extent(g);

      sampleCurve(density, local, minsteps, maxsteps).forEach(v => {
        const t = {};
        for (let i=0; i
github vega / vega / packages / vega-transforms / src / Density.js View on Github external
var dist = parseDist(_.distribution, source(pulse)),
        minsteps = _.steps || _.minsteps || 25,
        maxsteps = _.steps || _.maxsteps || 200,
        method = _.method || 'pdf';

    if (method !== 'pdf' && method !== 'cdf') {
      error('Invalid density method: ' + method);
    }
    if (!_.extent && !dist.data) {
      error('Missing density extent parameter.');
    }
    method = dist[method];

    var as = _.as || ['value', 'density'],
        domain = _.extent || extent(dist.data()),
        values = sampleCurve(method, domain, minsteps, maxsteps).map(v => {
          var tuple = {};
          tuple[as[0]] = v[0];
          tuple[as[1]] = v[1];
          return ingest(tuple);
        });

    if (this.value) out.rem = this.value;
    this.value = out.add = out.source = values;
  }

  return out;
};