Skip to content

mark-level facets #1085

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 37 commits into from
Dec 9, 2022
Merged

mark-level facets #1085

merged 37 commits into from
Dec 9, 2022

Conversation

Fil
Copy link
Contributor

@Fil Fil commented Oct 11, 2022

Closes #1081

The internal changes are pretty substantial, but hopefully easy to read.

Note that one unit test changes because the order of the index returned by the "exclude" option is not guaranteed (it was arbitrary anyways).

@Fil Fil requested a review from mbostock October 11, 2022 23:37
@Fil Fil mentioned this pull request Oct 12, 2022
5 tasks
@Fil Fil force-pushed the fil/mark-facets branch from 0040be8 to 2232893 Compare October 12, 2022 19:56
@Fil Fil requested a review from mbostock October 13, 2022 23:20
@Fil Fil mentioned this pull request Oct 16, 2022
@mbostock
Copy link
Member

mbostock commented Dec 2, 2022

I’m trying to work through two issues here:

  • The fx and fy channels and scales should only be instantiated once. We currently instantiate them twice: first when reading the mark facet state, then again along with the non-facet channels and scales. (I’ve tried, but it seems to have broken sorting of facet scale domains, and I’m not sure how to fix it yet.)
  • The fx and fy channels should respect the corresponding scale’s transform option, if any (via applyScaleTransforms). We do this for normal channels but not for the facet channels since we’ve introduced a new path.

Copy link
Member

@mbostock mbostock left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this PR is largely ready to go. Exceptions:

  1. It’d be better to only initialize the fx and fy scales once. We currently need to initialize them once to compute their domains, and then again with the other scales in case a mark channel wants to sort the domain of fx or fy. I’m not sure it’s worth the trouble to only initialize them once, though, so this isn’t urgent.

  2. I don’t think we’re respecting the scale.transform option correctly for the first initialization of fx and fy scales (see the TODO in code). We should test that because I suspect it is broken.

  3. We should also test a facet scale with a date domain. I think that was broken before I switched to InternMap.

@Fil
Copy link
Contributor Author

Fil commented Dec 2, 2022

"fy scale transform" is indeed broken. Example in https://observablehq.com/@observablehq/testing-facets-for-plot-1085

I wasn't able to reproduce the "date domain for fy" issue though.

@mbostock
Copy link
Member

mbostock commented Dec 2, 2022

I expected Date domains to work since we now use InternMap, but I think the order of the domain would have been wrong before in some cases. Thanks for testing.

@Fil
Copy link
Contributor Author

Fil commented Dec 2, 2022

I think we should merge this and open a new issue for the "fy scale transform" bug (which is independent)?

Copy link
Contributor Author

@Fil Fil left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can't approve my own PR, but lgtm. 👍

Copy link
Member

@mbostock mbostock left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I feel the lack of support for fx/fy scale transforms is a blocker. (I’m assuming that this is a regression from previous behavior, but I also think that this should work as advertised even if it’s admittedly rarely needed.)

@Fil
Copy link
Contributor Author

Fil commented Dec 8, 2022

I don't think it's a regression, just an old bug. Tests in https://observablehq.com/@observablehq/testing-facets-for-plot-1085 indicate that it is not working in any branch, nor in 0.6.0. Am I missing something?

Copy link
Member

@mbostock mbostock left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎉

@mbostock mbostock merged commit 7055da1 into main Dec 9, 2022
@mbostock mbostock deleted the fil/mark-facets branch December 9, 2022 18:34
@Fil Fil mentioned this pull request Dec 22, 2022
chaichontat pushed a commit to chaichontat/plot that referenced this pull request Jan 14, 2024
* define facets from each mark

* allow facet: "exclude" in mark faceting

this changes one unit test as it does not maintain the data order in the exclude facet. but that order was kinda arbitrary anyway. Use an explicit sort transform if necessary.

* a bit more documentation

* unnecessarily polish multiplication table test

* stricter/looser facet validation

* add TODO

* remove and simplify the weird parts (j, empty facet determination)
add a test plot with mark-level facets and exclude
clarify comments
simplify
proper facet look-up for grid lines

* clean up filterFacets

* fix comments

* regroup all facet handling, simplify

* inline maybeFacet; improve backwards compatibility

* minimize diff

* comments

* clean

* fix tests

* minimize diff

* keep top-level facet state separate

* avoid re-initializing fx and fy channels

* TODO re. applyScaleTransforms

* prettier

* adopt InternMap; remove sorting

* nullish, not undefined

* style

* remove TODO

* fx and fy aren’t in mark.channels

* remove todo

* fix comment

* use groups

* tighten state

* sparse facetsIndex

* simpler facetsIndex initialization

* small consolidation

* compute exclude facet index earlier

* simpler facet channels collection

Co-authored-by: Mike Bostock <[email protected]>
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.

New syntax for declaring facets from a mark
2 participants