Skip to content

Commit 1d1eddd

Browse files
authored
Have ggplotly() replace default fonts with thematic's font option (#1804)
* Have ggplotly() replace default fonts with thematic's font option (if set), closes #1803 * bump docker image to R 4.0
1 parent 36e2928 commit 1d1eddd

File tree

7 files changed

+25
-6
lines changed

7 files changed

+25
-6
lines changed

R/ggplotly.R

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1258,12 +1258,31 @@ bbox <- function(txt = "foo", angle = 0, size = 12) {
12581258
text2font <- function(x = ggplot2::element_text(), type = "height") {
12591259
list(
12601260
color = toRGB(x$colour),
1261-
family = x$family,
1261+
family = font_family(x$family),
12621262
# TODO: what about the size of vertical text?
12631263
size = unitConvert(grid::unit(x$size %||% 0, "points"), "pixels", type)
12641264
)
12651265
}
12661266

1267+
# Replace a default font family, "", with thematic's font option (if set)
1268+
font_family <- function(family = "") {
1269+
if (!identical(family, "")) {
1270+
return(family)
1271+
}
1272+
if (!isNamespaceLoaded("thematic")) {
1273+
return("")
1274+
}
1275+
font <- thematic::thematic_get_option("font")
1276+
if (!length(font)) {
1277+
return("")
1278+
}
1279+
# font$families is a vector of families, but font.family wants to be a
1280+
# string (like CSS font-family), so make sure the names are unquoted,
1281+
# then quote them
1282+
families <- sub("'$", "", sub("^'", "", font$families))
1283+
sprintf("'%s'", paste(families, collapse = "', '"))
1284+
}
1285+
12671286
# wrap text in bold/italics according to the text "face"
12681287
faced <- function(txt, face = "plain") {
12691288
if (is.null(face)) face <- "plain"

inst/docker/Dockerfile.vtest

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ ARG CACHEBUST=1
1111

1212
# Need this to add R repo
1313
RUN apt-get update && apt-get install -y software-properties-common apt-transport-https \
14-
&& add-apt-repository "deb https://cloud.r-project.org/bin/linux/ubuntu xenial-cran35/" \
14+
&& add-apt-repository "deb https://cloud.r-project.org/bin/linux/ubuntu xenial-cran40/" \
1515
&& apt-key adv --keyserver keyserver.ubuntu.com --recv-keys E298A3A825C0D65DFD57CBB651716619E084DAB9 \
1616
&& apt-get update && apt-get install -y \
1717
sudo \

tests/figs/axes/ticktext-linebreaks.svg

Lines changed: 1 addition & 1 deletion
Loading

tests/figs/deps.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
- vdiffr-svg-engine: 1.0
2-
- vdiffr: 0.3.1.9000
2+
- vdiffr: 0.3.2
33
- freetypeharfbuzz: 0.2.5

tests/figs/hline/split-hline-vline-abline.svg

Lines changed: 1 addition & 1 deletion
Loading

tests/figs/subplot/plotly-subplot-ggmatrix.svg

Lines changed: 1 addition & 1 deletion
Loading

tests/testthat/Rplots.pdf

3.74 KB
Binary file not shown.

0 commit comments

Comments
 (0)