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

A predicate to check whether a selection is empty or not #4371

Closed
kanitw opened this issue Dec 15, 2018 · 4 comments
Closed

A predicate to check whether a selection is empty or not #4371

kanitw opened this issue Dec 15, 2018 · 4 comments
Assignees
Labels
Area - Interaction Help Wanted Good tasks for contributors (try https://github.com/vega/vega-lite/issues/1486 first) P2 Important Issues that should be fixed soon RFC / Discussion 💬 For discussing proposed changes
Milestone

Comments

@kanitw
Copy link
Member

kanitw commented Dec 15, 2018

Our selection can include empty: "all" | "none". However, sometimes, we want to apply each of the modes to a different part of the same visualization.

For example, in https://vega.github.io/vega-lite/examples/interactive_bar_select_highlight.html:

  • We want the fillOpacity to activate the selection predicate both when there are selected data for the select selection and when there is none.
  • However, we want the strokeWidth to appear only when there are selected data for the select selection, but not when there is none. Currently, I had to add a hack where I have to combine an expression with the selection predicate:
           test": {
            "and": [
              {"selection": "select"},
              "length(data(\"select_store\"))"
            ]
          }

Note that the expression "length(data(\"select_store\"))" is a hack as I know the underlying data store name in Vega.

It would be more natural to provide a syntax for this as a part of a selection predicate (and a condition definition).

The tricky part is that the new syntax that we can add here may be overriding the "empty" defined.

Some alternatives (given a selection named select):

a) Add {empty: "sel_name"} to the selection logical chain

{
  "condition": {"selection": {"or": ["select", {"empty": "select"}], "value": ...}
}
{
  "condition": {"selection": {"and": ["select", {"not": {"empty": "select"}}], "value": ...}
}

b) Add {empty: "sel_name"} to the predicate chain

{
  "condition": {"test": {"or": [{"selection": "select"}, {"empty": "select"}], "value": ...}
}
{
  "condition": {"test": {"and": [{"selection": "select"}, {"not": {"empty": "select"}}], "value": ...}
}

c) Add boolean empty to both the selection predicate and condition predicate

{
  "condition": {
    // Don't trigger predicate if empty (equivalent to "and not empty") 
    "selection": "select", "empty": false,  
    "value": ...
  } 
}
{
  "condition": {
    //Trigger predicate if empty (equivalent to "or empty")
    "selection": "select", "empty": true,  
    "value": ...
  } 
}

For this c) design we can also add "empty" to the selection predicate too: {"selection": "select", "empty": false}


After writing these alternatives, I think c) is probably the most user-friendly.

@arvind @domoritz

@kanitw kanitw added this to the x.x Interaction Patches milestone Dec 15, 2018
@kanitw kanitw added 🙏 Help wanted Help Wanted Good tasks for contributors (try https://github.com/vega/vega-lite/issues/1486 first) RFC / Discussion 💬 For discussing proposed changes labels Dec 15, 2018
@domoritz
Copy link
Member

C definitely makes sense to me. Why do we even need an empty property on the selection itself? I feel how we handle empty is something that should be in the condition or the filter, not the definition of the selection.

@kanitw
Copy link
Member Author

kanitw commented Dec 15, 2018

I think if we have to pick one having only on the predicate make more sense.

However i can see that if we apply the predicate multiple times like in multi-view plots having it in the selection is good for setting the default empty for a certain selection.

@kanitw
Copy link
Member Author

kanitw commented Dec 15, 2018

Plus, we already have these on selection — better avoid breaking changes.

@kanitw kanitw changed the title A predicate to check whether a function is empty or not A predicate to check whether a selection is empty or not Feb 1, 2019
@kanitw kanitw added the P2 Important Issues that should be fixed soon label Mar 31, 2019
@kanitw kanitw added P3 Should be fixed at some point and removed P2 Important Issues that should be fixed soon labels Jun 9, 2019
@kanitw kanitw modified the milestones: soon?, 5.0? May 15, 2020
@kanitw kanitw modified the milestones: 5.0?, 5.0 - Design TODOs May 29, 2020
@kanitw kanitw added P2 Important Issues that should be fixed soon and removed P3 Should be fixed at some point labels May 29, 2020
@kanitw
Copy link
Member Author

kanitw commented May 29, 2020

Reading this again, I still like option c).

Plus, we already have these on selection — better avoid breaking changes.

Given we may introduce this in VL 5.0, which will already introduce a number of changes. It might make sense to just move this "empty" bit to predicate.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area - Interaction Help Wanted Good tasks for contributors (try https://github.com/vega/vega-lite/issues/1486 first) P2 Important Issues that should be fixed soon RFC / Discussion 💬 For discussing proposed changes
Projects
None yet
Development

No branches or pull requests

3 participants