shosaco / vistime
Showing 4 of 12 files from the diff.

@@ -10,9 +10,11 @@
Loading
10 10
#' @param title plot title
11 11
#' @param show_labels logical
12 12
#' @param background_lines interval of gray background lines
13 -
#' @importFrom assertthat is.string
14 -
#' @importFrom assertthat is.flag
15 -
#' @importFrom assertthat assert_that
13 +
#' @importFrom assertive.types assert_is_a_string
14 +
#' @importFrom assertive.types assert_is_data.frame
15 +
#' @importFrom assertive.types assert_is_a_number
16 +
#' @importFrom assertive.types assert_is_logical
17 +
#' @importFrom assertive.types assert_is_posixct
16 18
#'
17 19
#' @return list of the data frame and column arguments, or an error
18 20
#' @keywords internal
@@ -77,23 +79,22 @@
Loading
77 79
  if(length(.dots) > 0) warning("The following unexpected arguments were ignored: ",
78 80
                                paste(names(.dots), collapse = ", "))
79 81
80 -
  assert_that(is.string(col.start))
81 -
  assert_that(is.string(col.end))
82 -
  assert_that(is.string(col.event))
83 -
  assert_that(is.string(col.group))
84 -
  if(!is.null(col.tooltip)) assert_that(is.string(col.tooltip))
85 -
  assert_that(is.flag(optimize_y))
82 +
  assert_is_a_string(col.start)
83 +
  assert_is_a_string(col.end)
84 +
  assert_is_a_string(col.event)
85 +
  assert_is_a_string(col.group)
86 +
  if(!is.null(col.tooltip)) assert_is_a_string(col.tooltip)
87 +
  assert_is_logical(optimize_y)
86 88
87 89
  # missing if called from vistime_data
88 -
  if(!missing(linewidth) && !is.null(linewidth)) assert_that(is.numeric(linewidth))
89 -
  if(!missing(title) && !is.null(title)) assert_that(is.string(title))
90 -
  if(!missing(show_labels)) assert_that(is.flag(show_labels))
91 -
  if(!missing(background_lines) && !is.null(background_lines)) assert_that(is.numeric(background_lines))
90 +
  if(!missing(linewidth) && !is.null(linewidth)) assert_is_a_number(linewidth)
91 +
  if(!missing(title) && !is.null(title)) assert_is_a_string(title)
92 +
  if(!missing(show_labels)) assert_is_logical(show_labels)
93 +
  if(!missing(background_lines) && !is.null(background_lines)) assert_is_a_number(background_lines)
92 94
93 -
  if ("try-error" %in% class(try(as.data.frame(data), silent = T)))
94 -
    stop(paste("Expected an input data frame, but encountered", class(data)[1]))
95 +
  df <- tryCatch(as.data.frame(data, stringsAsFactors = F), error = function(e) assert_is_data.frame(data))
96 +
  assert_is_data.frame(df)
95 97
96 -
  df <- as.data.frame(data, stringsAsFactors = F)
97 98
98 99
  if (!col.start %in% names(df))
99 100
    stop("Column '", col.start, "' not found in data")
@@ -101,8 +102,8 @@
Loading
101 102
  if (sum(!is.na(df[[col.start]])) == 0)
102 103
    stop(paste0("error in column '", col.start, "': Please provide at least one point in time"))
103 104
104 -
  if ("try-error" %in% class(try(as.POSIXct(df[[col.start]]), silent = T)))
105 -
    stop("date format error: please make sure column '", col.start, "' can be converted to POSIXct type")
105 +
  df[[col.start]] <- tryCatch(as.POSIXct(df[[col.start]]), error = function(e) assert_is_posixct(df[[col.start]]))
106 +
  assert_is_posixct(df[[col.start]])
