test facets axis title + others
This commit is contained in:
parent
e76a129702
commit
318690ff06
|
@ -31,4 +31,17 @@ test_that("all apex utilities works", {
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
||||||
|
test_that("ax_nodata works", {
|
||||||
|
empty <- data.frame(
|
||||||
|
var1 = character(0),
|
||||||
|
var2 = numeric(0)
|
||||||
|
)
|
||||||
|
ax <- apex(empty, aes(var1, var2), "column") %>%
|
||||||
|
ax_nodata(
|
||||||
|
text = "Sorry no data to visualize",
|
||||||
|
fontSize = "30px"
|
||||||
|
)
|
||||||
|
expect_is(ax, "apexcharter")
|
||||||
|
expect_is(ax$x$ax_opts$noData, "list")
|
||||||
|
})
|
||||||
|
|
||||||
|
|
|
@ -22,4 +22,15 @@ test_that("ax_colors_manual works", {
|
||||||
expect_is(ax1$x$ax_opts$colors, "list")
|
expect_is(ax1$x$ax_opts$colors, "list")
|
||||||
expect_length(ax1$x$ax_opts$colors, 3)
|
expect_length(ax1$x$ax_opts$colors, 3)
|
||||||
expect_identical(ax1$x$ax_opts$colors, ax2$x$ax_opts$colors)
|
expect_identical(ax1$x$ax_opts$colors, ax2$x$ax_opts$colors)
|
||||||
|
|
||||||
|
|
||||||
|
ax <- apex(
|
||||||
|
data = mtcars,
|
||||||
|
type = "scatter",
|
||||||
|
mapping = aes(x = wt, y = mpg, fill = cyl)
|
||||||
|
)
|
||||||
|
expect_error(ax_colors_manual(ax, c("red", "blue", "green")))
|
||||||
|
expect_error(ax_colors_manual(ax, c(a = "red", b = "blue", "green")))
|
||||||
|
expect_error(ax_colors_manual(apexchart(), list(a = "red", b = "blue", b = "green")))
|
||||||
|
expect_error(ax_colors_manual(list(), list(a = "red", b = "blue", b = "green")))
|
||||||
})
|
})
|
||||||
|
|
|
@ -127,7 +127,7 @@ test_that("ax_facet_grid works with row and col", {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
test_that("globla title and subtitle works", {
|
test_that("global title and subtitle works", {
|
||||||
|
|
||||||
ax <- apex(mtcars, aes(disp, wt), type = "scatter") %>%
|
ax <- apex(mtcars, aes(disp, wt), type = "scatter") %>%
|
||||||
ax_facet_grid(vars(cyl), vars(carb))
|
ax_facet_grid(vars(cyl), vars(carb))
|
||||||
|
@ -139,8 +139,8 @@ test_that("globla title and subtitle works", {
|
||||||
|
|
||||||
ax <- ax %>%
|
ax <- ax %>%
|
||||||
ax_labs(
|
ax_labs(
|
||||||
title = "Facet wrap example",
|
title = "this is a title",
|
||||||
subtitle = "mpg data from ggplot2"
|
subtitle = "this is a subtitle"
|
||||||
)
|
)
|
||||||
|
|
||||||
facet <- build_facets(ax)
|
facet <- build_facets(ax)
|
||||||
|
@ -155,6 +155,61 @@ test_that("globla title and subtitle works", {
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
||||||
|
test_that("axis title works (grid)", {
|
||||||
|
|
||||||
|
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$xaxis_title)
|
||||||
|
expect_null(facet$yaxis_title)
|
||||||
|
|
||||||
|
ax <- ax %>%
|
||||||
|
ax_labs(
|
||||||
|
x = "x axis title",
|
||||||
|
y = "y axis title"
|
||||||
|
)
|
||||||
|
|
||||||
|
facet <- build_facets(ax)
|
||||||
|
expect_is(facet, "list")
|
||||||
|
expect_is(facet$xaxis_title, "list")
|
||||||
|
expect_is(facet$yaxis_title, "list")
|
||||||
|
|
||||||
|
TAG <- build_facet_tag(ax)
|
||||||
|
TAG <- htmltools::doRenderTags(TAG)
|
||||||
|
expect_true(grepl(pattern = "apexcharter-facet-yaxis-title", x = TAG))
|
||||||
|
expect_true(grepl(pattern = "apexcharter-facet-xaxis-title", x = TAG))
|
||||||
|
})
|
||||||
|
|
||||||
|
|
||||||
|
test_that("axis title works (wrap)", {
|
||||||
|
|
||||||
|
ax <- apex(mtcars, aes(disp, wt), type = "scatter") %>%
|
||||||
|
ax_facet_wrap(vars(cyl, carb))
|
||||||
|
|
||||||
|
facet <- build_facets(ax)
|
||||||
|
expect_is(facet, "list")
|
||||||
|
expect_null(facet$xaxis_title)
|
||||||
|
expect_null(facet$yaxis_title)
|
||||||
|
|
||||||
|
ax <- ax %>%
|
||||||
|
ax_labs(
|
||||||
|
x = "x axis title",
|
||||||
|
y = "y axis title"
|
||||||
|
)
|
||||||
|
|
||||||
|
facet <- build_facets(ax)
|
||||||
|
expect_is(facet, "list")
|
||||||
|
expect_is(facet$xaxis_title, "list")
|
||||||
|
expect_is(facet$yaxis_title, "list")
|
||||||
|
|
||||||
|
TAG <- build_facet_tag(ax)
|
||||||
|
TAG <- htmltools::doRenderTags(TAG)
|
||||||
|
expect_true(grepl(pattern = "apexcharter-facet-yaxis-title", x = TAG))
|
||||||
|
expect_true(grepl(pattern = "apexcharter-facet-xaxis-title", x = TAG))
|
||||||
|
})
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
test_that("complete_mapdata works", {
|
test_that("complete_mapdata works", {
|
||||||
|
|
|
@ -0,0 +1,5 @@
|
||||||
|
test_that("multiplication works", {
|
||||||
|
fmt <- format_num("~s")
|
||||||
|
expect_is(fmt, "JS_EVAL")
|
||||||
|
expect_error(format_num(".0f", locale = "DONT_EXIST"))
|
||||||
|
})
|
|
@ -1,3 +1,13 @@
|
||||||
|
test_that("add_line only works with apex and certain type", {
|
||||||
|
|
||||||
|
expect_error(apexchart() %>% add_line(aes(month, temperature)))
|
||||||
|
expect_error(apexchart() %>% add_smooth_line())
|
||||||
|
|
||||||
|
expect_error(apex(mtcars, aes(x = cyl), type = "pie") %>% add_line(aes(month, temperature)))
|
||||||
|
expect_error(apex(mtcars, aes(x = cyl), type = "pie") %>% add_smooth_line())
|
||||||
|
})
|
||||||
|
|
||||||
|
|
||||||
test_that("add_line works with column chart", {
|
test_that("add_line works with column chart", {
|
||||||
|
|
||||||
ax <- apex(climate_paris, aes(month, precipitation), type = "column") %>%
|
ax <- apex(climate_paris, aes(month, precipitation), type = "column") %>%
|
||||||
|
@ -28,5 +38,12 @@ test_that("add_smooth_line works with scatter chart", {
|
||||||
expect_is(ax, "apex")
|
expect_is(ax, "apex")
|
||||||
expect_is(ax$x$ax_opts$series, "list")
|
expect_is(ax$x$ax_opts$series, "list")
|
||||||
expect_length(ax$x$ax_opts$series, 2)
|
expect_length(ax$x$ax_opts$series, 2)
|
||||||
|
|
||||||
|
ax <- apex(cars, aes(speed, dist), type = "scatter") %>%
|
||||||
|
add_smooth_line(model = "lm")
|
||||||
|
|
||||||
|
expect_is(ax, "apex")
|
||||||
|
expect_is(ax$x$ax_opts$series, "list")
|
||||||
|
expect_length(ax$x$ax_opts$series, 2)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
|
@ -7,6 +7,35 @@ test_that("apexchartProxy works", {
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
||||||
|
test_that(".ax_proxy & .ax_proxy2 works", {
|
||||||
|
|
||||||
|
session <- as.environment(list(
|
||||||
|
ns = identity,
|
||||||
|
sendCustomMessage = function(type, message) {
|
||||||
|
session$lastCustomMessage = list(type = type, message = message)
|
||||||
|
}
|
||||||
|
))
|
||||||
|
|
||||||
|
proxy <- apexchartProxy("chart", session = session) %>%
|
||||||
|
.ax_proxy(name = "TEST", a = 1)
|
||||||
|
|
||||||
|
expect_is(session$lastCustomMessage, "list")
|
||||||
|
expect_identical(session$lastCustomMessage$type, "update-apexchart-TEST")
|
||||||
|
expect_identical(session$lastCustomMessage$message$id, "chart")
|
||||||
|
|
||||||
|
expect_error(.ax_proxy(apexchart(), name = "TEST", a = 1))
|
||||||
|
|
||||||
|
proxy <- apexchartProxy("chart", session = session) %>%
|
||||||
|
.ax_proxy2(name = "TEST", list(a = 1))
|
||||||
|
|
||||||
|
expect_is(session$lastCustomMessage, "list")
|
||||||
|
expect_identical(session$lastCustomMessage$type, "update-apexchart-TEST")
|
||||||
|
expect_identical(session$lastCustomMessage$message$id, "chart")
|
||||||
|
|
||||||
|
expect_error(.ax_proxy2(apexchart(), name = "TEST", a = 1))
|
||||||
|
})
|
||||||
|
|
||||||
|
|
||||||
test_that("ax_proxy_series works", {
|
test_that("ax_proxy_series works", {
|
||||||
|
|
||||||
session <- as.environment(list(
|
session <- as.environment(list(
|
||||||
|
|
|
@ -0,0 +1,12 @@
|
||||||
|
test_that("set_tooltip_fixed works", {
|
||||||
|
ax <- apex(
|
||||||
|
data = mtcars,
|
||||||
|
mapping = aes(x = cyl),
|
||||||
|
type = "column"
|
||||||
|
) %>%
|
||||||
|
set_tooltip_fixed()
|
||||||
|
|
||||||
|
expect_is(ax, "apex")
|
||||||
|
expect_is(ax$x$ax_opts$tooltip$fixed, "list")
|
||||||
|
expect_true(ax$x$ax_opts$tooltip$fixed$enabled)
|
||||||
|
})
|
Loading…
Reference in New Issue