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

Handle Vega geometry types in data #1359

Merged
merged 2 commits into from
May 19, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions panel/pane/vega.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,10 @@ def _get_sources(self, json, sources):
if name in sources or isinstance(datasets[name], dict):
continue
data = datasets.pop(name)
if isinstance(data, list) and any(isinstance(d, dict) and 'geometry' in d for d in data):
# Handle geometry records types
datasets[name] = data
continue
columns = set(data[0]) if data else []
if self.is_altair(self.object):
import altair as alt
Expand Down
67 changes: 67 additions & 0 deletions panel/tests/pane/test_vega.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,62 @@
}
}

gdf_example = {
'config': {'view': {'continuousWidth': 400, 'continuousHeight': 300}},
'data': {'name': 'data-778223ce4ff5da49611148b060c0cd3d'},
'mark': {'type': 'geoshape', 'fill': 'lightgray', 'stroke': 'white'},
'height': 600,
'projection': {'reflectY': True, 'type': 'identity'},
'width': 800,
'$schema': 'https://vega.github.io/schema/vega-lite/v4.0.0.json',
'datasets': {
'data-778223ce4ff5da49611148b060c0cd3d': [
{
'bid': 'SR01-01',
'type': 'Feature',
'geometry': {
'type': 'Polygon',
'coordinates': [
[[120.0, 855.0],
[120.0, 925.0],
[20.0, 925.0],
[20.0, 855.0],
[120.0, 855.0]]
]
}
},
{
'bid': 'SR02-02',
'type': 'Feature',
'geometry': {
'type': 'Polygon',
'coordinates': [
[[120.0, 940.0],
[120.0, 1010.0],
[20.0, 1010.0],
[20.0, 940.0],
[120.0, 940.0]]
]
}
},
{
'bid': 'SR03-03',
'type': 'Feature',
'geometry': {
'type': 'Polygon',
'coordinates': [
[[240.0, 940.0],
[240.0, 1010.0],
[140.0, 1010.0],
[140.0, 940.0],
[240.0, 940.0]]
]
}
}
]
}
}

def test_get_vega_pane_type_from_dict():
assert PaneBase.get_pane_type(vega_example) is Vega

Expand Down Expand Up @@ -109,6 +165,17 @@ def test_vega_pane(document, comm):
assert pane._models == {}


def test_vega_geometry_data(document, comm):
pane = Pane(gdf_example)

# Create pane
model = pane.get_root(document, comm=comm)
assert isinstance(model, VegaPlot)

# Ensure geometries are not packed into CDS
assert model.data_sources == {}


def test_vega_pane_inline(document, comm):
pane = Pane(vega_inline_example)

Expand Down