Skip to content

Commit

Permalink
docs: Use *predicates in "Faceted Line Chart with Cumulative Sum"
Browse files Browse the repository at this point in the history
Makes use of #3668

Resolves #3664 (comment)
  • Loading branch information
dangotbanned committed Nov 3, 2024
1 parent a375ab5 commit 7f6c188
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,8 @@
columns_sorted = ['Drought', 'Epidemic', 'Earthquake', 'Flood']

alt.Chart(source).transform_filter(
{'and': [ # type: ignore[arg-type]
alt.FieldOneOfPredicate(field='Entity', oneOf=columns_sorted), # Filter data to show only disasters in columns_sorted
alt.FieldRangePredicate(field='Year', range=[1900, 2000]) # Filter data to show only 20th century
]}
alt.FieldOneOfPredicate(field='Entity', oneOf=columns_sorted),
alt.FieldRangePredicate(field='Year', range=[1900, 2000])
).transform_window(
cumulative_deaths='sum(Deaths)', groupby=['Entity'] # Calculate cumulative sum of Deaths by Entity
).mark_line().encode(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,8 @@
columns_sorted = ['Drought', 'Epidemic', 'Earthquake', 'Flood']

alt.Chart(source).transform_filter(
{'and': [ # type: ignore[arg-type]
alt.FieldOneOfPredicate(field='Entity', oneOf=columns_sorted), # Filter data to show only disasters in columns_sorted
alt.FieldRangePredicate(field='Year', range=[1900, 2000]) # Filter data to show only 20th century
]}
alt.FieldOneOfPredicate(field='Entity', oneOf=columns_sorted),
alt.FieldRangePredicate(field='Year', range=[1900, 2000])
).transform_window(
cumulative_deaths='sum(Deaths)', groupby=['Entity'] # Calculate cumulative sum of Deaths by Entity
).mark_line().encode(
Expand Down

0 comments on commit 7f6c188

Please sign in to comment.