Skip to content

Commit 35c84fa

Browse files
authored
Merge pull request #1887 from plotly/histogram-mucho-bins-fix
Compute histogram bin positions beyond length 5000
2 parents 97d08c8 + eef9158 commit 35c84fa

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

src/traces/histogram/calc.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ module.exports = function calc(gd, trace) {
106106
// decrease end a little in case of rounding errors
107107
binend = pr2c(binspec.end) + (i - Axes.tickIncrement(i, binspec.size, false, calendar)) / 1e6;
108108

109-
while(i < binend && pos.length < 5000) {
109+
while(i < binend && pos.length < 1e6) {
110110
i2 = Axes.tickIncrement(i, binspec.size, false, calendar);
111111
pos.push((i + i2) / 2);
112112
size.push(sizeinit);
@@ -116,6 +116,8 @@ module.exports = function calc(gd, trace) {
116116
// nonuniform bins also need nonuniform normalization factors
117117
if(densitynorm) inc.push(1 / (i2 - i));
118118
if(doavg) counts.push(0);
119+
// break to avoid infinite loops
120+
if(i2 <= i) break;
119121
i = i2;
120122
}
121123

test/jasmine/tests/histogram_test.js

+13
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,19 @@ describe('Test histogram', function() {
246246
]);
247247
});
248248

249+
it('should handle very small bins', function() {
250+
var out = _calc({
251+
x: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9],
252+
xbins: {
253+
start: 0,
254+
end: 10,
255+
size: 0.001
256+
}
257+
});
258+
259+
expect(out.length).toEqual(9001);
260+
});
261+
249262
describe('cumulative distribution functions', function() {
250263
var base = {
251264
x: [0, 5, 10, 15, 5, 10, 15, 10, 15, 15],

0 commit comments

Comments
 (0)