From 2398c4985ff02699c93dee59c5cc010b4776f7fc Mon Sep 17 00:00:00 2001 From: Joel Ostblom Date: Tue, 13 Aug 2024 16:13:45 +0200 Subject: [PATCH 1/3] Do not change the default dimensions of altair charts unless they are set explicitly This will avoid using the knitr default dimensions from other figure formats for altair charts since altair already has sensible and easily overidable defaults --- R/knitr-engine.R | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/R/knitr-engine.R b/R/knitr-engine.R index 0876b59fe..dd2e3fbe4 100644 --- a/R/knitr-engine.R +++ b/R/knitr-engine.R @@ -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) From 94716f49e99c29991d86dd99ef0cb9b90a9dc3e6 Mon Sep 17 00:00:00 2001 From: Joel Ostblom Date: Fri, 23 Aug 2024 04:48:21 +0200 Subject: [PATCH 2/3] Add altair dimensions note in change log --- NEWS.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/NEWS.md b/NEWS.md index b261e0094..184ddd11f 100644 --- a/NEWS.md +++ b/NEWS.md @@ -9,6 +9,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. + # reticulate 1.38.0 - Python Exceptions converted to R conditions are now R lists instead From 082d2c9e7873549e0ffc9d2385f62d1cd5d3ac19 Mon Sep 17 00:00:00 2001 From: Joel Ostblom Date: Fri, 23 Aug 2024 16:28:24 +0200 Subject: [PATCH 3/3] Fix typo --- NEWS.md | 1 - 1 file changed, 1 deletion(-) diff --git a/NEWS.md b/NEWS.md index 46310aa5c..cc99bd575 100644 --- a/NEWS.md +++ b/NEWS.md @@ -22,7 +22,6 @@ - `as.character()` method for `python.builtin.bytes` gains a `nul` argument, allowing for convenient handling of embedded NULs in the string. (#1652) - # reticulate 1.38.0 - Python Exceptions converted to R conditions are now R lists instead