| 85596 | threshold = _sturges.default; |
| 85597 | |
| 85598 | function histogram(data) { |
| 85599 | if (!Array.isArray(data)) data = Array.from(data); |
| 85600 | var i, |
| 85601 | n = data.length, |
| 85602 | x, |
| 85603 | values = new Array(n); |
| 85604 | |
| 85605 | for (i = 0; i < n; ++i) { |
| 85606 | values[i] = value(data[i], i, data); |
| 85607 | } |
| 85608 | |
| 85609 | var xz = domain(values), |
| 85610 | x0 = xz[0], |
| 85611 | x1 = xz[1], |
| 85612 | tz = threshold(values, x0, x1); // Convert number of thresholds into uniform thresholds. |
| 85613 | |
| 85614 | if (!Array.isArray(tz)) { |
| 85615 | tz = (0, _ticks.tickStep)(x0, x1, tz); |
| 85616 | tz = (0, _range.default)(Math.ceil(x0 / tz) * tz, x1, tz); // exclusive |
| 85617 | } // Remove any thresholds outside the domain. |
| 85618 | |
| 85619 | |
| 85620 | var m = tz.length; |
| 85621 | |
| 85622 | while (tz[0] <= x0) tz.shift(), --m; |
| 85623 | |
| 85624 | while (tz[m - 1] > x1) tz.pop(), --m; |
| 85625 | |
| 85626 | var bins = new Array(m + 1), |
| 85627 | bin; // Initialize bins. |
| 85628 | |
| 85629 | for (i = 0; i <= m; ++i) { |
| 85630 | bin = bins[i] = []; |
| 85631 | bin.x0 = i > 0 ? tz[i - 1] : x0; |
| 85632 | bin.x1 = i < m ? tz[i] : x1; |
| 85633 | } // Assign data to bins by value, ignoring any outside the domain. |
| 85634 | |
| 85635 | |
| 85636 | for (i = 0; i < n; ++i) { |
| 85637 | x = values[i]; |
| 85638 | |
| 85639 | if (x0 <= x && x <= x1) { |
| 85640 | bins[(0, _bisect.default)(tz, x, 0, m)].push(data[i]); |
| 85641 | } |
| 85642 | } |
| 85643 | |
| 85644 | return bins; |
| 85645 | } |
| 85646 | |
| 85647 | histogram.value = function (_) { |
| 85648 | return arguments.length ? (value = typeof _ === "function" ? _ : (0, _constant.default)(_), histogram) : value; |