-
Notifications
You must be signed in to change notification settings - Fork 187
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
autoSpec #1284
autoSpec #1284
Conversation
I'd suggest we make the tests much more stringent, by comparing their serialized version to a template (which can be in a separate file on disk, or in the unit test page). For example instead of testing
we do:
of course this could be a nice function if we want to keep it readable. |
Why not use assert.deepStrictEqual? |
src/marks/auto.js
Outdated
@@ -91,7 +86,7 @@ export function auto(data, {x, y, color, size, fx, fy, mark} = {}) { | |||
// Determine the default mark type. | |||
if (mark === undefined) { | |||
mark = | |||
sizeValue != null || sizeReduce != null | |||
size != null || sizeReduce != null |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is this change doing?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
At one point in refactoring, I didn't have a reference to sizeValue here, and it seemed inconsistent to refer to x and y (not xValue and yValue) below, but sizeValue (not size) here, so I changed it. Upon further reflection, if sizeValue is undefined / null, then size will be undefined / null, so it doesn't matter. I'll revert this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it’ll be clearer if we store the materialized columns as a separate array, rather than redefining local variables/function arguments. I’ll incorporate into this into a commit I’m about to push.
src/marks/auto.js
Outdated
fx, | ||
fy, | ||
mark | ||
} = spec(data, initialOptions, {materialize: true}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A different way we can do this (without requiring an internal option and separate function) is to materialize the values as arrays, and then pass them into autoSpec; this way valueof does nothing (it returns the existing arrays). I’ll take a crack at this and push a commit if it works.
src/marks/auto.js
Outdated
return { | ||
x: { | ||
...(materialize ? {value: x} : xValue !== undefined && {value: xValue}), | ||
...(xReduce !== undefined && {reduce: xReduce}), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it might be clearer to return null here to fully realize the defaults. I’ll try that and see.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TIL "??=". Thanks for simplifying back to one function and for tackling the "return something that's defined one way or the other" thing!
* first draft of autospec * more stringent tests * exported autoSpec doesn't return materialized columns; internal spec function does * fix tests * revert useless change * normalize & materialize prior to autoSpec * materializeValues * preTTieR * lazy materialization for autoSpec * move comment * zero comments * nullish comments --------- Co-authored-by: Mike Bostock <mbostock@gmail.com>
Factors out the parts of the auto mark that fill in its options. Produces an object that you can pass as a fully-specified Plot.auto options object.
As an optimization, there are two versions:
So, calling Plot.auto will still only materialize columns once; calling Plot.auto(data, Plot.autoSpec(data, options)) will materialize them twice.
Optional to-dos, I'm not sure they're necessary for now: