How to use the d3-array.mean function in d3-array

To help you get started, we’ve selected a few d3-array 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 DefinitelyTyped / DefinitelyTyped / d3-array / d3-array-tests.ts View on Github external
// with accessors

numOrUndefinedExtent = d3Array.extent(mixedObjectArray, accessorMixedObjectToNum);
strOrUndefinedExtent = d3Array.extent(mixedObjectArray, accessorMixedObjectToStr);
mixedOrUndefinedExtent = d3Array.extent(mixedObjectArray, accessorMixedObjectToNumeric);
dateMixedOrUndefined = d3Array.extent(mixedObjectArray, accessorMixedObjectToDate);
numOrUndefinedExtent = d3Array.extent(mixedObjectArray, accessorMixedObjectToNumOrUndefined);
strOrUndefinedExtent = d3Array.extent(mixedObjectArray, accessorMixedObjectToStrOrUndefined);

// mean() ----------------------------------------------------------------------

numOrUndefined = d3Array.mean(numbersArray);
numOrUndefined = d3Array.mean(numericArray);
numOrUndefined = d3Array.mean(numbersOrUndefinedArray);

numOrUndefined = d3Array.mean(mixedObjectArray, accessorMixedObjectToNum);
numOrUndefined = d3Array.mean(mixedObjectOrUndefinedArray, accessorMixedObjectToNumOrUndefined);

// median() --------------------------------------------------------------------

numOrUndefined = d3Array.median(numbersArray);
numOrUndefined = d3Array.median(numericArray);
numOrUndefined = d3Array.median(numbersOrUndefinedArray);

numOrUndefined = d3Array.median(mixedObjectArray, accessorMixedObjectToNum);
numOrUndefined = d3Array.median(mixedObjectOrUndefinedArray, accessorMixedObjectToNumOrUndefined);

// quantile() ------------------------------------------------------------------

numOrUndefined = d3Array.quantile(numbersArray, 0.5);
numOrUndefined = d3Array.quantile(numericArray, 0.5);
numOrUndefined = d3Array.quantile(numbersOrUndefinedArray, 0.5);
github DefinitelyTyped / DefinitelyTyped / d3-array / d3-array-tests.ts View on Github external
numericOrUndefinedExtent = d3Array.extent(numericArray);
dateOrUndefinedExtent = d3Array.extent(dateArray);

// with accessors

numOrUndefinedExtent = d3Array.extent(mixedObjectArray, accessorMixedObjectToNum);
strOrUndefinedExtent = d3Array.extent(mixedObjectArray, accessorMixedObjectToStr);
mixedOrUndefinedExtent = d3Array.extent(mixedObjectArray, accessorMixedObjectToNumeric);
dateMixedOrUndefined = d3Array.extent(mixedObjectArray, accessorMixedObjectToDate);
numOrUndefinedExtent = d3Array.extent(mixedObjectArray, accessorMixedObjectToNumOrUndefined);
strOrUndefinedExtent = d3Array.extent(mixedObjectArray, accessorMixedObjectToStrOrUndefined);

// mean() ----------------------------------------------------------------------

numOrUndefined = d3Array.mean(numbersArray);
numOrUndefined = d3Array.mean(numericArray);
numOrUndefined = d3Array.mean(numbersOrUndefinedArray);

numOrUndefined = d3Array.mean(mixedObjectArray, accessorMixedObjectToNum);
numOrUndefined = d3Array.mean(mixedObjectOrUndefinedArray, accessorMixedObjectToNumOrUndefined);

// median() --------------------------------------------------------------------

numOrUndefined = d3Array.median(numbersArray);
numOrUndefined = d3Array.median(numericArray);
numOrUndefined = d3Array.median(numbersOrUndefinedArray);

numOrUndefined = d3Array.median(mixedObjectArray, accessorMixedObjectToNum);
numOrUndefined = d3Array.median(mixedObjectOrUndefinedArray, accessorMixedObjectToNumOrUndefined);

