-
Notifications
You must be signed in to change notification settings - Fork 620
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 using param / expr with field
keys to control which data column is used for an encoding
#7365
Comments
I don't see why it wouldn't work but it may not be easy to add. The way to find out is to change the types for field and then seeing what breaks. |
Oh cool! Just to clarify, with "change the types for field" does that mean to modify the VegaLite source to accept key-value pairs and not just strings as values for the I am thinking the syntax would look something like this Open the Chart in the Vega Editor: {
"data": {"url": "data/cars.json"},
"params": [
{
"name": "sel",
"select": {"type": "point"},
"bind": {"input": "select", "options": ["Horsepower", "Acceleration"]}
}
],
"mark": "circle",
"encoding": {
"x": {"field": {"param": "sel"}, "type": "quantitative"},
"y": {"field": "Miles_per_Gallon", "type": "quantitative"}
}
} Or maybe |
I was referring to the typescript sources. If you (or someone else) changes the types to support the param ref type (stricter than just a key value pair), you would see the downstream effects. |
I think this will be super useful, but may require that all transforms and scales properties in Vega that take fields must take signals for the field names too, so this may require massive enhancement to Vega? |
Hi @kanitw, I was thinking about this feature and interested in trying to contribute. Do I understand your comment correctly that this can't be produced by changes on the Vega-Lite side, but would need to be done on the Vega side? As an explicit example of what I want: I'd like for example this Repeated Line Chart but where, rather than showing all 3 views side-by-side, instead there is a dropdown menu that allows the user to select from among the 3 options. Thanks for any suggestions! |
I think something like that could be. possible if you create a new dataset in Vega that has a field for y that is derived with an expression like |
Thank you, @domoritz, I will look into this! |
I can confirm this works with the existing Vega-Lite implementation, although I am not sure if it is possible to customise the axis title to be data dependent. It would be useful if axis title could accept an expression in addition to a text literal. {
"data": {
"url": "data/weather.csv"
},
"params": [
{
"name": "measure",
"value": "temp_max",
"bind": {
"input": "select",
"options": ["temp_max","precipitation","wind"]
}
}
],
"transform": [
{
"calculate": "datum[measure]",
"as": "y"
}
],
"mark": "line",
"encoding": {
"x": {"field": "date", "timeUnit": "month"},
"y": {
"field": "y",
"aggregate": "mean"
},
"color": {"field": "location"}
}
} |
Thanks for the workaround, @jwoLondon
It seems that it already does:
|
@jwoLondon @domoritz Wow it is so cool that this works with the calculate transform and @mdejean Thank you for sharing that, it is working for me as well! However, if I fix the schema to version 5.2, I get an error message saying that the axis title only accepts strings (although the chart still shows, this means I can't generate the spec with Altair which checks this before displaying the chart). Was expression referencing in axis titles a recent addition after 5.2? |
@jwoLondon that's a very nice trick! |
Since {
"data": {"url": "data/weather.csv"},
"params": [
{
"name": "measure",
"value": "temp_max",
"bind": {
"input": "select",
"options": ["temp_max", "precipitation", "wind"]
}
}
],
"mark": "line",
"encoding": {
"x": {"field": "date", "timeUnit": "month"},
"y": {
"datum": {
"expr": "datum[measure]"
}
},
"color": {"field": "location"}
}
} This spec is already valid if we replace |
I can't find a way to repro it, but I've got a situation where the data in the data viewer has changed downstream when I use @jwoLondon 's method but a correlation calculation (don't ask) downstream and a kde plot fail to update. The underlying data in the data viewer for these dependent charts has indeed changed but the chart itself doesn't know to refresh. Is there some way (in Vega-Lite or Vega) I can explicitly tell a sub-chart to redraw when it sees a specific parameter get modified? |
Ok, I've got a repro with the following visualisation view here change the x variable to "displacement" and observe that the bottom KDE doesn't update. Change the value again and things get even more broken.
|
@jwoLondon @joelostblom Is it in Vega lite possible to select the visualized value depending on a nested field? datum[measure] from the example does not seem to be able to handle values such as Motor.Cylinder.
|
@domoritz Just following up on our discussion, when I try using the spec below. I run into {
"data": {"url": "data/weather.csv"},
"params": [
{
"name": "measure",
"value": "temp_max",
"bind": {
"input": "select",
"options": ["temp_max", "precipitation", "wind"]
}
}
],
"mark": "line",
"encoding": {
"x": {"field": "date", "timeUnit": "month"},
"y": {
"datum": {
"expr": "datum[measure]"
},
"type": "quantitative"
},
"color": {"field": "location"}
}
} Also @Sebastian2023 , sorry for not replying previously. Unfortunately I don't know how to make this work with a nested field. |
I suspect there might be an open issue for this somewhere but I could not find it when searching. The new parameter feature looks very cool, but I can't find and example of param / expr used together with the
field
key and when I try it in the vega editor, it says it only supports strings as values for this field. Would it be possible to add this functionality so that a field value could be set dynamically, e.g. to change which column is plotted on the x and y axis via a dropdown? Or am I not understanding how parameters are supposed to work?A workaround for this is mention in #7264 by first folding and then filtering on a param / expr, but it would be need if this feature was directly supported. To be clear a use case would be to create something like this (minus the cluster count calculations):
The text was updated successfully, but these errors were encountered: