Skip to content

Commit

Permalink
style: Revert style changes in user guide
Browse files Browse the repository at this point in the history
  • Loading branch information
dangotbanned committed Nov 2, 2024
1 parent 1a8c59a commit 83a3a64
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 64 deletions.
45 changes: 21 additions & 24 deletions doc/case_studies/exploring-weather.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
19 changes: 10 additions & 9 deletions doc/user_guide/compound_charts.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
17 changes: 10 additions & 7 deletions doc/user_guide/interactions/parameters.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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*
Expand Down Expand Up @@ -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)
Expand Down
30 changes: 15 additions & 15 deletions doc/user_guide/transform/filter.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
16 changes: 7 additions & 9 deletions doc/user_guide/transform/pivot.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down

0 comments on commit 83a3a64

Please sign in to comment.