Skip to content

Commit db7a579

Browse files
committed
Add geom_text + colour to our image diff reference
1 parent adfcee8 commit db7a579

File tree

2 files changed

+28
-1
lines changed

2 files changed

+28
-1
lines changed

run_tests_with_outputs.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
library(testthat)
2-
devtools::install_github("ropensci/plotly", ref="marianne-merge-layersintotraces")
2+
devtools::install_github("ropensci/plotly", ref="marianne-geom-text-colour")
33
library(plotly)
44

55
setwd("tests")

tests/testthat/test-ggplot-text.R

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,30 @@ test_that("textsize is translated correctly", {
1818
})
1919

2020
save_outputs(gg, "text")
21+
22+
test_that("geom_text splits along colour", {
23+
mds <- data.frame(State=c("Alabama", "Alabama", "Alabama", "Alabama",
24+
"Arizona", "Arizona"),
25+
City=c("HUNTSVILLE", "MOBILE", "BIRMINGHAM", "MONTGOMERY",
26+
"TUCSON", "PEORIA"),
27+
coord.1=c(1.561284, 6.088862, 9.978292, 15.454877,
28+
23.225289, -7.283954),
29+
coord.2=c(0.2228790, 0.8343259, -3.6507234, -4.8520206,
30+
-0.4438650, 9.1252792),
31+
Division=c("East South Central", "East South Central",
32+
"East South Central", "East South Central",
33+
"Mountain", "Mountain"))
34+
gg <- ggplot(mds) +
35+
geom_text(aes(x=coord.1, y=coord.2, label=City, colour=Division))
36+
L <- gg2list(gg)
37+
expect_equal(length(L), 3) # 2 traces + layout
38+
# Proper type and mode conversion
39+
expect_identical(L[[1]]$type, "scatter")
40+
expect_identical(L[[1]]$mode, "text")
41+
expect_identical(L[[2]]$type, "scatter")
42+
expect_identical(L[[2]]$mode, "text")
43+
# Right colour for each trace
44+
expect_identical(L[[1]]$textfont$color, "#F8766D")
45+
expect_identical(L[[2]]$textfont$color, "#00BFC4")
46+
save_outputs(gg, "text-colour")
47+
})

0 commit comments

Comments
 (0)