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

WIP: type hints for tab completion #2769

Closed
wants to merge 20 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
7980164
Add method based syntax from #1629 to v5
joelostblom Apr 16, 2022
91ddea9
Add correct function signatures and docstrings, and initial autocompl…
joelostblom May 13, 2022
9fa0c38
Merge branch 'altair-viz:master' into method-based-attr-setting
joelostblom Nov 24, 2022
cc5ca7c
Add general param info to docstrings and pass through adding the help…
joelostblom Nov 30, 2022
de8c650
Deal with docstring missing "Attributes" tag
joelostblom Nov 30, 2022
3e45b79
Fix black formatting
joelostblom Nov 30, 2022
0bc0aa1
Fix black formatting
joelostblom Nov 30, 2022
d749916
Update a few gallery examples to the method based syntax
joelostblom Dec 5, 2022
c33b093
Add test for method based attr setting
joelostblom Dec 5, 2022
34d83f5
Convert timeunit param to method
joelostblom Dec 5, 2022
adddf46
Convert a few additional gallery examples
joelostblom Dec 5, 2022
7db01fc
Convert a few additional gallery examples
joelostblom Dec 5, 2022
8992c96
Update relative imports syntax
joelostblom Dec 5, 2022
93640d4
Remove unused import
joelostblom Dec 5, 2022
734f003
Only generate new schema for the latest version of vega lite to avoid…
joelostblom Dec 5, 2022
f323915
Add another set of gallery examples
joelostblom Dec 7, 2022
52e6ada
Add another set of gallery examples
joelostblom Dec 8, 2022
ffcca0c
Add last set of gallery examples
joelostblom Dec 15, 2022
51cf112
Draft type hints for property setters
ChristopherDavisUCI Dec 21, 2022
8f22e96
Black formatting
ChristopherDavisUCI Dec 21, 2022
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
22 changes: 11 additions & 11 deletions altair/examples/airport_connections.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
"""
Connections Among U.S. Airports Interactive
-------------------------------------------
This example shows all the connections between major U.S. airports. Lookup transformations
are used to find the coordinates of each airport and connecting airports. Connections
This example shows all the connections between major U.S. airports. Lookup transformations
are used to find the coordinates of each airport and connecting airports. Connections
are displayed on mouseover via a single selection.
"""
# category: case studies
Expand All @@ -26,10 +26,10 @@
)

background = alt.Chart(states).mark_geoshape(
fill="lightgray",
fill="lightgray",
stroke="white"
).properties(
width=750,
width=750,
height=500
).project("albersUsa")

