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

ENH: add datatype geojson #1714

Merged
merged 7 commits into from
Oct 1, 2019
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
30 changes: 30 additions & 0 deletions altair/examples/us_incomebrackets_by_state_facet.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
"""
US Income by State: Wrapped Facet
---------------------------------
This example shows how to create a map of income in the US by state,
faceted over income brackets
"""
# category: maps

import altair as alt
from vega_datasets import data

states = alt.topo_feature(data.us_10m.url, 'states')
source = data.income.url

alt.Chart(source).mark_geoshape().encode(
shape='geo:G',
color='pct:Q',
tooltip=['name:N', 'pct:Q'],
facet='group:N'
).transform_lookup(
lookup='id',
from_=alt.LookupData(data=states, key='id'),
as_='geo'
).properties(
width=300,
height=175,
columns=2
).project(
type='albersUsa'
)
3 changes: 2 additions & 1 deletion altair/utils/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@ def infer_dtype(value):
TYPECODE_MAP = {'ordinal': 'O',
'nominal': 'N',
'quantitative': 'Q',
'temporal': 'T'}
'temporal': 'T',
'geojson': 'G'}

INV_TYPECODE_MAP = {v: k for k, v in TYPECODE_MAP.items()}

Expand Down
2 changes: 2 additions & 0 deletions altair/utils/tests/test_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,11 +82,13 @@ def check(s, **kwargs):
check('foobar:nominal', type='nominal', field='foobar')
check('foobar:ordinal', type='ordinal', field='foobar')
check('foobar:temporal', type='temporal', field='foobar')
check('foobar:geojson', type='geojson', field='foobar')

check('foobar:Q', type='quantitative', field='foobar')
check('foobar:N', type='nominal', field='foobar')
check('foobar:O', type='ordinal', field='foobar')
check('foobar:T', type='temporal', field='foobar')
check('foobar:G', type='geojson', field='foobar')

# Fields with aggregate and/or type
check('average(foobar)', field='foobar', aggregate='average')
Expand Down
1 change: 0 additions & 1 deletion altair/vegalite/v3/tests/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -476,7 +476,6 @@ def test_filter_transform_selection_predicates():
assert chart.to_dict()['transform'] == [{'filter': {'selection': {'or': ['s1', 's2']}}}]



def test_resolve_methods():
chart = alt.LayerChart().resolve_axis(x='shared', y='independent')
assert chart.resolve == alt.Resolve(axis=alt.AxisResolveMap(x='shared', y='independent'))
Expand Down
1 change: 1 addition & 0 deletions doc/user_guide/encoding.rst
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ quantitative ``Q`` a continuous real-valued quantity
ordinal ``O`` a discrete ordered quantity
nominal ``N`` a discrete unordered category
temporal ``T`` a time or date value
geojson ``G`` a geographic shape
============ ============== ================================================

If types are not specified for data input as a DataFrame, Altair defaults to
Expand Down