Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

In d3.histogram, the rightmost bin by default thresholds is too wide #65

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/histogram.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
12 changes: 12 additions & 0 deletions test/histogram-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down