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

d3.histogram shouldn’t coerce ordinal input to numbers. #34

Closed
cpietsch opened this issue Jun 8, 2016 · 4 comments
Closed

d3.histogram shouldn’t coerce ordinal input to numbers. #34

cpietsch opened this issue Jun 8, 2016 · 4 comments
Assignees

Comments

@cpietsch
Copy link

cpietsch commented Jun 8, 2016

Lets say you have a
let x = d3.scaleTime()

and you want to use it on an histogram

d3.histogram()
  .value(d=> d.date)
  .domain(x.domain())
  .thresholds(x.ticks(d3.timeYear, 1))
@mbostock
Copy link
Member

mbostock commented Jun 8, 2016

Yes, that’s valid. Is there a question? Here’s an example:

preview

@mbostock mbostock closed this as completed Jun 8, 2016
@cpietsch
Copy link
Author

cpietsch commented Jun 8, 2016

Oh sorry. I got confused by the negative x0/x1 values. Was expecting a date object or a positive value.

@mbostock
Copy link
Member

mbostock commented Jun 8, 2016

Ah. Well yes, the bin.x0 and bin.x1 are coerced to numbers. And so are the other parts of the histogram (the domain, the values, the thresholds). However, it occurs to me that this is overly strict, and really the histogram only requires comparable (ordinal) values and not numbers, so we could relax that and leave dates as dates.

@mbostock mbostock reopened this Jun 8, 2016
@mbostock mbostock self-assigned this Jun 8, 2016
@mbostock mbostock changed the title Histogram on d3.scaleTime() d3.histogram shouldn’t coerce ordinal input to numbers. Jun 8, 2016
@lgrkvst
Copy link

lgrkvst commented Oct 18, 2016

Observation: if .value() returns Date objects, the first element's x0 and the last element's x1 will stay Date objects. The bin thresholds in-between is coerced into numberobjects.

var A = [1476448344837, 1476448348221, 1476448350581, 1476448352482];
var yay = d3.histogram().value(a => a)(A); // all numbers
var nay = d3.histogram().value(a => new Date(a))(A); // Date objects for `nay[0].x0` and `nay[1].x1`

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

No branches or pull requests

3 participants