Skip to content

improve bin type coercion #790

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

Merged
merged 1 commit into from
Feb 28, 2022
Merged

improve bin type coercion #790

merged 1 commit into from
Feb 28, 2022

Conversation

mbostock
Copy link
Member

If the input channel is strings (or some other non-numeric type), we now coerce to a number. Example:

https://observablehq.com/d/71b0a051aff775f2

If the input channel is a typed array, we now also convert to a plain Array. This avoids an additional copy in d3.bin (since Array.isArray is false for typed arrays):

https://github.com/d3/d3-array/blob/2f28f41005de2fbb69e99439fabec5eb8bce26f0/src/bin.js#L16

And it also ensures that when we call coerceDate, that we produce an Array of Date instances (not possibly e.g. Float64Array of numbers).

V = V.map(coerceDate);

Fixes #789.

@mbostock mbostock requested a review from Fil February 26, 2022 22:04
@mbostock mbostock force-pushed the mbostock/bin-coercion branch from 432283d to c6dbd5e Compare February 26, 2022 22:15
@mbostock mbostock merged commit 4d36de0 into main Feb 28, 2022
@mbostock mbostock deleted the mbostock/bin-coercion branch February 28, 2022 14:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

The bin transform should coerce inputs to numbers
2 participants