Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Do not change the default dimensions of altair charts unless they are set with the altair specific options #1646

Merged
merged 4 commits into from
Aug 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,12 @@

- Fixes for CRAN check failures (#1645)

- Avoid overwriting Altair's default chart dimensions
with the values of `ut.width.px` and `ut.height.px`.
Instead, use `altair.fig.height`, `altair.fig.width`,
or Altair's `width` and `height` parameters
to adjust chart dimensions.

- New `as.raw()` method for `python.builtin.bytes` (#1649, #1652)

- `as.character()` method for `python.builtin.bytes` gains a `nul` argument,
Expand Down
14 changes: 5 additions & 9 deletions R/knitr-engine.R
Original file line number Diff line number Diff line change
Expand Up @@ -767,22 +767,18 @@ eng_python_autoprint <- function(captured, options) {

} else if (eng_python_is_altair_chart(value)) {

# set width if it's not already set
# set width and height if it's not already set
# This only applies to Chart objects, compound charts like HConcatChart
# don't have a 'width' or 'height' property attribute.
# TODO: add support for propagating width/height options from knitr to
# altair compound charts
width <- py_get_attr(value, "width", TRUE)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not sure if this line (and the corresponding one for height) are still needed, but I left them in for now.

if (inherits(width, "altair.utils.schemapi.UndefinedType")) {
width <- options$altair.fig.width %||% options$out.width.px %||% 810L
value <- value$properties(width = width)
if (!is.null(options$altair.fig.width)) {
value <- value$properties(width = options$altair.fig.width)
}

# set height if it's not already set
height <- py_get_attr(value, "height", TRUE)
if (inherits(height, "altair.utils.schemapi.UndefinedType")) {
height <- options$altair.fig.height %||% options$out.height.px %||% 400L
value <- value$properties(height = height)
if (!is.null(options$altair.fig.height)) {
value <- value$properties(height = options$altair.fig.height)
}

# set a unique id (used for div container for figure)
Expand Down
Loading