Skip to content
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

avoid a crash on facet: exclude on a non-faceted mark #1282

Merged
merged 2 commits into from
Feb 21, 2023

Conversation

Fil
Copy link
Contributor

@Fil Fil commented Feb 17, 2023

closes #1281

@Fil Fil requested a review from mbostock February 17, 2023 09:55
src/plot.js Outdated
@@ -100,6 +100,7 @@ export function plot(options = {}) {
for (const mark of marks) {
if (mark.facet === "exclude") {
const facetState = facetStateByMark.get(mark);
if (facetState === undefined) throw new Error(`the facet: "exclude" option is restricted to top-level facets`);
Copy link
Member

Choose a reason for hiding this comment

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

This isn’t accurate—you can also use facet: "exclude" if you specify mark-level faceting, e.g.

Plot.dot(penguins, {facet: "exclude", fx: "sex", fy: "species", x: "culmen_depth_mm", y: "culmen_length_mm", r: 2, fill: "#ddd"}),

@Fil
Copy link
Contributor Author

Fil commented Feb 21, 2023

We should be consistent when the facet option is activated (ie not undefined) on a non-faceted mark: either ignore all cases, or error all cases.

Currently we ignore all cases but crash on "exclude". This can be fixed by changing that line to:

    if (facetState !== undefined) facetState.facetsIndex = facetExclude(facetState.facetsIndex);

I'm not sure erroring on all cases would bring much, but it's an alternative.

@Fil Fil changed the title better error avoid a crash on facet: exclude on a non-faceted mark Feb 21, 2023
src/plot.js Outdated Show resolved Hide resolved
@Fil Fil merged commit 228f62e into main Feb 21, 2023
@Fil Fil deleted the fil/better-error-facet-exclude-1281 branch February 21, 2023 16:41
chaichontat pushed a commit to chaichontat/plot that referenced this pull request Jan 14, 2024
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.

Throw a better error when facet: "exclude" is used without faceting?
2 participants