x-axis datetime for column & scatter

This commit is contained in:
pvictor 2020-04-17 08:57:23 +02:00
parent 7dc81c6db6
commit 9c9a277aee
3 changed files with 29 additions and 11 deletions

View File

@ -1,5 +1,5 @@
Package: apexcharter
Version: 0.1.4.920
Version: 0.1.4.930
Title: Create Interactive Chart with the JavaScript 'ApexCharts' Library
Description: Provides an 'htmlwidgets' interface to 'apexcharts.js'.
'Apexcharts' is a modern JavaScript charting library to build interactive charts and visualizations with simple API.

View File

@ -218,12 +218,12 @@ choose_config <- function(type, mapdata) {
switch(
type,
"bar" = config_bar(horizontal = TRUE),
"column" = config_bar(horizontal = FALSE),
"column" = config_bar(horizontal = FALSE, datetime = datetime),
"line" = config_line(datetime = datetime),
"area" = config_line(datetime = datetime),
"spline" = config_line(curve = "smooth", datetime = datetime),
"scatter" = config_scatter(range_x = range_x, range_y = range_y),
"bubble" = config_scatter(range_x = range_x, range_y = range_y),
"scatter" = config_scatter(range_x = range_x, range_y = range_y, datetime = datetime),
"bubble" = config_scatter(range_x = range_x, range_y = range_y, datetime = datetime),
"timeline" = config_timeline(),
list()
)
@ -231,13 +231,16 @@ choose_config <- function(type, mapdata) {
# Config for column & bar charts
config_bar <- function(horizontal = FALSE) {
config_bar <- function(horizontal = FALSE, datetime = FALSE) {
config <- list(
dataLabels = list(enabled = FALSE),
plotOptions = list(
bar = list(
horizontal = horizontal
)
),
tooltip = list(
shared = TRUE
)
)
if (isTRUE(horizontal)) {
@ -248,6 +251,9 @@ config_bar <- function(horizontal = FALSE) {
)
))
}
if (isTRUE(datetime)) {
config$xaxis$type <- "datetime"
}
config
}
@ -269,15 +275,23 @@ config_line <- function(curve = "straight", datetime = FALSE) {
}
config_scatter <- function(range_x, range_y) {
config_scatter <- function(range_x, range_y, datetime = FALSE) {
config <- list(
dataLabels = list(enabled = FALSE),
xaxis = list(
type = "numeric",
min = range_x[1], max = range_x[2]
min = range_x[1], max = range_x[2],
crosshairs = list(
show = TRUE,
stroke = list(dashArray = 0)
)
),
yaxis = list(
min = range_y[1], max = range_y[2]
min = range_y[1], max = range_y[2],
decimalsInFloat = 3,
tooltip = list(
enabled = TRUE
)
),
grid = list(
xaxis = list(
@ -287,6 +301,10 @@ config_scatter <- function(range_x, range_y) {
)
)
)
if (isTRUE(datetime)) {
config$xaxis$type <- "datetime"
}
config
}
config_timeline <- function() {

View File

@ -60,14 +60,14 @@ test_that("choose_config works", {
)
expect_identical(choose_config("bar", mapdata), config_bar(horizontal = TRUE))
expect_identical(choose_config("column", mapdata), config_bar(horizontal = FALSE))
expect_identical(choose_config("column", mapdata), config_bar(horizontal = FALSE, datetime = TRUE))
expect_identical(choose_config("line", mapdata), config_line(datetime = TRUE))
expect_identical(choose_config("area", mapdata), config_line(datetime = TRUE))
expect_identical(choose_config("spline", mapdata), config_line(curve = "smooth", datetime = TRUE))
expect_identical(choose_config("scatter", mapdata), config_scatter(range_num(mapdata$x), range_num(mapdata$y)))
expect_identical(choose_config("bubble", mapdata), config_scatter(range_num(mapdata$x), range_num(mapdata$y)))
expect_identical(choose_config("scatter", mapdata), config_scatter(range_num(mapdata$x), range_num(mapdata$y), datetime = TRUE))
expect_identical(choose_config("bubble", mapdata), config_scatter(range_num(mapdata$x), range_num(mapdata$y), datetime = TRUE))
expect_identical(choose_config("timeline", mapdata), config_timeline())