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

Support multiple conditions in an encoding (if/else/else...) #3040

Closed
pelotom opened this issue Sep 26, 2017 · 3 comments
Closed

Support multiple conditions in an encoding (if/else/else...) #3040

pelotom opened this issue Sep 26, 2017 · 3 comments

Comments

@pelotom
Copy link
Contributor

pelotom commented Sep 26, 2017

Correct me if I'm wrong, but it seems like currently an encoding can only take one of at most two branches, based on a single condition:

{
  "color": {
    "condition": { "selection": "focused", "value": "red" },
    "value": "blue"
  }
}

but it would be nice if one could check multiple conditions until one succeeds, e.g. something like

{
  "color": [
    { "condition": { "selection": "focused", "value": "red" } },
    { "condition": { "selection": "pinned", "value": "green" } },
    { "value": "blue" }
  ]
}
@kanitw kanitw added this to the 2.x.x Features & Patches milestone Sep 26, 2017
@kanitw
Copy link
Member

kanitw commented Sep 26, 2017

You're right, currently we intentionally support only two branches, so that we can limit that one encoding channel can have only one field.

That said, it is possible to extend the design to have multiple branches with different values -- as long as there is only one field for each encoding channel (relaxing the latter constraint introduce way more complexity to the system and is definitely not worth supporting).

I could see it work with the following syntax:

{
  "color": {
    "condition": [
       { "selection": "sel1", "value": "red" },
       { "selection": "sel2", "value": "green" },
    ],
    "value": "blue"
  }
}

where the condition array can only be a ConditionValueDef.

However, we haven't prioritized it since we have not found an example visualization that would really need this. If you have a convincing use case, please feel free to submit one.

For example, If you have a clear use case to have "pinned" data and "focused" data, please feel free to describe.

@pelotom
Copy link
Contributor Author

pelotom commented Sep 26, 2017

That syntax looks good to me.

Ok, let me describe my use case. I want the user to be able to hover the mouse over various elements in the chart, whereupon they will acquire a "focused" effect... maybe in a scatterplot they become slightly larger than the other points, for example. Then if the user clicks on an element it becomes "pinned", at which point it becomes even more emphasized... maybe in addition to being larger than the other points it acquires a red color, for example. Now as the user hovers over other items they acquire the focus effect, but not the pinned effect, so that it's clear that the old element is still pinned, whereas the things they are hovering over are only transiently focused and potentially pinnable. This chart might be accompanied by an external details view which listens only for "pin" events and shows details about the pinned element, so it needs to be clear which element that view is referring to.

@kanitw kanitw modified the milestones: 2.x.x Features & Patches, 2.x Visual Encoding Patches Sep 28, 2017
@kanitw
Copy link
Member

kanitw commented Oct 19, 2017

Will be fixed in #3146 (pending review)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants