Skip to content

Commit

Permalink
Merge branch 'main' into when-then-user-guide
Browse files Browse the repository at this point in the history
  • Loading branch information
dangotbanned authored Sep 27, 2024
2 parents 3d01545 + cabf1e6 commit 4800d2c
Show file tree
Hide file tree
Showing 6 changed files with 116 additions and 2 deletions.
2 changes: 1 addition & 1 deletion altair/expr/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -237,4 +237,4 @@ def __repr__(self) -> str:
return f"{self.group}[{self.name!r}]"


IntoExpression: TypeAlias = Union[bool, None, str, OperatorMixin, Dict[str, Any]]
IntoExpression: TypeAlias = Union[bool, None, str, float, OperatorMixin, Dict[str, Any]]
2 changes: 1 addition & 1 deletion altair/vegalite/v5/display.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ def jupyter_renderer(spec: dict, **metadata):
JupyterChart.enable_offline(offline=offline) # type: ignore[attr-defined]

# propagate embed options
embed_options = metadata.get("embed_options", None)
embed_options = metadata.get("embed_options")

# Need to ignore attr-defined mypy rule because mypy doesn't see _repr_mimebundle_
# conditionally defined in AnyWidget
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
"""
Bar Chart with Labels based on Measured Luminance
=================================================
This example shows a basic horizontal bar chart with labels where the measured luminance to decides if the text overlay is be colored ``black`` or ``white``.
"""
# category: bar charts
import altair as alt
from vega_datasets import data

source = data.barley()

base = alt.Chart(source).encode(
x=alt.X('sum(yield):Q', stack='zero'),
y=alt.Y('site:O', sort='-x'),
text=alt.Text('sum(yield):Q', format='.0f')
)

bars = base.mark_bar(
tooltip=alt.expr("luminance(scale('color', datum.sum_yield))")
).encode(
color='sum(yield):Q'
)

text = base.mark_text(
align='right',
dx=-3,
color=alt.expr("luminance(scale('color', datum.sum_yield)) > 0.5 ? 'black' : 'white'")
)

bars + text
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
"""
Grouped Bar Chart with xOffset and overlapping bars
---------------------------------------------------
Like :ref:`gallery_grouped_bar_chart2`, this example shows a grouped bar chart using the ``xOffset`` encoding channel, but in this example the bars are partly overlapping within each group.
"""
# category: bar charts
import altair as alt
import pandas as pd

source = pd.DataFrame(
{
"category": list("AABBCC"),
"group": list("xyxyxy"),
"value": [0.1, 0.6, 0.7, 0.2, 0.6, 0.1],
}
)

base = alt.Chart(source, width=alt.Step(12)).encode(
x="category:N",
y="value:Q",
xOffset=alt.XOffset("group:N", scale=alt.Scale(paddingOuter=0.5)),
)

alt.layer(
base.mark_bar(size=20, stroke="white", fillOpacity=0.9).encode(fill="group:N"),
base.mark_text(dy=-5).encode(text="value:Q"),
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
"""
Bar Chart with Labels based on Measured Luminance
=================================================
This example shows a basic horizontal bar chart with labels where the measured luminance to decides if the text overlay is be colored ``black`` or ``white``.
"""
# category: bar charts
import altair as alt
from vega_datasets import data

source = data.barley()

base = alt.Chart(source).encode(
x=alt.X('sum(yield):Q').stack('zero'),
y=alt.Y('site:O').sort('-x'),
text=alt.Text('sum(yield):Q', format='.0f')
)

bars = base.mark_bar(
tooltip=alt.expr("luminance(scale('color', datum.sum_yield))")
).encode(
color='sum(yield):Q'
)

text = base.mark_text(
align='right',
dx=-3,
color=alt.expr("luminance(scale('color', datum.sum_yield)) > 0.5 ? 'black' : 'white'")
)

bars + text
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
"""
Grouped Bar Chart with xOffset and overlapping bars
---------------------------------------------------
Like :ref:`gallery_grouped_bar_chart2`, this example shows a grouped bar chart using the ``xOffset`` encoding channel, but in this example the bars are partly overlapping within each group.
"""
# category: bar charts
import altair as alt
import pandas as pd

source = pd.DataFrame(
{
"category": list("AABBCC"),
"group": list("xyxyxy"),
"value": [0.1, 0.6, 0.7, 0.2, 0.6, 0.1],
}
)

base = alt.Chart(source, width=alt.Step(12)).encode(
x="category:N",
y="value:Q",
xOffset=alt.XOffset("group:N").scale(paddingOuter=0.5),
)

alt.layer(
base.mark_bar(size=20, stroke="white", fillOpacity=0.9).encode(fill="group:N"),
base.mark_text(dy=-5).encode(text="value:Q"),
)

0 comments on commit 4800d2c

Please sign in to comment.