@data-ui/histogram
Version:
React + d3 library for creating histograms
16 lines (15 loc) • 521 B
JavaScript
/* eslint no-param-reassign: 0 */
// bins should minimally have the shape
// Array<Object{ count: Number }>
export default 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;
});
}