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

fix crash on missing top bin #248

Merged
merged 5 commits into from Apr 7, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/bin.js
Expand Up @@ -84,8 +84,10 @@ export default function bin() {
if (isFinite(step)) {
if (step > 0) {
for (i = 0; i < n; ++i) {
if ((x = values[i]) != null && x0 <= x && x <= x1) {
if ((x = values[i]) != null && x0 <= x && x < x1) {
bins[Math.floor((x - x0) / step)].push(data[i]);
Fil marked this conversation as resolved.
Show resolved Hide resolved
} else if (x === x1) {
bins[bins.length - 1].push(data[i]);
}
}
} else if (step < 0) {
Expand Down
4 changes: 4 additions & 0 deletions test/bin-test.js
Expand Up @@ -235,6 +235,10 @@ it("bin(data) assigns floating point values to the correct bins", () => {
}
});

it("bin(data) assigns integer values to the correct bins", () => {
assert.deepStrictEqual(bin().domain([4, 5])([5]), [box([5], 4, 5)]);
});

function box(bin, x0, x1) {
bin.x0 = x0;
bin.x1 = x1;
Expand Down