diff --git a/src/traces/histogram/calc.js b/src/traces/histogram/calc.js index 95f97930e72..f1bca0555e7 100644 --- a/src/traces/histogram/calc.js +++ b/src/traces/histogram/calc.js @@ -106,7 +106,7 @@ module.exports = function calc(gd, trace) { // decrease end a little in case of rounding errors binend = pr2c(binspec.end) + (i - Axes.tickIncrement(i, binspec.size, false, calendar)) / 1e6; - while(i < binend && pos.length < 5000) { + while(i < binend && pos.length < 1e6) { i2 = Axes.tickIncrement(i, binspec.size, false, calendar); pos.push((i + i2) / 2); size.push(sizeinit); @@ -116,6 +116,8 @@ module.exports = function calc(gd, trace) { // nonuniform bins also need nonuniform normalization factors if(densitynorm) inc.push(1 / (i2 - i)); if(doavg) counts.push(0); + // break to avoid infinite loops + if(i2 <= i) break; i = i2; } diff --git a/test/jasmine/tests/histogram_test.js b/test/jasmine/tests/histogram_test.js index a9fed476675..8c257a9b12d 100644 --- a/test/jasmine/tests/histogram_test.js +++ b/test/jasmine/tests/histogram_test.js @@ -246,6 +246,19 @@ describe('Test histogram', function() { ]); }); + it('should handle very small bins', function() { + var out = _calc({ + x: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9], + xbins: { + start: 0, + end: 10, + size: 0.001 + } + }); + + expect(out.length).toEqual(9001); + }); + describe('cumulative distribution functions', function() { var base = { x: [0, 5, 10, 15, 5, 10, 15, 10, 15, 15],