"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.getHistogram = void 0;
const getHistogram = function () {
  let dataSource = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
  let resolution = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 12;
  const values = dataSource.filter(value => value > 0).map(value => parseInt(value)).sort((a, b) => a - b);
  let bins = [];
  let max;
  let maxBinCount;
  let min;
  if (values.length >= resolution) {
    max = Math.max(...values);
    min = Math.min(...values);
    const binSize = (max - min) / resolution;
    bins = Array.from({
      length: resolution
    }, (_, i) => ({
      range: [min + i * binSize, min + (i + 1) * binSize],
      count: 0
    }));
    values.forEach(value => {
      if (value >= min && value <= max) {
        const binIndex = Math.min(Math.floor((value - min) / binSize), resolution - 1);
        if (bins[binIndex]) bins[binIndex].count++;
      }
    });
    maxBinCount = Math.max(...bins.map(bin => bin.count));
  }
  const {
    length: binsFilled
  } = bins.filter(function () {
    let {
      count
    } = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
    return count > 0;
  });
  return binsFilled >= resolution / 2 ? {
    bins,
    max,
    maxBinCount,
    min,
    values
  } : {};
};
exports.getHistogram = getHistogram;
//# sourceMappingURL=getHistogram.js.map