Skip to content

Commit 5402282

Browse files
authored
Get altair's properties() method working again (#129)
1 parent 4451359 commit 5402282

File tree

2 files changed

+11
-6
lines changed

2 files changed

+11
-6
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
88
## [UNRELEASED]
99

1010
* The `@render_widget` decorator now attaches a `widget` (and `value`) attribute to the function it decorates. This allows for easier access to the widget instance (or value), and eliminates the need for `register_widget` (which is now soft deprecated). (#119)
11+
* The `.properties()` method on `altair.Chart` object now works as expected again. (#129)
1112
* Reduce default plot margins on plotly graphs.
1213

1314
## [0.2.4] - 2023-11-20

shinywidgets/_render_widget_base.py

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -195,16 +195,20 @@ def set_layout_defaults(widget: Widget) -> Tuple[Widget, bool]:
195195

196196
# Since as_widget() has already happened, we only need to handle JupyterChart
197197
if isinstance(widget, alt.JupyterChart):
198-
if isinstance(
199-
widget.chart, # pyright: ignore[reportUnknownMemberType]
200-
alt.ConcatChart,
201-
):
198+
chart = cast(alt.JupyterChart, widget).chart # type: ignore
199+
if isinstance(chart, alt.ConcatChart):
202200
# Throw warning to use ui.layout_column_wrap() instead
203201
warnings.warn(
204202
"Consider using shiny.ui.layout_column_wrap() instead of alt.concat() "
205-
"for multi-column layout (the latter doesn't support filling layout)."
203+
"for multi-column layout (the latter doesn't support filling layout).",
204+
stacklevel=2
206205
)
207206
else:
208-
widget.chart = widget.chart.properties(width="container", height="container") # type: ignore
207+
UndefinedType = alt.utils.schemapi.UndefinedType # type: ignore
208+
if isinstance(chart.width, UndefinedType): # type: ignore[reportMissingTypeStubs]
209+
chart = chart.properties(width="container") # type: ignore
210+
if isinstance(chart.height, UndefinedType): # type: ignore[reportMissingTypeStubs]
211+
chart = chart.properties(height="container") # type: ignore
212+
widget.chart = chart
209213

210214
return (widget, fill)

0 commit comments

Comments
 (0)