-
Notifications
You must be signed in to change notification settings - Fork 150
/
api-hc-extras.R
289 lines (258 loc) · 7.37 KB
/
api-hc-extras.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
#' Adding Color Axis options to highchart objects
#'
#' Function to set the axis color to highcharts objects.
#'
#' @param hc A \code{highchart} \code{htmlwidget} object.
#' @param ... Arguments are defined in \url{http://api.highcharts.com/highmaps#colorAxis}.
#'
#' @examples
#'
#'
#' nyears <- 5
#'
#' df <- expand.grid(seq(12) - 1, seq(nyears) - 1)
#' df$value <- abs(seq(nrow(df)) + 10 * rnorm(nrow(df))) + 10
#' df$value <- round(df$value, 2)
#' ds <- list_parse2(df)
#'
#'
#' hc <- highchart() %>%
#' hc_chart(type = "heatmap") %>%
#' hc_title(text = "Simulated values by years and months") %>%
#' hc_xAxis(categories = month.abb) %>%
#' hc_yAxis(categories = 2016 - nyears + seq(nyears)) %>%
#' hc_add_series(name = "value", data = ds)
#'
#' hc_colorAxis(hc, minColor = "#FFFFFF", maxColor = "#434348")
#'
#' hc_colorAxis(hc, minColor = "#FFFFFF", maxColor = "#434348",
#' type = "logarithmic")
#'
#'
#' require("viridisLite")
#'
#' n <- 4
#' stops <- data.frame(q = 0:n/n,
#' c = substring(viridis(n + 1), 0, 7),
#' stringsAsFactors = FALSE)
#' stops <- list_parse2(stops)
#'
#' hc_colorAxis(hc, stops = stops, max = 75)
#'
#' @export
hc_colorAxis <- function(hc, ...) {
.hc_opt(hc, "colorAxis", ...)
}
#' Drilldown options for higcharts objects
#'
#' Options for drill down, the concept of inspecting increasingly high
#' resolution data through clicking on chart items like columns or pie slices.
#'
#' @param hc A \code{highchart} \code{htmlwidget} object.
#' @param ... Arguments defined in \url{http://api.highcharts.com/highcharts#drilldown}.
#'
#' @examples
#'
#' library("dplyr")
#' library("purrr")
#'
#' df <- data_frame(
#' name = c("Animals", "Fruits", "Cars"),
#' y = c(5, 2, 4),
#' drilldown = tolower(name)
#' )
#'
#' df
#'
#' ds <- list_parse(df)
#' names(ds) <- NULL
#' str(ds)
#'
#' hc <- highchart() %>%
#' hc_chart(type = "column") %>%
#' hc_title(text = "Basic drilldown") %>%
#' hc_xAxis(type = "category") %>%
#' hc_legend(enabled = FALSE) %>%
#' hc_plotOptions(
#' series = list(
#' boderWidth = 0,
#' dataLabels = list(enabled = TRUE)
#' )
#' ) %>%
#' hc_add_series(
#' name = "Things",
#' colorByPoint = TRUE,
#' data = ds
#' )
#'
#' dfan <- data_frame(
#' name = c("Cats", "Dogs", "Cows", "Sheep", "Pigs"),
#' value = c(4, 3, 1, 2, 1)
#' )
#'
#' dffru <- data_frame(
#' name = c("Apple", "Organes"),
#' value = c(4, 2)
#' )
#'
#' dfcar <- data_frame(
#' name = c("Toyota", "Opel", "Volkswage"),
#' value = c(4, 2, 2)
#' )
#'
#' second_el_to_numeric <- function(ls){
#'
#' map(ls, function(x){
#' x[[2]] <- as.numeric(x[[2]])
#' x
#' })
#'
#' }
#'
#' dsan <- second_el_to_numeric(list_parse2(dfan))
#'
#' dsfru <- second_el_to_numeric(list_parse2(dffru))
#'
#' dscar <- second_el_to_numeric(list_parse2(dfcar))
#'
#'
#' hc <- hc %>%
#' hc_drilldown(
#' allowPointDrilldown = TRUE,
#' series = list(
#' list(
#' id = "animals",
#' data = dsan
#' ),
#' list(
#' id = "fruits",
#' data = dsfru
#' ),
#' list(
#' id = "cars",
#' data = dscar
#' )
#' )
#' )
#'
#' hc
#'
#' @export
hc_drilldown <- function(hc, ...) {
.hc_opt(hc, "drilldown", ...)
}
#' Adding scrollbar options to highstock objects
#'
#' Options regarding the scrollbar which is a means of panning
#' over the X axis of a chart.
#'
#' @param hc A \code{highchart} \code{htmlwidget} object.
#' @param ... Arguments defined in \url{http://api.highcharts.com/highstock#scrollbar}.
#'
#' @export
hc_scrollbar <- function(hc, ...) {
.hc_opt(hc, "scrollbar", ...)
}
#' Adding navigator options to highstock charts
#'
#' Options regarding the navigator: The miniseries below chart
#' in a highstock chart.
#'
#' @param hc A \code{highchart} \code{htmlwidget} object.
#' @param ... Arguments defined in \url{http://api.highcharts.com/highstock#navigator}.
#'
#' @export
hc_navigator <- function(hc, ...) {
.hc_opt(hc, "navigator", ...)
}
#' Adding scrollbar options to highstock charts
#'
#' Options to edit the range selector which is The range selector is a tool
#' for selecting ranges to display within the chart. It provides buttons
#' to select preconfigured ranges in the chart, like 1 day, 1 week, 1 month
#' etc. It also provides input boxes where min and max dates can be manually
#' input.
#'
#' @param hc A \code{highchart} \code{htmlwidget} object.
#' @param ... Arguments defined in \url{http://api.highcharts.com/highstock#rangeSelector}.
#'
#' @export
hc_rangeSelector <- function(hc, ...) {
.hc_opt(hc, "rangeSelector", ...)
}
#' Adding mapNavigation options to highmaps charts
#'
#' Options regarding the mapNavigation: A collection of options for zooming
#' and panning in a map.
#'
#' @param hc A \code{highchart} \code{htmlwidget} object.
#' @param ... Arguments defined in \url{http://api.highcharts.com/highmaps#mapNavigation}.
#'
#' @export
hc_mapNavigation <- function(hc, ...) {
.hc_opt(hc, "mapNavigation", ...)
}
#' Adding patterns to be used in highcharts series
#'
#' Helper function to use the fill patter plugin http://www.highcharts.com/plugin-registry/single/9/Pattern-Fill.
#'
#' @param hc A \code{highchart} \code{htmlwidget} object.
#' @param ... Arguments defined in \url{http://www.highcharts.com/plugin-registry/single/9/Pattern-Fill}.
#'
#' @export
hc_defs <- function(hc, ...) {
.hc_opt(hc, "defs", ...)
}
#' Adding annotations to highcharts objects
#'
#' Helper function to add annotations to highcharts library.
#'
#' @param hc A \code{highchart} \code{htmlwidget} object.
#' @param ... Arguments defined in \url{http://www.highcharts.com/plugin-registry/single/17/Annotations}.
#'
#' @export
hc_annotations <- function(hc, ...) {
.hc_opt(hc, "annotations", ...)
}
#' Adding annotations to highcharts objects
#'
#' Applies only to polar charts and angular gauges. This configuration object
#' holds general options for the combined X and Y axes set. Each xAxis or
#' yAxis can reference the pane by index.
#'
#' @param hc A \code{highchart} \code{htmlwidget} object.
#' @param ... Arguments defined in \url{http://api.highcharts.com/highcharts#pane}.
#'
#' @export
hc_pane <- function(hc, ...) {
.hc_opt(hc, "pane", ...)
}
#' Adding options to Motion options to highcharts objects
#'
#' The Motion Highcharts Plugin adds an interactive HTML5 player
#' to any Highcharts chart (Highcharts, Highmaps and Highstock).
#'
#' @param hc A \code{highchart} \code{htmlwidget} object.
#' @param ... Arguments defined in \url{https://github.com/larsac07/Motion-Highcharts-Plugin/wiki}.
#'
#' @export
hc_motion <- function(hc, ...) {
.hc_opt(hc, "motion", ...)
}
#' Setting elementId
#'
#' Function to modify the \code{id} for the container.
#'
#' @param hc A \code{highchart} \code{htmlwidget} object.
#' @param id A string
#'
#' @examples
#'
#' hchart(rnorm(10)) %>%
#' hc_elementId("newid")
#'
#' @export
hc_elementId <- function(hc, id = NULL) {
hc$elementId <- as.character(id)
hc
}