From 83a3a64da9e15f0fce369dfeab20abc64be4868a Mon Sep 17 00:00:00 2001 From: dangotbanned <125183946+dangotbanned@users.noreply.github.com> Date: Sat, 2 Nov 2024 12:46:31 +0000 Subject: [PATCH] style: Revert style changes in user guide https://github.com/vega/altair/pull/3544#discussion_r1825666513, https://github.com/vega/altair/pull/3544#discussion_r1825666641, https://github.com/vega/altair/pull/3544#discussion_r1825666004, https://github.com/vega/altair/pull/3544#discussion_r1825666103, https://github.com/vega/altair/pull/3544#discussion_r1825663695, https://github.com/vega/altair/pull/3544#discussion_r1825663427, https://github.com/vega/altair/pull/3544#discussion_r1825664959, https://github.com/vega/altair/pull/3544#discussion_r1825665411 --- doc/case_studies/exploring-weather.rst | 45 ++++++++++------------ doc/user_guide/compound_charts.rst | 19 ++++----- doc/user_guide/interactions/parameters.rst | 17 ++++---- doc/user_guide/transform/filter.rst | 30 +++++++-------- doc/user_guide/transform/pivot.rst | 16 ++++---- 5 files changed, 63 insertions(+), 64 deletions(-) diff --git a/doc/case_studies/exploring-weather.rst b/doc/case_studies/exploring-weather.rst index 058085faa..ad2a3bc2d 100644 --- a/doc/case_studies/exploring-weather.rst +++ b/doc/case_studies/exploring-weather.rst @@ -226,33 +226,30 @@ of the selection (for more information on selections, see .. altair-plot:: brush = alt.selection_interval() - color = ( - alt.when(brush) - .then(alt.Color("weather:N").scale(scale)) - .otherwise(alt.value("lightgray")) + color = alt.Color("weather:N").scale(scale) + temp_range = alt.datum["temp_max"] - alt.datum["temp_min"] + + points = alt.Chart(width=600, height=400).mark_point().encode( + alt.X("temp_max:Q").title("Maximum Daily Temperature (C)"), + alt.Y("temp_range:Q").title("Daily Temperature Range (C)"), + color=alt.when(brush).then(color).otherwise(alt.value("lightgray")), + size=alt.Size("precipitation:Q").scale(range=[1, 200]), + ).transform_calculate( + temp_range=temp_range + ).add_params( + brush ) - points = ( - alt.Chart() - .mark_point() - .encode( - alt.X("temp_max:Q").title("Maximum Daily Temperature (C)"), - alt.Y("temp_range:Q").title("Daily Temperature Range (C)"), - color=color, - size=alt.Size("precipitation:Q").scale(range=[1, 200]), - ) - .transform_calculate("temp_range", "datum.temp_max - datum.temp_min") - .properties(width=600, height=400) - .add_params(brush) - ) - bars = ( - alt.Chart() - .mark_bar() - .encode(x="count()", y="weather:N", color=alt.Color("weather:N").scale(scale)) - .transform_calculate("temp_range", "datum.temp_max - datum.temp_min") - .transform_filter(brush) - .properties(width=600) + bars = alt.Chart(width=600).mark_bar().encode( + x="count()", + y="weather:N", + color=color + ).transform_calculate( + temp_range=temp_range + ).transform_filter( + brush ) + alt.vconcat(points, bars, data=df) This chart, containing concatenations, data transformations, selections, and diff --git a/doc/user_guide/compound_charts.rst b/doc/user_guide/compound_charts.rst index 171e83f28..a39114d38 100644 --- a/doc/user_guide/compound_charts.rst +++ b/doc/user_guide/compound_charts.rst @@ -366,21 +366,22 @@ layered chart with a hover selection: hover = alt.selection_point(on='pointerover', nearest=True, empty=False) when_hover = alt.when(hover) - base = ( - alt.Chart(iris) - .encode( - x="petalLength:Q", - y="petalWidth:Q", - color=when_hover.then("species:N").otherwise(alt.value("lightgray")), - ) - .properties(width=180, height=180) + base = alt.Chart(iris).encode( + x='petalLength:Q', + y='petalWidth:Q', + color=when_hover.then("species:N").otherwise(alt.value("lightgray")) + ).properties( + width=180, + height=180, ) + points = base.mark_point().add_params(hover) + text = base.mark_text(dy=-5).encode( text="species:N", opacity=when_hover.then(alt.value(1)).otherwise(alt.value(0)), ) - + (points + text).facet("species:N") Though each of the above examples have faceted the data across columns, diff --git a/doc/user_guide/interactions/parameters.rst b/doc/user_guide/interactions/parameters.rst index 8ebb30146..cf42d572b 100644 --- a/doc/user_guide/interactions/parameters.rst +++ b/doc/user_guide/interactions/parameters.rst @@ -172,7 +172,9 @@ a conditional color encoding: x="Horsepower:Q", y="Miles_per_Gallon:Q", color=conditional, - ).add_params(brush) + ).add_params( + brush + ) As you can see, the color of the points now changes depending on whether they are inside or outside the selection. Above we are using the selection parameter ``brush`` as a *predicate* @@ -207,14 +209,15 @@ Omitting the ``.otherwise()`` clause will use the channel default instead: source = data.cars() brush = alt.selection_interval() - color = alt.when(brush).then(alt.value('goldenrod')) - points = ( - alt.Chart(source) - .mark_point() - .encode(x="Horsepower", y="Miles_per_Gallon", color=color) - .add_params(brush) + points = alt.Chart(source).mark_point().encode( + x="Horsepower", + y="Miles_per_Gallon", + color=alt.when(brush).then(alt.value("goldenrod")) + ).add_params( + brush ) + points Multiple conditional branches (``if, elif, ..., elif`` in Python) diff --git a/doc/user_guide/transform/filter.rst b/doc/user_guide/transform/filter.rst index 73f43ae16..fb4c7420f 100644 --- a/doc/user_guide/transform/filter.rst +++ b/doc/user_guide/transform/filter.rst @@ -135,23 +135,23 @@ to select the data to be shown in the top chart: selection = alt.selection_point(fields=['year']) - top = ( - alt.Chart() - .mark_line() - .encode(x="age:O", y="sum(people):Q", color="year:O") - .properties(width=600, height=200) - .transform_filter(selection) - ) - color = ( - alt.when(selection).then(alt.value("steelblue")).otherwise(alt.value("lightgray")) + top = alt.Chart(width=600, height=200).mark_line().encode( + x="age:O", + y="sum(people):Q", + color="year:O" + ).transform_filter( + selection ) - bottom = ( - alt.Chart() - .mark_bar() - .encode(x="year:O", y="sum(people):Q", color=color) - .properties(width=600, height=100) - .add_params(selection) + + color = alt.when(selection).then(alt.value("steelblue")).otherwise(alt.value("lightgray")) + bottom = alt.Chart(width=600, height=100).mark_bar().encode( + x="year:O", + y="sum(people):Q", + color=color + ).add_params( + selection ) + alt.vconcat(top, bottom, data=pop) Logical Operands diff --git a/doc/user_guide/transform/pivot.rst b/doc/user_guide/transform/pivot.rst index 24258cb82..eb280d1e5 100644 --- a/doc/user_guide/transform/pivot.rst +++ b/doc/user_guide/transform/pivot.rst @@ -56,15 +56,13 @@ values on multiple lines: lines = base.mark_line().encode(y='price:Q', color='symbol:N') points = lines.mark_point().transform_filter(selection) - rule = ( - base.transform_pivot("symbol", value="price", groupby=["date"]) - .mark_rule() - .encode( - opacity=alt.when(selection).then(alt.value(0.3)).otherwise(alt.value(0)), - tooltip=[alt.Tooltip(c, type="quantitative") for c in columns], - ) - .add_params(selection) - ) + rule = base.transform_pivot( + 'symbol', value='price', groupby=['date'] + ).mark_rule().encode( + opacity=alt.when(selection).then(alt.value(0.3)).otherwise(alt.value(0)), + tooltip=[alt.Tooltip(c, type='quantitative') for c in columns] + ).add_params(selection) + lines + points + rule