Expand All @@ -39,11 +39,11 @@
latitude2="lat2:Q",
longitude2="lon2:Q"
).transform_lookup(
lookup="origin",
lookup="origin",
from_=lookup_data
).transform_lookup(
lookup="destination",
from_=lookup_data,
lookup="destination",
from_=lookup_data,
as_=["state", "lat2", "lon2"]
).transform_filter(
select_city
Expand All @@ -52,14 +52,14 @@
points = alt.Chart(flights_airport).mark_circle().encode(
latitude="latitude:Q",
longitude="longitude:Q",
size=alt.Size("routes:Q", scale=alt.Scale(range=[0, 1000]), legend=None),
order=alt.Order("routes:Q", sort="descending"),
size=alt.Size("routes:Q").legend(None).scale(range=[0, 1000]),
order=alt.Order("routes:Q").sort("descending"),
tooltip=["origin:N", "routes:Q"]
).transform_aggregate(
routes="count()",
routes="count()",
groupby=["origin"]
).transform_lookup(
lookup="origin",
lookup="origin",
from_=lookup_data
).transform_filter(
(alt.datum.state != "PR") & (alt.datum.state != "VI")
Expand Down
13 changes: 9 additions & 4 deletions altair/examples/annual_weather_heatmap.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,16 @@
source = data.seattle_weather()

alt.Chart(source, title="Daily Max Temperatures (C) in Seattle, WA").mark_rect().encode(
x=alt.X("date(date):O", title="Day", axis=alt.Axis(format="%e", labelAngle=0)),
y=alt.Y("month(date):O", title="Month"),
color=alt.Color("max(temp_max)", legend=alt.Legend(title=None)),
alt.X("date(date):O").title("Day").axis(format="%e", labelAngle=0),
alt.Y("month(date):O").title("Month"),
alt.Color("max(temp_max)").title(None),
tooltip=[
alt.Tooltip("monthdate(date)", title="Date"),
alt.Tooltip("max(temp_max)", title="Max Temp"),
],
).configure_view(step=13, strokeWidth=0).configure_axis(domain=False)
).configure_view(
step=13,
strokeWidth=0
).configure_axis(
domain=False
)
4 changes: 2 additions & 2 deletions altair/examples/anscombe_plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
source = data.anscombe()

alt.Chart(source).mark_circle().encode(
alt.X('X', scale=alt.Scale(zero=False)),
alt.Y('Y', scale=alt.Scale(zero=False)),
alt.X('X').scale(zero=False),
alt.Y('Y').scale(zero=False),
alt.Facet('Series', columns=2),
).properties(
width=180,
Expand Down
12 changes: 5 additions & 7 deletions altair/examples/bar_chart_trellis_compact.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,9 @@
)

alt.Chart(source, width=60, height=alt.Step(8)).mark_bar().encode(
y=alt.Y("c:N", axis=None),
x=alt.X("p:Q", title=None, axis=alt.Axis(format="%")),
color=alt.Color(
"c:N", title="settings", legend=alt.Legend(orient="bottom", titleOrient="left")
),
row=alt.Row("a:N", title="Factor A", header=alt.Header(labelAngle=0)),
column=alt.Column("b:N", title="Factor B"),
alt.Y("c:N").axis(None),
alt.X("p:Q").title(None).axis(format="%"),
alt.Color("c:N").title("settings").legend(orient="bottom", titleOrient="left"),
alt.Row("a:N").title("Factor A").header(labelAngle=0),
alt.Column("b:N").title("Factor B"),
)
31 changes: 13 additions & 18 deletions altair/examples/beckers_barley_trellis_plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,24 +10,19 @@
source = data.barley()

alt.Chart(source, title="The Morris Mistake").mark_point().encode(
alt.X(
'yield:Q',
title="Barley Yield (bushels/acre)",
scale=alt.Scale(zero=False),
axis=alt.Axis(grid=False)
),
alt.Y(
'variety:N',
title="",
sort='-x',
axis=alt.Axis(grid=True)
),
color=alt.Color('year:N', legend=alt.Legend(title="Year")),
row=alt.Row(
'site:N',
title="",
sort=alt.EncodingSortField(field='yield', op='sum', order='descending'),
)
alt.X('yield:Q')
.title("Barley Yield (bushels/acre)")
.scale(zero=False)
.axis(grid=False),
alt.Y('variety:N')
.title("")
.sort('-x')
.axis(grid=True),
alt.Color('year:N')
.legend(title="Year"),
alt.Row('site:N')
.title("")
.sort(alt.EncodingSortField(field='yield', op='sum', order='descending'))
).properties(
height=alt.Step(20)
).configure_view(stroke="transparent")
2 changes: 1 addition & 1 deletion altair/examples/beckers_barley_wrapped_facet.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
source = data.barley.url

alt.Chart(source).mark_point().encode(
alt.X('median(yield):Q', scale=alt.Scale(zero=False)),
alt.X('median(yield):Q').scale(zero=False),
y='variety:O',
color='year:N',
facet=alt.Facet('site:O', columns=2),
Expand Down
6 changes: 3 additions & 3 deletions altair/examples/bump_chart.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
stocks = data.stocks()
source = stocks.groupby([pd.Grouper(key="date", freq="6M"),"symbol"]).mean().reset_index()

alt.Chart(source).mark_line(point = True).encode(
x = alt.X("date:O", timeUnit="yearmonth", title="date"),
alt.Chart(source).mark_line(point=True).encode(
x=alt.X("date:O").timeUnit("yearmonth").title("date"),
y="rank:O",
color=alt.Color("symbol:N")
).transform_window(
Expand All @@ -26,4 +26,4 @@
title="Bump Chart for Stock Prices",
width=600,
height=150,
)
)
28 changes: 12 additions & 16 deletions altair/examples/candlestick_chart.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,27 +12,23 @@

source = data.ohlc()

open_close_color = alt.condition("datum.open <= datum.close",
alt.value("#06982d"),
alt.value("#ae1325"))
open_close_color = alt.condition(
"datum.open <= datum.close",
alt.value("#06982d"),
alt.value("#ae1325")
)

base = alt.Chart(source).encode(
alt.X('date:T',
axis=alt.Axis(
format='%m/%d',
labelAngle=-45,
title='Date in 2009'
)
),
alt.X('date:T')
.axis(format='%m/%d', labelAngle=-45)
.title('Date in 2009'),
color=open_close_color
)

rule = base.mark_rule().encode(
alt.Y(
'low:Q',
title='Price',
scale=alt.Scale(zero=False),
),
alt.Y('low:Q')
.title('Price')
.scale(zero=False),
alt.Y2('high:Q')
)

Expand All @@ -41,4 +37,4 @@
alt.Y2('close:Q')
)

rule + bar
rule + bar
29 changes: 14 additions & 15 deletions altair/examples/co2_concentration.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,25 +27,24 @@
groupby=['decade'],
frame=[None, None]
).transform_calculate(
end="datum.first_date === datum.scaled_date ? 'first' : datum.last_date === datum.scaled_date ? 'last' : null"
end=(
"datum.first_date === datum.scaled_date ? 'first'"
": datum.last_date === datum.scaled_date ? 'last'"
": null"
)
).encode(
x=alt.X(
"scaled_date:Q",
axis=alt.Axis(title="Year into Decade", tickCount=11)
),
y=alt.Y(
"CO2:Q",
title="CO2 concentration in ppm",
scale=alt.Scale(zero=False)
)
alt.X("scaled_date:Q")
.title("Year into Decade")
.axis(tickCount=11),
alt.Y("CO2:Q")
.title("CO2 concentration in ppm")
.scale(zero=False)
)

