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
Improvements to calcExtents #44
Comments
This function currently looks at the first row for any undefined, NaN or null values. It might also be better to simply skip these values instead of breaking on them, similar to some d3 functions. I want to look at the a few examples and how both d3 and tidy.js handle them. |
Any thoughts welcome @jtrim-ons @jurb |
The object-based API you're suggesting looks like an improvement to me. I've had a go at implementing it: https://github.com/jtrim-ons/layercake/blob/new-api-for-calcExtents/src/lib/calcExtents.js . I've written it so that the current array-based API still works. I've changed the behaviour of the function in a few subtle ways, partly just to simplify the code. Some of these might not be good!
I also fixed a bug which I think is definitely worth fixing even if you don't use any of my code in the end! If the accessor function returns an array that is part of the datum, the current version of args: [[
{ x: [-4, 0], y: [1, 6] }, { x: [-5, 1], y: [2, 7]}, { x: [-3, 2], y: [3, 8] }, { x: [-2, 3], y: [4, 9] }, { x: [-1, 4], y: [5, 10] }
], [{ field: 'x', accessor: d => d.x }, { field: 'y', accessor: d => d.y }]],
expected: { x: [-5, 4], y: [1, 10] }
} I've added another test function to check for this. |
Thanks for putting the thought into this and putting this together so quickly. I think that's a good approach! Is there a good argument for keeping the current array-based API? If the return value changes from In the library, I would probably change layercake/src/LayerCake.svelte Line 171 in bc13c6c
Some backstory, I used for-loops in the original function since they're a bit faster than |
Some responses in no particular order...
|
I think that sounds good! And on the breaking change, I remembered that anything that changes how it deals with |
Thanks for all the work on this @jtrim-ons! This is now available in 5.0.0! |
I finished updating the examples, the site and the REPL examples. Let me know if I missed anything or if some changes don't stick – sometimes the REPL doesn't always save right. |
Currently, the second argument to
calcExtents
is an array of objects defining a field and accessor. It might make more sense for this to be an object likeBecause the output of this function is a similarly structured object, it makes a bit more sense that the input matches the output. Also I think it would make it examples like the SmallMultiple wrapper be a bit easier where you wouldn't have to loop through the input array:
Would become:
There was maybe a reason why I made the input an array, though, so I'll look into this. It would also be a breaking change.
The text was updated successfully, but these errors were encountered: