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

fix: facet fails on geoshape #9292

Open
wants to merge 8 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Binary file added examples/compiled/geo_facet.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions examples/compiled/geo_facet.svg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
143 changes: 143 additions & 0 deletions examples/compiled/geo_facet.vg.json
@@ -0,0 +1,143 @@
{
"$schema": "https://vega.github.io/schema/vega/v5.json",
"description": "Faceting folded column data (this could also be done using `repeat` without the transform fold.",
"background": "white",
"padding": 5,
"data": [
{
"name": "source_1",
"url": "https://cdn.jsdelivr.net/npm/vega-datasets@v1.29.0/data/population_engineers_hurricanes.csv",
"format": {"type": "csv"}
},
{
"name": "source_0",
"url": "https://cdn.jsdelivr.net/npm/vega-datasets@v1.29.0/data/us-10m.json",
"format": {"feature": "states", "type": "topojson"},
"transform": [
{
"type": "lookup",
"from": "source_1",
"key": "id",
"fields": ["id"],
"values": ["population", "engineers", "hurricanes"]
},
{
"type": "fold",
"fields": ["population", "engineers", "hurricanes"],
"as": ["key", "value"]
},
{
"type": "filter",
"expr": "isValid(datum[\"value\"]) && isFinite(+datum[\"value\"])"
}
]
},
{
"name": "row_domain",
"source": "source_0",
"transform": [{"type": "aggregate", "groupby": ["key"]}]
}
],
"projections": [
{
"name": "projection",
"size": {"signal": "[child_width, child_height]"},
"fit": {"signal": "data('source_0')"},
"type": "albersUsa"
}
],
"signals": [
{"name": "child_width", "value": 200},
{"name": "child_height", "value": 100}
],
"layout": {
"padding": 20,
"offset": {"rowTitle": 10},
"columns": 1,
"bounds": "full",
"align": "all"
},
"marks": [
{
"name": "row-title",
"type": "group",
"role": "row-title",
"title": {
"text": "key",
"orient": "left",
"style": "guide-title",
"offset": 10
}
},
{
"name": "row_header",
"type": "group",
"role": "row-header",
"from": {"data": "row_domain"},
"sort": {"field": "datum[\"key\"]", "order": "ascending"},
"title": {
"text": {
"signal": "isValid(parent[\"key\"]) ? parent[\"key\"] : \"\"+parent[\"key\"]"
},
"orient": "left",
"style": "guide-label",
"frame": "group",
"offset": 10
},
"encode": {"update": {"height": {"signal": "child_height"}}}
},
{
"name": "cell",
"type": "group",
"style": "view",
"from": {
"facet": {"name": "facet", "data": "source_0", "groupby": ["key"]}
},
"sort": {"field": ["datum[\"key\"]"], "order": ["ascending"]},
"encode": {
"update": {
"width": {"signal": "child_width"},
"height": {"signal": "child_height"}
}
},
"marks": [
{
"name": "child_marks",
"type": "shape",
"style": ["geoshape"],
"from": {"data": "facet"},
"encode": {
"update": {
"tooltip": {
"signal": "{\"value\": format(datum[\"value\"], \"\")}"
},
"fill": {"scale": "child_color", "field": "value"},
"ariaRoleDescription": {"value": "geoshape"},
"description": {
"signal": "\"value: \" + (format(datum[\"value\"], \"\"))"
}
}
},
"transform": [{"type": "geoshape", "projection": "projection"}]
}
],
"scales": [
{
"name": "child_color",
"type": "linear",
"domain": {"data": "facet", "field": "value"},
"range": "heatmap",
"interpolate": "hcl",
"zero": false
}
],
"legends": [
{
"fill": "child_color",
"gradientLength": {"signal": "clamp(child_height, 64, 200)"},
"title": "value"
}
]
}
]
}
Binary file modified examples/compiled/geo_layer_line_london.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion examples/compiled/geo_layer_line_london.svg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 1 addition & 3 deletions examples/compiled/geo_layer_line_london.vg.json
Expand Up @@ -45,9 +45,7 @@
{
"name": "projection",
"size": {"signal": "[width, height]"},
"fit": {
"signal": "[data('source_0'), layer_1_geojson_0, data('source_2')]"
}
"fit": {"signal": "[data('source_0'), layer_1_geojson_0]"}
}
],
"marks": [
Expand Down
2 changes: 1 addition & 1 deletion examples/compiled/interactive_geo_earthquakes.vg.json
Expand Up @@ -54,7 +54,7 @@
{
"name": "projection",
"size": {"signal": "[width, height]"},
"fit": {"signal": "[data('source_0'), data('world'), layer_2_geojson_0]"},
"fit": {"signal": "[data('source_0'), layer_2_geojson_0]"},
"type": "orthographic",
"rotate": {"signal": "[rotate0, rotate1, 0]"}
}
Expand Down
29 changes: 29 additions & 0 deletions examples/specs/geo_facet.vl.json
@@ -0,0 +1,29 @@
{
"$schema": "https://vega.github.io/schema/vega-lite/v5.json",
"description": "Faceting folded column data (this could also be done using `repeat` without the transform fold.",
"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"}}
}
7 changes: 6 additions & 1 deletion site/_data/examples.json
Expand Up @@ -761,7 +761,12 @@
{
"name": "geo_repeat",
"png": true,
"title": "Three Choropleths Representing Disjoint Data from the Same Table"
"title": "Three Repeated Choropleths"
},
{
"name": "geo_facet",
"png": true,
"title": "Three Faceted Choropleths"
},
{
"name": "geo_text",
Expand Down
4 changes: 3 additions & 1 deletion src/compile/projection/assemble.ts
Expand Up @@ -44,7 +44,9 @@ export function assembleProjectionForModel(model: Model): VgProjection[] {
};

const fits: string[] = component.data.reduce((sources, data) => {
const source: string = isSignalRef(data) ? data.signal : `data('${model.lookupDataSource(data)}')`;
const source: string = isSignalRef(data)
? data.signal
: `data('${model.lookupDataSource(model.component.data.sources[0].dataName)}')`;
if (!contains(sources, source)) {
// build a unique list of sources
sources.push(source);
Expand Down