Skip to content

Commit

Permalink
Merge pull request #1646 from joelostblom/respect-altair-defaults
Browse files Browse the repository at this point in the history
fix: Do not change the default dimensions of altair charts unless they are set with the altair specific options
  • Loading branch information
t-kalinowski authored Aug 23, 2024
2 parents 588ff09 + 082d2c9 commit 750ebc9
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 9 deletions.
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)
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

0 comments on commit 750ebc9

Please sign in to comment.