How to use the d3-array.sum 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 rrag / react-stockcharts / src / lib / interactive / components / LinearRegressionChannelWithArea.js View on Github external
const startIndex = Math.min(left, right);
	const endIndex = Math.max(left, right) + 1;

	const array = fullData.slice(startIndex, endIndex);

	const xs = array.map(d => xAccessor(d).valueOf());
	const ys = array.map(d => d.close);
	const n = array.length;

	const combine = zipper()
		.combine((x, y) => x * y);

	const xys = combine(xs, ys);
	const xSquareds = xs.map(x => Math.pow(x, 2));

	const b = (n * sum(xys) - sum(xs) * sum(ys)) / (n * sum(xSquareds) - Math.pow(sum(xs), 2));
	const a = (sum(ys) - b * sum(xs)) / n;

	const newy1 = a + b * x1Value;
	const newy2 = a + b * x2Value;

	const x1 = xScale(x1Value);
	const y1 = yScale(newy1);
	const x2 = xScale(x2Value);
	const y2 = yScale(newy2);

	const stdDev = type === "SD"
		? deviation(array, d => d.close)
		: 0;

	const dy = yScale(newy1 - stdDev) - y1;
github elastic / elastic-charts / src / chart_types / xy_chart / domains / y_domain.ts View on Github external
function computeYStackedDomain(dataseries: RawDataSeries[], scaleToExtent: boolean): number[] {
  const stackMap = new Map();
  dataseries.forEach((ds, index) => {
    ds.data.forEach((datum) => {
      const stack = stackMap.get(datum.x) || [];
      stack[index] = datum.y1;
      stackMap.set(datum.x, stack);
    });
  });
  const dataValues = [];
  for (const stackValues of stackMap) {
    dataValues.push(...stackValues[1]);
    if (stackValues[1].length > 1) {
      dataValues.push(sum(stackValues[1]));
    }
  }
  if (dataValues.length === 0) {
    return [];
  }
  return computeContinuousDataDomain(dataValues, identity, scaleToExtent);
}
github apache / druid / web-console / src / views / home-view / lookups-card / lookups-card.tsx View on Github external
processQuery: async capabilities => {
        if (capabilities.hasCoordinatorAccess()) {
          const resp = await axios.get('/druid/coordinator/v1/lookups/status');
          const data = resp.data;
          const lookupsCount = sum(Object.keys(data).map(k => Object.keys(data[k]).length));
          return {
            lookupsCount,
          };
        } else {
          throw new Error(`must have coordinator access`);
        }
      },
      onStateChange: ({ result, loading, error }) => {
github orbiting / republik-frontend / components / Shareholder / data.js View on Github external
.key(d => d.Kategorie)
    .entries(data)
    .map(d => {
      if (d.values.length > 1) {
        return {
          ...d.values[0],
          Anzahl: undefined,
          children: d.values
        }
      }
      return d.values[0]
    })
}).sum(d => d.Anzahl)

export const total = sum(data, d => +d.Anzahl)
export const totalChf = sum(data, d => +d.Anzahl * d['Nominal CHF'])

export const colors = {
  Geldgeber: 'rgb(157, 38, 14)',
  Gründerteam: 'rgb(54, 71, 63)',
  'Eigenaktien Republik': '#979797',
  'Project R Gen': 'rgb(65, 171, 29)'
}
github rrag / react-stockcharts / src / lib / interactive / components / LinearRegressionChannelWithArea.js View on Github external
const endIndex = Math.max(left, right) + 1;

	const array = fullData.slice(startIndex, endIndex);

	const xs = array.map(d => xAccessor(d).valueOf());
	const ys = array.map(d => d.close);
	const n = array.length;

	const combine = zipper()
		.combine((x, y) => x * y);

	const xys = combine(xs, ys);
	const xSquareds = xs.map(x => Math.pow(x, 2));

	const b = (n * sum(xys) - sum(xs) * sum(ys)) / (n * sum(xSquareds) - Math.pow(sum(xs), 2));
	const a = (sum(ys) - b * sum(xs)) / n;

	const newy1 = a + b * x1Value;
	const newy2 = a + b * x2Value;

	const x1 = xScale(x1Value);
	const y1 = yScale(newy1);
	const x2 = xScale(x2Value);
	const y2 = yScale(newy2);

	const stdDev = type === "SD"
		? deviation(array, d => d.close)
		: 0;

	const dy = yScale(newy1 - stdDev) - y1;

	return {
github tomshanley / d3-sankey-circular / dist / d3-sankey-circular.es.js View on Github external
graph.nodes.forEach(function (node) {
      node.partOfCycle = false;
      node.value = Math.max(sum(node.sourceLinks, value), sum(node.targetLinks, value));
      node.sourceLinks.forEach(function (link) {
        if (link.circular) {
          node.partOfCycle = true;
          node.circularLinkType = link.circularLinkType;
        }
      });
      node.targetLinks.forEach(function (link) {
        if (link.circular) {
          node.partOfCycle = true;
          node.circularLinkType = link.circularLinkType;
        }
      });
    });
  }
github elastic / elastic-charts / src / utils / domain.ts View on Github external
.rollup((values: any) => {
      return sum(values, yAccessor);
    })
    .entries(data);
github ricklupton / d3-sankey-diagram / src / sankey.js View on Github external
function maybeScaleToFit (G, nested) {
    if (scale !== null) return
    const maxValue = sum(nested.bandValues)
    if (maxValue <= 0) {
      scale = 1
    } else {
      scale = (y1 - y0) / maxValue
      if (whitespace !== 1) scale *= (1 - whitespace)
    }
  }