106 107
107 108
  if (!col.event %in% names(df)){
108 109
    message("Column '", col.event, "' not found in data. Defaulting to col.event='", col.start, "'")

@@ -1,6 +1,6 @@
Loading
1 1
#' Create a Timeline rendered by Plotly
2 2
#'
3 -
#' Provide a data frame with event data to create a visual and interactive timeline plot.
3 +
#' Provide a data frame with event data to create a visual and interactive timeline plot rendered by Plotly.
4 4
#' Simplest drawable dataframe can have columns `event` and `start`.
5 5
#'
6 6
#' @param data \code{data.frame} that contains the data to be visualized
@@ -32,9 +32,9 @@
Loading
32 32
#' @param background_lines (optional, integer) the number of vertical lines to draw in the
33 33
#'   background to demonstrate structure (default: 10). Less means more memory-efficient plot.
34 34
#' @param ... for deprecated arguments up to vistime 1.1.0 (like events, colors, ...)
35 +
#' @seealso Functions \code{?hc_vistime} and \code{?gg_vistime} for different charting engines (Highcharts and ggplot2).
35 36
#' @export
36 37
#' @return \code{vistime} returns an object of class \code{plotly} and \code{htmlwidget}.
37 -
#'  See `gg_vistime` for the static `ggplot` version.
38 38
#' @examples
39 39
#' # presidents and vice presidents
40 40
#' pres <- data.frame(

@@ -1,6 +1,6 @@
Loading
1 1
#' Create a Timeline rendered by Highcharts.js
2 2
#'
3 -
#' Provide a data frame with event data to create a visual and interactive timeline plot.
3 +
#' Provide a data frame with event data to create a visual and interactive timeline plot rendered by Highcharts.
4 4
#' Simplest drawable dataframe can have columns `event` and `start`.
5 5
#'
6 6
#' @param data \code{data.frame} that contains the data to be visualized
@@ -25,6 +25,7 @@
Loading
25 25
#' @param show_labels (optional, boolean) choose whether or not event labels shall be
26 26
#'   visible. Default: \code{TRUE}.
27 27
#' @param ... for deprecated arguments up to vistime 1.1.0 (like events, colors, ...)
28 +
#' @seealso Functions \code{?vistime} and \code{?gg_vistime} for different charting engines (Plotly and ggplot2).
28 29
#' @export
29 30
#' @return \code{hc_vistime} returns an object of class \code{highchart} and \code{htmlwiget}
30 31
#' @examples
@@ -38,6 +39,22 @@
Loading
38 39
#' )
39 40
#'
40 41
#' hc_vistime(pres, col.event = "Position", col.group = "Name", title = "Presidents of the USA")
42 +
#' #'
43 +
#' \dontrun{
44 +
#' # ------ It is possible to change all attributes of the timeline using highcharter::hc_*() functions:
45 +
#' data <- read.csv(text="event,start,end
46 +
#'                        Phase 1,2020-12-15,2020-12-24
47 +
#'                        Phase 2,2020-12-23,2020-12-29
48 +
#'                        Phase 3,2020-12-28,2021-01-06
49 +
#'                        Phase 4,2021-01-06,2021-02-02")
50 +
#'
51 +
#' library(highcharter)
52 +
#' p <- hc_vistime(data, optimize_y = T, col.group = "event", title = "Highcharts customization example")
53 +
#' p %>% hc_title(style = list(fontSize=30)) %>%
54 +
#'       hc_yAxis(labels = list(style = list(fontSize=30, color="violet"))) %>%
55 +
#'       hc_xAxis(labels = list(style = list(fontSize=30, color="red"), rotation=30)) %>%
56 +
#'       hc_chart(backgroundColor = "lightgreen")
57 +
#' }
41 58
42 59
43 60
hc_vistime <- function(data,

@@ -1,6 +1,6 @@
Loading
1 -
#' Create a Timeline rendered by ggplot
1 +
#' Create a Timeline rendered by ggplot2
2 2
#'
3 -
#' Provide a data frame with event data to create a static timeline plot.
3 +
#' Provide a data frame with event data to create a static timeline plot created by ggplot2.
4 4
#' Simplest drawable dataframe can have columns `event` and `start`.
5 5
#'
6 6
#' @param data \code{data.frame} that contains the data to be visualized
@@ -28,6 +28,7 @@
Loading
28 28
#'   visible. Default: \code{TRUE}.
29 29
#' @param background_lines (optional, integer) the number of vertical lines to draw in the background to demonstrate structure (default: heuristic).
30 30
#' @param ... for deprecated arguments up to vistime 1.1.0 (like events, colors, ...)
31 +
#' @seealso Functions \code{?vistime} and \code{?hc_vistime} for different charting engines (Plotly and Highcharts).
31 32
#' @export
32 33
#' @return \code{gg_vistime} returns an object of class \code{gg} and \code{ggplot}.
33 34
#' @examples
Files Coverage
R 86.43%
Project Totals (12 files) 86.43%
Sunburst
The inner-most circle is the entire project, moving away from the center are folders then, finally, a single file. The size and color of each slice is representing the number of statements and the coverage, respectively.
Icicle
The top section represents the entire project. Proceeding with folders and finally individual files. The size and color of each slice is representing the number of statements and the coverage, respectively.
Grid
Each block represents a single file in the project. The size and color of each block is represented by the number of statements and the coverage, respectively.
Loading