Skip to content

Commit

Permalink
docs: Add example for Then.when
Browse files Browse the repository at this point in the history
  • Loading branch information
dangotbanned committed Jul 21, 2024
1 parent 94764a2 commit cf5e676
Showing 1 changed file with 20 additions and 1 deletion.
21 changes: 20 additions & 1 deletion altair/vegalite/v5/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -907,7 +907,7 @@ def when(
A selection or test predicate. ``str`` input will be treated as a test operand.
.. note::
accepts the same range of inputs as in :func:`.condition()`.
Accepts the same range of inputs as in :func:`.condition()`.
*more_predicates
Additional predicates, restricted to types supporting ``&``.
empty
Expand All @@ -925,6 +925,25 @@ def when(
-------
:class:`ChainedWhen`
A partial state which requires calling :meth:`ChainedWhen.then()` to finish the condition.
Examples
--------
Chain calls to express precise queries::
import altair as alt
from vega_datasets import data
source = data.cars()
color = (
alt.when(alt.datum.Miles_per_Gallon >= 30, Origin="Europe")
.then(alt.value("crimson"))
.when(alt.datum.Horsepower > 150)
.then(alt.value("goldenrod"))
.otherwise(alt.value("grey"))
)
alt.Chart(source).mark_point().encode(x="Horsepower", y="Miles_per_Gallon", color=color)
"""
condition = _parse_when(predicate, *more_predicates, empty=empty, **constraints)
conditions = self.to_dict()
Expand Down

0 comments on commit cf5e676

Please sign in to comment.