-
Notifications
You must be signed in to change notification settings - Fork 184
explicit facet option in a mark #450
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
Conversation
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.
This is great. I was thinking we should do something like this. My feedback is mostly on how to make the facet option more consistent with other Plot options.
src/mark.js
Outdated
const names = new Set(); | ||
this.data = data; | ||
this.facet = facet; |
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.
We should do some validation and coercion here.
I also think we can unify the types a little more. Currently:
"exclude"
is a string,null
andundefined
are equivalent, andtrue
andfalse
are booleans.
If we want to be more analogous to the scale.axis option, perhaps:
"exclude"
"include"
, andtrue
is shorthand for"include"
undefined
is"include"
if data is strict equal, and otherwisenull
to disable facetingnull
or any other falsey value is mapped tonull
to disable faceting
Any other truthy value, after being coerced to a string, would throw an error. We’d use the keyword
helper:
Line 126 in 068f8d8
export function keyword(input, name, allowed) { |
Co-authored-by: Mike Bostock <[email protected]>
- "include" (shorthand: true) - "exclude" - null (or falsy) undefined is the default test on data === facet.data.
src/facet.js
Outdated
const markFacets = mark.facet == null ? mark.data === this.data ? facetsIndex : undefined | ||
: mark.facet === "exclude" ? facetsIndex.map(facet => Uint32Array.from(difference(index, facet))) | ||
: mark.facet === true ? facetsIndex | ||
const facet = mark.facet && keyword(mark.facet, "facet", ["include", "exclude"]); |
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.
This (validation and type coercion of the facet option via keyword
) needs to happen in the mark constructor (as I said previously), not here in initialize.
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.
yes I understood your comment just after pushing the previous commit 8-)
I think it's worth adding an "auto" option value (rather than undefined), which makes the code easier to read, and would maybe clarify the documentation
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.
Yea, I wasn’t sure whether we needed "auto"
in addition to undefined
, but sure, if you want.
src/facet.js
Outdated
const facet = mark.facet && keyword(mark.facet, "facet", ["include", "exclude"]); | ||
const markFacets = facet === undefined ? mark.data === this.data ? facetsIndex : undefined | ||
: facet === "include" ? facetsIndex | ||
: facet === "exclude" ? facetsIndex.map(f => Uint32Array.from(difference(index, f))) |
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 we probably shouldn’t bother with this optimization, but: this could be extracted out of the for loop using a lazily-constructed variable so that it can be shared across multiple excluded marks.
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.
it's cheap so I added it too
adds an "auto" symbol as default value computes the facet exclusion index only once.
Co-authored-by: Mike Bostock <[email protected]>
…to fil/explicit-facets
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.
Nice work!
Wow! |
you can enable or disable faceting explicitly on a mark with the facet option, which accepts the following values:
See https://observablehq.com/@fil/plot-explicit-facet-option