Skip to content

Commit

Permalink
Merge pull request #1887 from plotly/histogram-mucho-bins-fix
Browse files Browse the repository at this point in the history
Compute histogram bin positions beyond length 5000
  • Loading branch information
etpinard committed Jul 19, 2017
2 parents 97d08c8 + eef9158 commit 35c84fa
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/traces/histogram/calc.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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;
}

Expand Down
13 changes: 13 additions & 0 deletions test/jasmine/tests/histogram_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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],
Expand Down

0 comments on commit 35c84fa

Please sign in to comment.