facet title: vignette and tests

This commit is contained in:
pvictor 2021-01-08 11:33:13 +01:00
parent 67680c48f3
commit 83d6926fe6
7 changed files with 98 additions and 2 deletions

View File

@ -38,3 +38,13 @@ apex(mpg, aes(displ, cty), type = "scatter") %>%
}
)
# Title and subtitle are treated as global
apex(mpg, aes(displ, cty), type = "scatter") %>%
ax_labs(
title = "Facet grid example",
subtitle = "mpg data from ggplot2"
) %>%
ax_facet_grid(rows = vars(drv), cols = vars(year))

View File

@ -31,9 +31,16 @@ apex(mpg, aes(displ, cty), type = "scatter") %>%
}
)
# Title and subtitle are treated as global
apex(mpg, aes(displ, cty), type = "scatter") %>%
ax_labs(
title = "Facet wrap example",
subtitle = "mpg data from ggplot2"
) %>%
ax_facet_wrap(vars(drv), ncol = 2)
# Multiple variables
apex(mpg, aes(displ, cty), type = "scatter") %>%
ax_facet_wrap(vars(year, drv))

View File

@ -29,9 +29,11 @@
.apexcharter-facet-subtitle {
font-family: Helvetica, Arial, sans-serif;
margin-bottom: 5px;
}
.apexcharter-facet-title {
font-family: Helvetica, Arial, sans-serif;
margin-bottom: 5px;
}

View File

@ -81,9 +81,16 @@ apex(mpg, aes(displ, cty), type = "scatter") \%>\%
}
)
# Title and subtitle are treated as global
apex(mpg, aes(displ, cty), type = "scatter") \%>\%
ax_labs(
title = "Facet wrap example",
subtitle = "mpg data from ggplot2"
) \%>\%
ax_facet_wrap(vars(drv), ncol = 2)
# Multiple variables
apex(mpg, aes(displ, cty), type = "scatter") \%>\%
ax_facet_wrap(vars(year, drv))
@ -180,4 +187,14 @@ apex(mpg, aes(displ, cty), type = "scatter") \%>\%
}
)
# Title and subtitle are treated as global
apex(mpg, aes(displ, cty), type = "scatter") \%>\%
ax_labs(
title = "Facet grid example",
subtitle = "mpg data from ggplot2"
) \%>\%
ax_facet_grid(rows = vars(drv), cols = vars(year))
}

View File

@ -126,6 +126,37 @@ test_that("ax_facet_grid works with row and col", {
})
test_that("globla title and subtitle works", {
ax <- apex(mtcars, aes(disp, wt), type = "scatter") %>%
ax_facet_grid(vars(cyl), vars(carb))
facet <- build_facets(ax)
expect_is(facet, "list")
expect_null(facet$title)
expect_null(facet$subtitle)
ax <- ax %>%
ax_labs(
title = "Facet wrap example",
subtitle = "mpg data from ggplot2"
)
facet <- build_facets(ax)
expect_is(facet, "list")
expect_is(facet$title, "list")
expect_is(facet$subtitle, "list")
TAG <- build_facet_tag(ax)
TAG <- htmltools::doRenderTags(TAG)
expect_true(grepl(pattern = "apexcharter-facet-subtitle", x = TAG))
expect_true(grepl(pattern = "apexcharter-facet-title", x = TAG))
})
test_that("complete_mapdata works", {
cmd <- complete_mapdata(
@ -154,3 +185,14 @@ test_that("complete_data works", {
})
test_that("apexfacetOutput works", {
TAG <- apexfacetOutput("facet")
expect_is(TAG, "shiny.tag.list")
expect_true(length(htmltools::findDependencies(TAG)) > 0)
})

View File

@ -11,3 +11,12 @@ test_that("apex_grid works", {
)
expect_is(ax, "apex_grid")
})
test_that("apexgridOutput works", {
TAG <- apexgridOutput("grid")
expect_is(TAG, "shiny.tag.list")
expect_true(length(htmltools::findDependencies(TAG)) > 0)
})

View File

@ -35,6 +35,7 @@ Current limitations are :
- x-axis always appear for scatter and line charts
- x-axis labels can differ between charts even with fixed scale depending on the width of the chart and the formatter applied to labels
- when scale on an axis is fixed, the chart with the axis don't have the exact same size than the other since the axis take space in the plotting area
- if legend is needed, it will appear on each charts
## Facet wrap
@ -45,6 +46,10 @@ Create a grid of charts according to a variable of the data with `ax_facet_wrap(
data("mpg", package = "ggplot2")
apex(mpg, aes(displ, cty), type = "scatter") %>%
ax_labs(
title = "Facet wrap example",
subtitle = "mpg data from ggplot2"
) %>%
ax_facet_wrap(vars(drv), ncol = 2)
```
@ -78,6 +83,10 @@ Create a matrix of charts defined by row and column faceting variables with `ax_
data("mpg", package = "ggplot2")
apex(mpg, aes(displ, cty), type = "scatter") %>%
ax_labs(
title = "Facet grid example",
subtitle = "mpg data from ggplot2"
) %>%
ax_facet_grid(rows = vars(drv), cols = vars(year))
```