-
Notifications
You must be signed in to change notification settings - Fork 621
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
facet fails on geoshape #3729
Comments
I just ran into this and it seems like it is an issue also in the latest version of Vega-Lite (5.2). Here is a spec that reproduces it with a sample dataset; the colorscale seems correct, just that the maps are not showing: {
"data": {
"url": "https://cdn.jsdelivr.net/npm/vega-datasets@v1.29.0/data/us-10m.json",
"format": {"feature": "states", "type": "topojson"}
},
"facet": {"row": {"field": "key", "type": "nominal"}},
"spec": {
"mark": {"type": "geoshape", "tooltip": true},
"encoding": {"color": {"field": "value", "type": "quantitative"}},
"height": 100,
"projection": {"type": "albersUsa"},
"transform": [
{
"lookup": "id",
"from": {
"data": {
"url": "https://cdn.jsdelivr.net/npm/vega-datasets@v1.29.0/data/population_engineers_hurricanes.csv"
},
"key": "id",
"fields": ["population", "engineers", "hurricanes"]
}
},
{"fold": ["population", "engineers", "hurricanes"]}
]
},
"resolve": {"scale": {"color": "independent"}}
} |
In the compiled Vega, one have to change the line "fit": {"signal": "data('child_main')"}, into "fit": {"signal": "data('source_0')"}, to make it work. It looks good then! I tried to find in the VL-codebase to see where |
Any chance this will ever get fixed? This is currently a pretty big blocker in a project I'm developing where just concatenating charts is not a viable workaround. |
If you could help triage to see where the issue lies, I'm happy to help with the pull request. I have a lot on my plate so making time to triage this specific issue may take some time. |
What do you mean by triage in this case. Im happy to help but am quite unfamiliar with the vega codebase and internal functioning, so im not sure how much of a help i can be. |
Vega-Lite is basically a transpiler. The first step would be to find out what Vega spec vo generates that's wrong. The we need to find out what code causes it. This could be something where if you step through the translation of an example, you could see where the code generates the wrong output. |
I just tried and can recreate the issue with @joelostblom's spec and resolve it with @mattijn's fix. Does that help @domoritz? {
"data": {
"url": "https://cdn.jsdelivr.net/npm/vega-datasets@v1.29.0/data/us-10m.json",
"format": {"feature": "states", "type": "topojson"}
},
"facet": {"row": {"field": "key", "type": "nominal"}},
"spec": {
"mark": {"type": "geoshape", "tooltip": true},
"encoding": {"color": {"field": "value", "type": "quantitative"}},
"height": 100,
"projection": {"type": "albersUsa"},
"transform": [
{
"lookup": "id",
"from": {
"data": {
"url": "https://cdn.jsdelivr.net/npm/vega-datasets@v1.29.0/data/population_engineers_hurricanes.csv"
},
"key": "id",
"fields": ["population", "engineers", "hurricanes"]
}
},
{"fold": ["population", "engineers", "hurricanes"]}
]
},
"resolve": {"scale": {"color": "independent"}}
} In the compiled Vega, change the line "fit": {"signal": "data('child_main')"}, into "fit": {"signal": "data('source_0')"}, and it then works. |
Update: =========================================== I compare this generated vega script with this example, and found that the issue maybe missing a line in transform |
Thanks for exploring this @ChiaLingWeng ! If I understand correctly it seems like your first working spec is similar to this example from the Altair gallery. The key in these workarounds seem to be to use a lookup transform for the geo data instead of specifying it as the default data object of the chart, does that sound correct? It would be great to get it working without a lookup transform, and it seems like replacing |
Hi @joelostblom, yes, my workaround is to create another lookup transform. vega-lite/src/compile/projection/parse.ts Line 69 in 5b7f963
vega-lite/src/compile/model.ts Lines 469 to 475 in 5b7f963
From my understanding, I think it's quite reasonable to have childModel name "child" in facet chart (correct me if I'm wrong). So I search facet geo graph example and come up with adding {"type": "geojson", "signal": "child_main"} might be correct
|
@ChiaLingWeng Ah I see, thanks for elaborating. I think what you are suggesting makes sense and it's exciting to see a potential solution that would bring faceted maps to VL! I will say that I'm not the most familiar with the code base; would you be able to create a PR that implements your solution so that we can have a review from someone on the team with more experience? |
Hi @joelostblom, I switch the 2 data source position and find this can work. I'm a little confused now, but I'll see if I can help on this. {
"data": {
"url": "https://cdn.jsdelivr.net/npm/vega-datasets@v1.29.0/data/population_engineers_hurricanes.csv"
},
"facet": {"row": {"field": "key", "type": "nominal"}},
"spec": {
"height": 100,
"transform": [
{"fold": ["population", "engineers", "hurricanes"]},
{
"lookup": "id",
"from": {
"data": {
"url": "data/us-10m.json",
"format": {"type": "topojson", "feature": "states"}
},
"key": "id"
},
"as": "geo"
}
],
"projection": {"type": "albersUsa"},
"mark": "geoshape",
"encoding": {
"shape": {"field": "geo", "type": "geojson"},
"color": {"field": "value", "type": "quantitative"}
}
},
"resolve": {"scale": {"color": "independent"}}
} |
Thanks for taking the time to look into this further @ChiaLingWeng. I was trying to understand it better myself by using a simpler example that does not involve a transform and where the only data source is the geo data:
If I add facetting based on the ID to this chart, we can see that all the charts are empty, but the color scale is actually correct. So the data is passed correctly to the scale, but not to the map projection:
If you open the Vega spec for the faceted VL chart, you can see that the data is referenced in three places:
Based on that, it seems like the simplest solution might be to figure out how to replace the first occurrence with |
facet fails on geojson with Error: Undefined data set name: "child_main"
example
generated vega (editor)
it works without projection
The text was updated successfully, but these errors were encountered: