Skip to content

Commit

Permalink
Merge pull request #184 from animint/hello-world-example
Browse files Browse the repository at this point in the history
hello world example in ?animint
  • Loading branch information
tdhock authored Jan 26, 2025
2 parents f4f1b4a + 111df2c commit 00d0d7f
Show file tree
Hide file tree
Showing 7 changed files with 63 additions and 3 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: animint2
Title: Animated Interactive Grammar of Graphics
Version: 2025.1.25
Version: 2025.1.27
URL: https://animint.github.io/animint2/
BugReports: https://github.com/animint/animint2/issues
Authors@R: c(
Expand Down
5 changes: 5 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
# Changes in version 2025.1.27 (PR#184)

- Add simple Hello world example to ?animint.
- Increase text size of "a" in legend SVG.

# Changes in version 2025.1.25 (PR#182)

- Tour text includes selector names for geoms with named clickSelects/showSelected.
Expand Down
2 changes: 1 addition & 1 deletion R/geom-text.r
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ GeomText <- gganimintproto("GeomText", Geom,
required_aes = c("x", "y", "label"),

default_aes = aes(
colour = "black", size = 3.88, angle = 0, hjust = 0.5,
colour = "black", size = 12, angle = 0, hjust = 0.5,
vjust = 0.5, alpha = NA, family = "", fontface = 1, lineheight = 1.2
),

Expand Down
1 change: 0 additions & 1 deletion R/z_animint.R
Original file line number Diff line number Diff line change
Expand Up @@ -817,7 +817,6 @@ getLegendList <- function(plistextra){
gdefs[[legend.name]]$breaks <- sc$breaks
}
}

legend.list <- lapply(gdefs, getLegend)
## Add a flag to specify whether or not there is both a color and a
## fill legend to display. If so, we need to draw the interior of
Expand Down
22 changes: 22 additions & 0 deletions R/z_print.R
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,28 @@ print.animint <- function(x, ...){
##' @return list of class animint
##' @author Toby Dylan Hocking
##' @examples
##'
##' if(require('data.table'))setDTthreads(1)#for CRAN.
##' library(animint2)
##' ## Simple hello world example (1 selector: word).
##' animint(ggplot()+geom_text(aes(
##' word, word, label=word, color=word),
##' data=data.frame(word=c("Hello","world!"))))
##'
##' ## More complex Hello World (2 selectors: number, language).
##' hello_df = data.frame(
##' language=c("en","en","fr","fr"),
##' word=c("Hello","world!","Bonjour","monde !"),
##' number=factor(c(1,2,1,2)))
##' animint(ggplot()+geom_text(aes(
##' number, "message", label=word, color=number),
##' showSelected="language", data=hello_df)+
##' geom_text(aes(
##' number, "select language", label=language),
##' clickSelects="language",
##' data=data.frame(number=factor(1:2), language=c("en","fr"))))
##'
##' ## More complex World Bank example (3 selectors: country, region, year).
##' data(WorldBank, package="animint2")
##' years <- unique(WorldBank[, "year", drop=FALSE])
##' y1960 <- subset(WorldBank, year==1960)
Expand Down Expand Up @@ -66,6 +86,7 @@ print.animint <- function(x, ...){
##' geom_point(aes(
##' fertility.rate, life.expectancy,
##' key=country, colour=region, size=population),
##' chunk_vars=character(),
##' showSelected="year",
##' clickSelects="country",
##' data=WorldBank)+
Expand All @@ -74,6 +95,7 @@ print.animint <- function(x, ...){
##' key=country,
##' label=country),
##' showSelected=c("country", "year"),
##' chunk_vars=character(),
##' data=WorldBank)+
##' geom_text(aes(
##' 5, 80, key=1, label=paste("year =", year)),
Expand Down
22 changes: 22 additions & 0 deletions man/animint.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions tests/testthat/test-renderer1-theme-text-size.R
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ viz <- animint(
theme_grey()+
geom_text(aes(
0,y,label=text,color=text),
size=6,
data=df),
sizeNum=ggplot()+
ggtitle("theme_grey()+theme(legend.text)")+
Expand All @@ -129,6 +130,7 @@ viz <- animint(
theme(legend.text=element_text(size=16))+
geom_text(aes(
0,y,label=text,color=text),
size=24,
data=df),
sizePx=ggplot()+
ggtitle("theme_grey()+theme(legend.text)")+
Expand All @@ -154,6 +156,16 @@ test_that("theme_grey legend entry text size is 16px", {
expect_match(size.list$sizePx, "16px")
})

test_that("little a in legend svg is same size as key", {
text.selector <- '//table[@class="legend"]//svg//text'
size.computed <- getPropertyValue(info$html, text.selector, "font-size")
size.expected <- rep(c("12","6","24","12"),each=2)
expect_equal(size.computed, size.expected)
fill.computed <- getStyleValue(info$html, text.selector, "fill")
fill.expected <- rep(c("blue","red"),4)
expect_color(fill.computed, fill.expected)
})

test_that("text colors rendered", {
computed.colors <- getStyleValue(
info$html, '//svg[@id="plot_default"]//text[@class="geom"]', "fill")
Expand Down

0 comments on commit 00d0d7f

Please sign in to comment.