// quantile() ------------------------------------------------------------------
github tmrowco / electricitymap-contrib / web / src / main.js View on Github external
function centerOnZoneName(state, zoneName, zoomLevel) {
  if (typeof zoneMap === 'undefined') { return; }
  const selectedZone = state.data.grid.zones[zoneName];
  const selectedZoneCoordinates = [];
  selectedZone.geometry.coordinates.forEach((geojson) => {
    // selectedZoneCoordinates.push(geojson[0]);
    geojson[0].forEach((coord) => {
      selectedZoneCoordinates.push(coord);
    });
  });
  const maxLon = d3Max(selectedZoneCoordinates, d => d[0]);
  const minLon = d3Min(selectedZoneCoordinates, d => d[0]);
  const maxLat = d3Max(selectedZoneCoordinates, d => d[1]);
  const minLat = d3Min(selectedZoneCoordinates, d => d[1]);
  const lon = d3Mean([minLon, maxLon]);
  const lat = d3Mean([minLat, maxLat]);

  zoneMap.setCenter([lon, lat]);
  if (zoomLevel) {
    // Remember to set center and zoom in case the map wasn't loaded yet
    zoneMap.setZoom(zoomLevel);
    // If the panel is open the zoom doesn't appear perfectly centered because
    // it centers on the whole window and not just the visible map part.
    // something one could fix in the future. It's tricky because one has to project, unproject
    // and project again taking both starting and ending zoomlevel into account
    zoneMap.map.easeTo({ center: [lon, lat], zoom: zoomLevel });
  }
}
github CartoDB / carto.js / src / dataviews / histogram-dataview-model.js View on Github external
getDistributionType: function (data) {
    var histogram = data || this.get('data');
    var freqAccessor = function (a) { return a.freq; };
    var osc = d3.max(histogram, freqAccessor) - d3.min(histogram, freqAccessor);
    var mean = d3.mean(histogram, freqAccessor);
    // When the difference between the max and the min values is less than
    // 10 percent of the mean, it's a flat histogram (F)
    if (osc < mean * 0.1) return 'F';
    var sumFreqs = d3.sum(histogram, freqAccessor);
    var freqs = histogram.map(function (bin) {
      return 100 * bin.freq / sumFreqs;
    });

    // The ajus array represents relative growths
    var ajus = freqs.map(function (freq, index) {
      var next = freqs[index + 1];
      if (freq > next) return -1;
      if (Math.abs(freq - next) <= 0.05) return 0;
      return 1;
    });
    ajus.pop();
github tidepool-org / viz / src / utils / trends / data.js View on Github external
export function calculateSmbgStatsForBin(binKey, binSize, data, outOfRange) {
  const centerOfBinMs = parseInt(binKey, 10);
  const stats = {
    id: binKey,
    min: min(data),
    mean: mean(data),
    max: max(data),
    msX: centerOfBinMs,
    msFrom: centerOfBinMs - (binSize / 2),
    msTo: centerOfBinMs + (binSize / 2),
  };
  if (!_.isEmpty(outOfRange)) {
    const thresholds = determineRangeBoundaries(outOfRange);
    stats.outOfRangeThresholds = thresholds;
  }
  return stats;
}
github samccone / bundle-buddy / viz / src / NetworkZoom.js View on Github external
Math.round(maxLines * 0.5),
      maxLines
    ])
    .orient("horizontal");
  svg.select("g.sizeLegend").selectAll(".cells").remove();
  svg.select("g.sizeLegend").call(sizeLegend);
  updateNetworkPosition(containerWidth);

  const match = svg.select(".node.selectedBundle");

  const nx = min(svg.selectAll(".node").data(), d => d.x - size(d.size)) - 10;

  const sources = svg.selectAll(".node").data().filter(d => d.type === "input");
  const minSource = min(sources, d => d.x);
  const maxSource = max(sources, d => d.x);
  const avgY = mean(sources, d => d.y);
  const maxHeight = size(max(sources, d => d.size));
  const rectPadding = 20;
  const wrap = containerWidth / 2 - (match.datum().x - nx);

  const selectedBundlesY = max(svg.selectAll(".node").data(), d => d.y);

  let annotations = [
    {
      note: {
        title: "Selected Bundle",
        wrap,
        label: stripHashes(selectedBundles),
        align: "middle",
        lineType: "vertical"
      },
      type: annotationCallout,
github rrag / react-stockcharts / src / lib / calculator / bollingerband.js View on Github external
				.accumulator(values => mean(values)).sourcePath(sourcePath);
github pritishvaidya / react-native-soundcloud-waveform / src / components / Waveform.js View on Github external
backgroundColor: getColor(
              chunks,
              i,
              percentPlayed,
              percentPlayable,
              inverse,
              active,
              activeInverse,
              activePlayable,
              activePlayableInverse,
              inactive,
              inactiveInverse,
            ),
            width: 2,
            marginRight: 1,
            height: scaleLinearHeight(mean(chunk)),
          }}
          />
        
      ))}
github chanzuckerberg / idseq-web / app / assets / src / components / visualizations / Histogram.js View on Github external
.attr("class", (_, index) => `rect-${index}`)
        .attr("x", d => x(d.x0) + i * this.getBarWidth(x, d))
        .attr("width", d => this.getBarWidth(x, d))
        .attr("y", d => y(d.length))
        .attr("height", d => y(0) - y(d.length))
        .style("opacity", barOpacity);

      bins[i].forEach((bin, index) => {
        let barWidth = this.getBarWidth(x, bin);
        const xMidpoint = x(bin.x0) + i * barWidth + barWidth / 2;
        barCentersToIndices[xMidpoint] = [i, index];
        barCenters.push(xMidpoint);
      });

      if (this.options.showStatistics) {
        let avg = mean(this.data[i]);
        let dev = deviation(this.data[i]);

        let stats = this.svg.append("g");

        stats
          .append("line")
          .attr("stroke", colors[i])
          .attr("x1", x(avg))
          .attr("x2", x(avg))
          .attr("y1", this.margins.top)
          .attr("y2", this.size.height - this.margins.bottom);

        let rect0 = max([x(avg - dev), this.margins.left]);
        let rect1 = min([x(avg + dev), this.size.width - this.margins.right]);
        let rectWidth = rect1 - rect0;
github localvoid / uibench / src / index.jsx View on Github external
const values = reports.map((r) => {
        const samples = r.samples[sampleName];

        return {
          sampleCount: samples.length,
          median: d3median(samples),
          mean: d3mean(samples),
          stdev: stdev(samples),
          min: d3min(samples),
          max: d3max(samples),
        };
      });