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

Conversation

hirakuro
Copy link
Contributor

Nice to meet you.

d3.histogram()(data) returns bins their width are automatically determined by default thresholds.

I understand that widths of middle bins are fixed and widths of edge bins (leftmost and rightmost) are less or equal to the fixed width. But sometimes the rightmost bin may have wider width.

For example, the result of code below has wider rightmost bin:

> d3.histogram()([9.8, 10, 11, 12, 13, 13.2])
[ [ 9.8, x0: 9.8, x1: 10 ], // width: 0.2
  [ 10, x0: 10, x1: 11 ], // width: 1
  [ 11, x0: 11, x1: 12 ], // width: 1
  [ 12, 13, 13.2, x0: 12, x1: 13.2 ] ] // width: 1.2 (!?)

I expect that the last part of bins should be:

  [ 11, x0: 11, x1: 12 ], // width: 1
  [ 12, x0: 12, x1: 13 ], // width: 1
  [ 13, 13.2, x0: 13, x1: 13.2 ] ] // width: 0.2

In src/hitogram.js#L33, the default thresholds are generated by:

 tz = range(Math.ceil(x0 / tz) * tz, Math.floor(x1 / tz) * tz, tz); // exclusive

I think that this Math.floor is not needed because result of range(a, b, c) already does not include b (isn't it?).

@mbostock
Copy link
Member

Merged as 18113f1. Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants