UNPKG

@data-ui/histogram

Version:

React + d3 library for creating histograms

21 lines (18 loc) 604 B
"use strict"; exports.__esModule = true; exports.default = addDensityAndCumulativeValuesToBins; /* eslint no-param-reassign: 0 */ // bins should minimally have the shape // Array<Object{ count: Number }> function addDensityAndCumulativeValuesToBins(bins) { var cumulative = 0; bins.forEach(function (bin) { cumulative += isNaN(bin.count) ? 0 : bin.count; // eslint-disable-line no-restricted-globals bin.cumulative = cumulative; }); var total = cumulative; bins.forEach(function (bin) { bin.density = bin.count / total; bin.cumulativeDensity = bin.cumulative / total; }); }