line = base.mark_line().encode(
color=alt.Color(
"decade:O",
scale=alt.Scale(scheme="magma"),
legend=None
)
alt.Color("decade:O")
.scale(scheme="magma")
.legend(None)
)

text = base.encode(text="year:N")
Expand Down
48 changes: 30 additions & 18 deletions altair/examples/comet_chart.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,22 +11,34 @@
import altair as alt
import vega_datasets

(
alt.Chart(vega_datasets.data.barley.url)
.transform_pivot("year", value="yield", groupby=["variety", "site"])
.transform_fold(["1931", "1932"], as_=["year", "yield"])
.transform_calculate(calculate="datum['1932'] - datum['1931']", as_="delta")
.mark_trail()
.encode(
x=alt.X('year:O', title=None),
y=alt.Y('variety:N', title='Variety'),
size=alt.Size('yield:Q', scale=alt.Scale(range=[0, 12]), legend=alt.Legend(values=[20, 60], title='Barley Yield (bushels/acre)')),
color=alt.Color('delta:Q', scale=alt.Scale(domainMid=0), legend=alt.Legend(title='Yield Delta (%)')),
tooltip=alt.Tooltip(['year:O', 'yield:Q']),
column=alt.Column('site:N', title='Site')

)
.configure_view(stroke=None)
.configure_legend(orient='bottom', direction='horizontal')
.properties(title='Barley Yield comparison between 1932 and 1931')
alt.Chart(
vega_datasets.data.barley.url,
title='Barley Yield comparison between 1932 and 1931'
).mark_trail().encode(
alt.X('year:O').title(None),
alt.Y('variety:N').title('Variety'),
alt.Size('yield:Q')
.scale(range=[0, 12])
.legend(values=[20, 60])
.title('Barley Yield (bushels/acre)'),
alt.Color('delta:Q')
.scale(domainMid=0)
.title('Yield Delta (%)'),
alt.Tooltip(['year:O', 'yield:Q']),
alt.Column('site:N').title('Site')
).transform_pivot(
"year",
value="yield",
groupby=["variety", "site"]
).transform_fold(
["1931", "1932"],
as_=["year", "yield"]
).transform_calculate(
calculate="datum['1932'] - datum['1931']",
as_="delta"
).configure_legend(
orient='bottom',
direction='horizontal'
).configure_view(
stroke=None
)
4 changes: 2 additions & 2 deletions altair/examples/connected_scatterplot.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
source = data.driving()

alt.Chart(source).mark_line(point=True).encode(
alt.X('miles', scale=alt.Scale(zero=False)),
alt.Y('gas', scale=alt.Scale(zero=False)),
alt.X('miles').scale(zero=False),
alt.Y('gas').scale(zero=False),
order='year'
)
2 changes: 1 addition & 1 deletion altair/examples/density_stack.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,6 @@
steps=200
).mark_area().encode(
alt.X('value:Q'),
alt.Y('density:Q', stack='zero'),
alt.Y('density:Q').stack('zero'),
alt.Color('Measurement_type:N')
).properties(width=400, height=100)
8 changes: 2 additions & 6 deletions altair/examples/diverging_stacked_bar_chart.py
Original file line number Diff line number Diff line change
Expand Up @@ -358,10 +358,6 @@
alt.Chart(source).mark_bar().encode(
x='percentage_start:Q',
x2='percentage_end:Q',
y=alt.Y('question:N', axis=y_axis),
color=alt.Color(
'type:N',
legend=alt.Legend( title='Response'),
scale=color_scale,
)
y=alt.Y('question:N').axis(y_axis),
color=alt.Color('type:N').title('Response').scale(color_scale),
)
9 changes: 6 additions & 3 deletions altair/examples/donut_chart.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,12 @@
import pandas as pd
import altair as alt

