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

dl.histogram returning repeated bins #107

Open
mathisonian opened this issue Jun 25, 2020 · 2 comments
Open

dl.histogram returning repeated bins #107

mathisonian opened this issue Jun 25, 2020 · 2 comments
Labels

Comments

@mathisonian
Copy link
Member

Hey all,

This library has been extremely useful, but I'm hitting an issue with the histogram method. A simple reproduction is available here: https://observablehq.com/d/cfefd9c0c388f478

The issue is that the values that are returned seem to repeat when a high number of bins is used. For example, I'd expect to get bins with values of ..., .27, .28, .29, ... but instead get two bins at .28 and no bin at .29.

Screen Shot 2020-06-25 at 4 15 54 PM

Its possible that I'm doing something wrong with the options (or just generally unreasonable) in which case please let me know.

@jheer
Copy link
Member

jheer commented Jun 26, 2020

Hmm, that looks like a rounding bug introduced by the value call on this line:
https://github.com/vega/datalib/blob/master/src/bins/histogram.js#L60

The corresponding function (bins.js#L72) is:

function value(v) {
  return this.step * Math.floor(v / this.step + EPSILON);
}

Meanwhile, the equivalent call in Vega's Bin transform is a bit different. IIRC, I rewrote it to handle these floating point issues:

this.start + this.step * Math.floor(EPSILON + (v - this.start) / this.step)

I'm not sure when I will have the time to patch and test, but in the meantime would welcome a PR if you try the change yourself.

@jheer jheer added the bug label Jun 26, 2020
@mathisonian
Copy link
Member Author

Thanks @jheer! I figured it was some rounding issue. These pointers are helpful, I can take a stab at a patch & test in the next couple of days.

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

No branches or pull requests

2 participants