Skip to content
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 src/resources/rmd/hooks.R
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,12 @@ knitr_hooks <- function(format, resourceDir, handledLanguages) {
options
}

# coalesce echos so that all code is displayed for renderings: [light, dark]
opts_hooks[["renderings"]] <- function(options){
options$fig.show = 'hold'
options
}

opts_hooks[["collapse"]] <- function(options) {
if (isTRUE(options[["collapse"]])) {
comment <- options[["comment"]]
Expand Down
8 changes: 3 additions & 5 deletions tests/docs/smoke-all/dark-mode/ggplot-brandless.qmd
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ ggplot(mtcars, aes(mpg, wt)) +

### with crossref but no caption

::: {#fig-thematic-ggplot}
::: {#fig-ggplot}
```{r}
#| echo: true
#| renderings:
Expand All @@ -89,15 +89,13 @@ ggplot(mtcars, aes(mpg, disp)) +
geom_point(aes(colour = factor(cyl))) + colour_scale
```

thematic - base r graphics
ggplot - dark only

</div>

## patchwork

### with crossref and caption

::: {#fig-thematic-patchwork}
::: {#fig-ggplot-mpg-hp}
```{r}
#| renderings: [light, dark]
theme_set(united_theme)
Expand Down
74 changes: 74 additions & 0 deletions tests/docs/smoke-all/dark-mode/ggplot-duobrand-echo.qmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
---
title: "knitr dark mode - ggplot"
brand:
light: united-brand.yml
dark: slate-brand.yml
execute:
echo: false
warning: false
_quarto:
tests:
html:
ensureHtmlElements:
-
- 'body.quarto-light'
- 'div.cell div.light-content'
- 'div.cell div.dark-content'
- 'div.cell div.cell-code pre.code-with-copy'
- []
ensureFileRegexMatches:
-
- 'united_theme <span class="sc">\+</span> colour_scale'
- 'slate_theme <span class="sc">\+</span> colour_scale'
- []
---

```{r}
#| echo: false
#| warning: false
library(ggplot2)

ggplot_theme <- function(bgcolor, fgcolor) {
theme_minimal(base_size = 11) %+%
theme(
panel.border = element_blank(),
panel.grid.major.y = element_blank(),
panel.grid.minor.y = element_blank(),
panel.grid.major.x = element_blank(),
panel.grid.minor.x = element_blank(),
text = element_text(colour = fgcolor),
axis.text = element_text(colour = fgcolor),
rect = element_rect(colour = bgcolor, fill = bgcolor),
plot.background = element_rect(fill = bgcolor, colour = NA),
axis.line = element_line(colour = fgcolor),
axis.ticks = element_line(colour = fgcolor)
)
}

brand_ggplot <- function(brand_yml) {
brand <- yaml::yaml.load_file(brand_yml)
ggplot_theme(brand$color$background, brand$color$foreground)
}

united_theme <- brand_ggplot("united-brand.yml")
slate_theme <- brand_ggplot("slate-brand.yml")

colour_scale <- scale_colour_manual(values = c("darkorange", "purple", "cyan4"))
```

### with crossref but no caption

and `echo: true`

::: {#fig-ggplot}

```{r}
#| echo: true
#| renderings: [light, dark]
ggplot(mtcars, aes(mpg, disp)) +
geom_point(aes(colour = factor(cyl))) + united_theme + colour_scale
ggplot(mtcars, aes(mpg, disp)) +
geom_point(aes(colour = factor(cyl))) + slate_theme + colour_scale
```

:::
9 changes: 3 additions & 6 deletions tests/docs/smoke-all/dark-mode/ggplot-duobrand.qmd
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ ggplot(mtcars, aes(mpg, wt)) +

and `echo: true`

::: {#fig-thematic-ggplot}
::: {#fig-ggplot}

```{r}
#| echo: true
Expand All @@ -83,8 +83,6 @@ ggplot(mtcars, aes(mpg, disp)) +

### with caption but no crossref

dark rendering only

<div>

```{r}
Expand All @@ -93,15 +91,14 @@ ggplot(mtcars, aes(mpg, disp)) +
geom_point(aes(colour = factor(cyl))) + slate_theme + colour_scale
```

thematic - base r graphics
ggplot - dark only

</div>

## patchwork

### with crossref and caption

::: {#fig-thematic-patchwork}
::: {#fig-ggplot-mpg-hp}
```{r}
#| renderings: [light, dark]
ggplot(mtcars, aes(mpg, hp)) +
Expand Down
Loading