source = pd.DataFrame({"category": [1, 2, 3, 4, 5, 6], "value": [4, 6, 10, 3, 7, 8]})
source = pd.DataFrame({
"category": [1, 2, 3, 4, 5, 6],
"value": [4, 6, 10, 3, 7, 8]
})

alt.Chart(source).mark_arc(innerRadius=50).encode(
theta=alt.Theta(field="value", type="quantitative"),
color=alt.Color(field="category", type="nominal"),
theta="value",
color="category:N",
)
12 changes: 6 additions & 6 deletions altair/examples/dot_dash_plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,23 +16,23 @@

# Configure the points
points = base.mark_point().encode(
x=alt.X('Miles_per_Gallon', title=''),
y=alt.Y('Horsepower', title=''),
alt.X('Miles_per_Gallon').title(''),
alt.Y('Horsepower').title(''),
color=alt.condition(brush, 'Origin', alt.value('grey'))
)

# Configure the ticks
tick_axis = alt.Axis(labels=False, domain=False, ticks=False)

x_ticks = base.mark_tick().encode(
alt.X('Miles_per_Gallon', axis=tick_axis),
alt.Y('Origin', title='', axis=tick_axis),
alt.X('Miles_per_Gallon').axis(tick_axis),
alt.Y('Origin').title('').axis(tick_axis),
color=alt.condition(brush, 'Origin', alt.value('lightgrey'))
)

y_ticks = base.mark_tick().encode(
alt.X('Origin', title='', axis=tick_axis),
alt.Y('Horsepower', axis=tick_axis),
alt.X('Origin').title('').axis(tick_axis),
alt.Y('Horsepower').axis(tick_axis),
color=alt.condition(brush, 'Origin', alt.value('lightgrey'))
)

Expand Down