Map view fails if GeoJSON transform is passed a `null` feature value.
See original GitHub issueWhen linking a data source to a geo data source with lookup, we have two choices. Either make the geo data the primary data source and lookup the secondary attribute data; or make the attribute data primary and lookup the geo data.
When the geo data are primary and not all secondary data match, only those matched are encoded, which is expected and desired behaviour:
{
"$schema": "https://vega.github.io/schema/vega-lite/v3.json",
"data": {
"url": "https://vega.github.io/vega-lite/data/us-10m.json",
"format": {"type": "topojson", "feature": "states"}
},
"projection": {"type": "albersUsa"},
"transform": [
{
"lookup": "id",
"from": {
"data": {
"values": [
{"attId": 53, "att": "Washington"},
{"attId": 12, "att": "Florida"}
]
},
"key": "attId",
"fields": ["att"]
}
}
],
"encoding": {"color": {"field": "att", "type": "nominal"}},
"mark": "geoshape"
}
If the attribute data are made primary, only the matched attributes are shown, which again is desired and expected behaviour:
{
"$schema": "https://vega.github.io/schema/vega-lite/v3.json",
"data": {
"values": [
{"attId": 12, "att": "Florida"},
{"attId": 53, "att": "Washington"}
]
},
"projection": {"type": "albersUsa"},
"transform": [
{
"lookup": "attId",
"from": {
"data": {
"url": "https://vega.github.io/vega-lite/data/us-10m.json",
"format": {"type": "topojson", "feature": "states"}
},
"key": "id"
},
"as": "geo"
}
],
"encoding": {
"color": {"field": "att", "type": "nominal"},
"shape": {"field": "geo", "type": "geojson"}
},
"mark": "geoshape"
}
However, in this attribute-as-primary spec, if one of the attributes is not found, then none of the map features is shown (line 7):
{
"$schema": "https://vega.github.io/schema/vega-lite/v3.json",
"data": {
"values": [
{"attId": 12, "att": "Florida"},
{"attId": 53, "att": "Washington"},
{"attId": 999, "att": "Dummy attribute"}
]
},
"projection": {"type": "albersUsa"},
"transform": [
{
"lookup": "attId",
"from": {
"data": {
"url": "https://vega.github.io/vega-lite/data/us-10m.json",
"format": {"type": "topojson", "feature": "states"}
},
"key": "id"
},
"as": "geo"
}
],
"encoding": {
"color": {"field": "att", "type": "nominal"},
"shape": {"field": "geo", "type": "geojson"}
},
"mark": "geoshape"
}
This seems like a bug to me. I would expect it to show at least the matched geoshapes rather than nothing at all. It is problematic because it is not always obvious what the complete set of feature ids/properties are in a topojson file, so it can be quite easy to include a non-matching attribute.
Issue Analytics
- State:
- Created 4 years ago
- Comments:7 (7 by maintainers)
Top GitHub Comments
Thanks @jwoLondon! @domoritz: this is not about full joins, a lookup is perfectly sufficient here.
The problem is that D3’s auto-fit logic for projections is breaking because we’re passing a `null` GeoJSON feature into it. So I consider this a Vega bug (fortunately an easy one to fix: just add a filter to our GeoJSON marshaling) and I will transfer the issue over to vega/vega.
In the meantime, if you add explicit
scale
and/ortranslate
parameters to the projection definition the auto-fit logic will be disabled and you can see the map (though without automatic fitting, of course).Ah v5 fixed it (by this issue: https://github.com/vega/vega-lite/issues/6163). Congrats!