Skip to content

A reactive notebook for Python — run reproducible experiments, query with SQL, execute as a script, deploy as an app, and version with git. Stored as pure Python. All in a modern, AI-native editor.

fix: respect width properties on mo.ui.altair_chart (#402)

Myles Scolnicka281a84083bd
diff --git a/frontend/src/plugins/impl/vega/vega.css b/frontend/src/plugins/impl/vega/vega.css
index c8e87e71d2..5030edd9b6 100644
--- a/frontend/src/plugins/impl/vega/vega.css
+++ b/frontend/src/plugins/impl/vega/vega.css
@@ -1,6 +1,5 @@
.vega-embed {
width: 100%;
- height: 100%;
min-width: 300px;
flex: 1;
}
diff --git a/marimo/_plugins/ui/_impl/altair_chart.py b/marimo/_plugins/ui/_impl/altair_chart.py
index 092fcf6c21..87a39d9a1a 100644
--- a/marimo/_plugins/ui/_impl/altair_chart.py
+++ b/marimo/_plugins/ui/_impl/altair_chart.py
@@ -196,7 +196,11 @@ class altair_chart(UIElement[ChartSelection, "pd.DataFrame"]):
f"{type(chart)}; expected altair.Chart"
)
- if isinstance(chart, (alt.Chart, alt.LayerChart)):
+ # Make full-width if no width is specified
+ if (
+ isinstance(chart, (alt.Chart, alt.LayerChart))
+ and chart.width is alt.Undefined
+ ):
chart = chart.properties(width="container")
vega_spec = _parse_spec(chart)
diff --git a/marimo/_smoke_tests/altair_charts.py b/marimo/_smoke_tests/altair_charts.py
index c9d918d1ed..ac1223c164 100644
--- a/marimo/_smoke_tests/altair_charts.py
+++ b/marimo/_smoke_tests/altair_charts.py
@@ -1,7 +1,7 @@
# Copyright 2023 Marimo. All rights reserved.
import marimo
-__generated_with = "0.1.50"
+__generated_with = "0.1.59"
app = marimo.App(width="full")
@@ -142,6 +142,34 @@ def __(chart2, mo):
return
+def __(mo):
+ mo.md("# Defined Width + Height")
+ return
+
+
+def __(alt, iris, mo):
+ _chart = (
+ alt.Chart(iris)
+ .mark_circle()
+ .properties(width=600, height=400)
+ .encode(
+ alt.X("sepalLength", scale=alt.Scale(zero=False)),
+ alt.Y("sepalWidth", scale=alt.Scale(zero=False)),
+ color="species",
+ size="petalWidth",
+ )
+ )
+
+ mo.ui.altair_chart(
+ _chart,
+ chart_selection=None,
+ legend_selection=None,
+ )
+ return
+
+
@app.cell
def __(alt, chart_selection_value, iris, legend_selection_value, mo):
# _color_sel = alt.selection_point(fields=["species"], bind="legend")