-
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
duplicate parameter definition error in layered charts (because of "point": true
)
#7854
Comments
"point": true
)
This spec is another example: Open the Chart in the Vega Editor: {
"data": {
"values": [
{"a": 1, "b": 1, "c": 1, "d": 1},
{"a": 2, "b": 2, "c": 1, "d": 2},
{"a": 3, "b": 1, "c": 2, "d": 3},
{"a": 4, "b": 2, "c": 2, "d": 4}
]
},
"facet": {"field": "c", "type": "nominal"},
"params": [
{
"name": "selected",
"select": {"type": "point", "fields": ["d"]},
"bind": "legend",
"views": ["view_1"]
}
],
"spec": {
"name": "view_1",
"mark": {"type": "line", "point": true},
"encoding": {
"color": {"field": "d", "type": "nominal"},
"x": {"field": "a", "type": "quantitative"},
"y": {"field": "b", "type": "quantitative"},
"opacity": {"condition": {"value": 1, "param": "selected"}, "value": 0.25}
}
},
"$schema": "https://vega.github.io/schema/vega-lite/v5.2.0.json"
} When changing {
"data": {
"values": [
{"a": 1, "b": 1, "c": 1, "d": 1},
{"a": 2, "b": 2, "c": 1, "d": 2},
{"a": 3, "b": 1, "c": 2, "d": 3},
{"a": 4, "b": 2, "c": 2, "d": 4}
]
},
"facet": {"field": "c", "type": "nominal"},
"spec": {
"layer": [
{
"mark": "line",
"encoding": {
"color": {"field": "d", "type": "nominal"},
"opacity": {
"condition": {"value": 1, "param": "selected"},
"value": 0.25
},
"x": {"field": "a", "type": "quantitative"},
"y": {"field": "b", "type": "quantitative"}
},
"name": "view_1"
},
{
"mark": "circle",
"encoding": {
"color": {"field": "d", "type": "nominal"},
"opacity": {
"condition": {"value": 1, "param": "selected"},
"value": 0.25
},
"x": {"field": "a", "type": "quantitative"},
"y": {"field": "b", "type": "quantitative"}
}
}
]
},
"params": [
{
"name": "selected",
"select": {"type": "point", "fields": ["d"]},
"bind": "legend",
"views": ["view_1"]
}
],
"$schema": "https://vega.github.io/schema/vega-lite/v5.2.0.json"
} Open the Chart in the Vega Editor I assume the |
"point": true
)"point": true
)
Hi @mattijn, I was looking at a variant of your example #7854 (comment) above. Here is the version I was looking at: Open the Chart in the Vega Editor. My version is one step simpler than yours because mine has If you open my version in the Vega editor and click on "Extended Vega-Lite Spec" at the bottom and then "Edit Extended Vega-Lite Spec", you'll see that the parameter has been moved from the top level to inside the I can't quite follow the code, but based on this comment, my guess is that it might be related to the Does that give you any ideas? |
That might be another issue. If I modify your example into a manual layered version of a Can we find the location in the code where the |
Thank you! I haven't completely processed what you wrote @mattijn, but I do think I tracked down where the vega-lite/src/normalize/pathoverlay.ts Lines 162 to 174 in 2ddf383
|
Will changing this sentence (on line 170): ...pointOverlay into ...omit(pointOverlay, ['name']) be sufficient? It seems that |
Nope, that is one level too deep. I think my suggestion will turn this: "name": "foo"
"mark": {"type":"point", "filled": true, "name": "bah"}, into: "name": "foo"
"mark": {"type":"point", "filled": true}, Where we like to " |
Hi @mattijn, do you know what's the best way to test these kind of code changes? Is it opening a linked Vega Editor? Or is there a more natural choice like running the code in VS Code and using debugging? (All the (limited) JavaScript I've played with before has been website-focused, so I always tested it by using a web browser.) |
There is a contributing page in the repo. It mentions VS Code as preferable IDE: https://github.com/vega/vega-lite/blob/next/CONTRIBUTING.md#suggested-programming-environment. But I've no much experience in this either. |
Thanks @mattijn. I'm just experimenting at this stage, but can you take a look at https://github.com/ChristopherDavisUCI/vega-lite/commit/1ced888950ce5580266fc1fc4f35a902238bd449 and see if you think it helps the error from #7854 (comment) ? It does not seem to help your initial |
@ChristopherDavisUCI Nice catch, I missed the implementation of named views, this is great! For reference, produces import altair as alt
from vega_datasets import data
stocks = data.stocks.url
highlight = alt.selection_point(name="highlight", on="mouseover", clear="mouseout")
line = (
alt.Chart(height=100)
.mark_line(point=True)
.encode(x=alt.X("date:N", timeUnit="year"), y=alt.Y("mean(price):Q"))
)
rect = (
alt.Chart()
.mark_rect()
.encode(
x=alt.X("date:T", timeUnit="year"),
fill=alt.Y("mean(price):Q"),
stroke=alt.condition(
highlight, alt.value("black"), alt.value(None), empty=False
),
)
.add_params(highlight)
)
alt.vconcat(line, rect, data=stocks) {
"$schema": "https://vega.github.io/schema/vega-lite/v5.2.0.json",
"data": {
"url": "https://cdn.jsdelivr.net/npm/vega-datasets@v1.29.0/data/stocks.csv"
},
"params": [
{
"name": "highlight",
"select": {"clear": "mouseout", "on": "mouseover", "type": "point"},
"views": ["view_3"]
}
],
"vconcat": [
{
"encoding": {
"x": {"field": "date", "timeUnit": "year", "type": "nominal"},
"y": {"aggregate": "mean", "field": "price", "type": "quantitative"}
},
"height": 100,
"mark": {"point": true, "type": "line"}
},
{
"encoding": {
"fill": {"aggregate": "mean", "field": "price", "type": "quantitative"},
"stroke": {
"condition": {"empty": false, "param": "highlight", "value": "black"},
"value": null
},
"x": {"field": "date", "timeUnit": "year", "type": "temporal"}
},
"mark": "rect",
"name": "view_3"
}
]
} which is valid. Only difference is the naming of |
Thanks for checking this out, @binste! You're right that @mattijn's original chart now works in Altair, but I believe this is an example where an update is still needed:
Like in the other examples, changing to I think my code here fixes this particular issue, but I'm not sure if it's a reasonable approach or if it causes other problems. |
Yes there is still a common pattern affected. The second comment is still problematic. It was raised as well in vega/altair#2713. |
You remove the I think what you do is you import the But how you knew you could define Which |
You're right, I meant that I remove The main point is that the Does that make more sense? |
Yes it does! Thanks for explaining. I notice there is also an |
Fixed by #8662 |
Original observed in this Altair issue comment: vega/altair#2528 (comment).
Open the Chart in the Vega Editor
gives
When setting -upon first sight unrelated-
"point": true
to"point": false
it will work:Defining the
parameter
on the view, it will also work with"point": true
.The text was updated successfully, but these errors were encountered: