diff --git a/src/histogram.js b/src/histogram.js index 9a31e1dc..8cb7f487 100644 --- a/src/histogram.js +++ b/src/histogram.js @@ -30,7 +30,7 @@ export default function() { // Convert number of thresholds into uniform thresholds. if (!Array.isArray(tz)) { tz = tickStep(x0, x1, tz); - tz = range(Math.ceil(x0 / tz) * tz, Math.floor(x1 / tz) * tz, tz); // exclusive + tz = range(Math.ceil(x0 / tz) * tz, x1, tz); // exclusive } // Remove any thresholds outside the domain. diff --git a/test/histogram-test.js b/test/histogram-test.js index c4af048f..c52db3d1 100644 --- a/test/histogram-test.js +++ b/test/histogram-test.js @@ -122,6 +122,18 @@ tape("histogram.thresholds(function) sets the bin thresholds accessor", function test.end(); }); +tape("histogram()() returns bins whose rightmost bin is not too wide", function(test) { + var h = arrays.histogram(); + test.deepEqual(h([9.8, 10, 11, 12, 13, 13.2]), [ + bin([9.8], 9.8, 10), + bin([10], 10, 11), + bin([11], 11, 12), + bin([12], 12, 13), + bin([13, 13.2], 13, 13.2), + ]); + test.end(); +}); + function bin(bin, x0, x1) { bin.x0 = x0; bin.x1 = x1;