-
Notifications
You must be signed in to change notification settings - Fork 149
/
Copy pathhighcharts-api.R
1248 lines (1158 loc) · 32.4 KB
/
highcharts-api.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
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
# Generated by 'dev/generate-highcharts-api.R'
# Generated in 2022-08-11 22:55:18
#
#' Annotations options for highcharter objects
#'
#' A basic type of an annotation. It allows to add custom labels
#' or shapes. The items can be tied to points, axis coordinates
#' or chart pixel coordinates.
#'
#' @param hc A `highchart` `htmlwidget` object.
#' @param ... Arguments defined in \url{https://api.highcharts.com/highcharts/annotations}.
#'
#' @examples
#'
#' # Ex 1
#' highchart() |>
#' hc_add_series(
#' data = c(29.9, 71.5, 106.4, 129.2, 144.0, 176.0, 135.6, 148.5, 216.4, 194.1, 95.6, 54.4)
#' ) |>
#' hc_xAxis(
#' tickInterval = 0.5,
#' gridLineWidth = 1
#' ) |>
#' hc_annotations(
#' list(
#' labels =
#' list(
#' list(
#' point = list(x = 3, y = 129.2, xAxis = 0, yAxis = 0),
#' text = "x: {x}<br/>y: {y}"
#' ),
#' list(
#' point = list(x = 9, y = 194.1, xAxis = 0, yAxis = 0),
#' text = "x: {x}<br/>y: {y}"
#' ),
#' list(
#' point = list(x = 5, y = 100, xAxis = 0),
#' text = "x: {x}<br/>y: {point.plotY} px"
#' ),
#' list(
#' point = list(x = 0, y = 0),
#' text = "x: {point.plotX} px<br/>y: {point.plotY} px"
#' )
#' )
#' )
#' )
#'
#' # Ex 2
#' df <- data.frame(
#' x = 1:10,
#' y = 1:10
#' )
#'
#' highchart() |>
#' hc_add_series(data = df, hcaes(x = x, y = y), type = "area") |>
#' hc_annotations(
#' list(
#' labels = list(
#' list(point = list(x = 5, y = 5, xAxis = 0, yAxis = 0), text = "Middle"),
#' list(point = list(x = 1, y = 1, xAxis = 0, yAxis = 0), text = "Start")
#' )
#' )
#' )
#'
#' @export
hc_annotations <- function(hc, ...) {
.hc_opt(hc, "annotations", ...)
}
#' Boost options for highcharter objects
#'
#' Options for the Boost module. The Boost module allows certain series types
#' to be rendered by WebGL instead of the default SVG. This allows hundreds of
#' thousands of data points to be rendered in milliseconds. In addition to the
#' WebGL rendering it saves time by skipping processing and inspection of the
#' data wherever possible. This introduces some limitations to what features are
#' available in boost mode. See the docs for
#' details.
#' In addition to the global boost option, each series has a
#' boostThreshold that defines when the
#' boost should kick in.
#' Requires the modules/boost.js module.
#'
#' @param hc A `highchart` `htmlwidget` object.
#' @param ... Arguments defined in \url{https://api.highcharts.com/highcharts/boost}.
#'
#' @examples
#'
#' # # Ex 1
#' # options(highcharter.rjson = FALSE)
#' #
#' # n <- 50000
#' #
#' # x <- sin(4*2*pi*seq(n)/n) + rnorm(n)/10
#' #
#' # x <- round(x, 3)
#' #
#' # plot(x)
#' #
#' # hc1 <- highchart() |>
#' # hc_chart(zoomType = "x") |>
#' # hc_add_series(data = x) |>
#' # hc_title(text = "No boost") |>
#' # hc_boost(
#' # enabled = FALSE # Default
#' # )
#' #
#' # hc1
#' #
#' # # Boost is a stripped-down renderer-in-a-module for Highcharts. It bypasses
#' # # some of the standard Highcharts features (such as animation), and focuses
#' # # on pushing as many points as possible as quickly as possible.
#' #
#' # hc2 <- highchart() |>
#' # hc_chart(zoomType = "x") |>
#' # hc_add_series(data = x) |>
#' # hc_title(text = "With boost") |>
#' # hc_boost(enabled = TRUE)
#' #
#' # hc2
#' #
#' #
#' # # # Ex 2
#' # # library(MASS)
#' # #
#' # # n <- 20000
#' # #
#' # # sigma <- matrix(c(10,3,3,2),2,2)
#' # # sigma
#' # #
#' # # mvr <- round(mvrnorm(n, rep(c(0, 0)), sigma), 2)
#' # #
#' # # vx <- ceiling(1+abs(max(mvr[, 1])))
#' # # vy <- ceiling(1+abs(max(mvr[, 2])))
#' # #
#' # # # unnamed list
#' # # ds <- list_parse2(as.data.frame(mvr))
#' # #
#' # # highchart() |>
#' # # hc_chart(zoomType = "xy") |>
#' # # hc_xAxis(min = -vx, max = vx) |>
#' # # hc_yAxis(min = -vy, max = vy) |>
#' # # hc_add_series(
#' # # data = ds, #list
#' # # type = "scatter",
#' # # name = "A lot of points!",
#' # # color = 'rgba(0,0,0,0.1)',
#' # # marker = list(radius = 2)
#' # # ) |>
#' # # hc_boost(
#' # # enabled = TRUE
#' # # )
#' # #
#' # # dat <- as.data.frame(mvr)
#' # # names(dat) <- c("x", "y")
#' # #
#' # # highchart() |>
#' # # hc_chart(zoomType = "xy") |>
#' # # hc_xAxis(min = -vx, max = vx) |>
#' # # hc_yAxis(min = -vy, max = vy) |>
#' # # hc_add_series(
#' # # data = dat,
#' # # type = "scatter",
#' # # hcaes(x, y),
#' # # name = "A lot of points!",
#' # # color = 'rgba(0,0,0,0.1)',
#' # # marker = list(radius = 2)
#' # # ) |>
#' # # hc_boost(enabled = TRUE)
#' # #
#' # # # Ex3
#' # # N <- 1000000
#' # # n <- 5
#' # # s <- seq(n)
#' # # s <- s/(max(s) + min(s))
#' # # s <- round(s, 2)
#' # #
#' # # series <- s |>
#' # # purrr::map(~ stats::arima.sim(round(N/n), model = list(ar = .x)) + .x * n * 20) |>
#' # # purrr::map(as.vector) |>
#' # # purrr::map(round, 2) |>
#' # # purrr::map(~ list(data = .x))
#' # #
#' # # highchart() |>
#' # # hc_add_series_list(series) |>
#' # # hc_chart(zoomType = "x") |>
#' # # hc_boost(enabled = TRUE)
#'
#' @export
hc_boost <- function(hc, ...) {
.hc_opt(hc, "boost", ...)
}
#' Caption options for highcharter objects
#'
#' The chart's caption, which will render below the chart and will be part
#' of exported charts. The caption can be updated after chart initialization
#' through the Chart.update or Chart.caption.update methods.
#'
#' @param hc A `highchart` `htmlwidget` object.
#' @param ... Arguments defined in \url{https://api.highcharts.com/highcharts/caption}.
#'
#' @examples
#'
#' highchart() |>
#' hc_title(text= "Chart with a caption") |>
#' hc_subtitle(text= "This is the subtitle") |>
#' hc_xAxis(categories = c("Apples", "Pears", "Banana", "Orange")) |>
#' hc_add_series(
#' data = c(1, 4, 3, 5),
#' type = "column",
#' name = "Fruits"
#' ) |>
#' hc_caption(
#' text = "<b>The caption renders in the bottom, and is part of the exported
#' chart.</b><br><em>Lorem ipsum dolor sit amet, consectetur adipiscing elit,
#' sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim
#' ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip
#' ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate
#' velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat
#' cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est
#' laborum.</em>'"
#' )
#'
#' @export
hc_caption <- function(hc, ...) {
.hc_opt(hc, "caption", ...)
}
#' Chart options for highcharter objects
#'
#' General options for the chart.
#'
#' @param hc A `highchart` `htmlwidget` object.
#' @param ... Arguments defined in \url{https://api.highcharts.com/highcharts/chart}.
#'
#' @examples
#'
#' hc <- highchart() |>
#' hc_xAxis(categories = month.abb) |>
#' hc_add_series(name = "Tokyo", data = sample(1:12)) |>
#' hc_add_series(name = "London", data = sample(1:12) + 10)
#'
#' hc
#'
#' hc |>
#' hc_chart(
#' type = "column",
#' options3d = list(enabled = TRUE, beta = 15, alpha = 15)
#' )
#'
#'
#' hc |>
#' hc_chart(
#' borderColor = "#EBBA95",
#' borderRadius = 10,
#' borderWidth = 2,
#' backgroundColor = list(
#' linearGradient = c(0, 0, 500, 500),
#' stops = list(
#' list(0, 'rgb(255, 255, 255)'),
#' list(1, 'rgb(200, 200, 255)')
#' )
#' )
#' )
#'
#'
#' @export
hc_chart <- function(hc, ...) {
.hc_opt(hc, "chart", ...)
}
#' Coloraxis options for highcharter objects
#'
#' A color axis for series. Visually, the color
#' axis will appear as a gradient or as separate items inside the
#' legend, depending on whether the axis is scalar or based on data
#' classes.
#' For supported color formats, see the
#' docs article about colors.
#' A scalar color axis is represented by a gradient. The colors either
#' range between the minColor and the
#' maxColor, or for more fine grained control the
#' colors can be defined in stops. Often times, the
#' color axis needs to be adjusted to get the right color spread for the
#' data. In addition to stops, consider using a logarithmic
#' axis type, or setting min and
#' max to avoid the colors being determined by
#' outliers.
#' When dataClasses are used, the ranges are
#' subdivided into separate classes like categories based on their
#' values. This can be used for ranges between two values, but also for
#' a true category. However, when your data is categorized, it may be as
#' convenient to add each category to a separate series.
#' Color axis does not work with: sankey, sunburst, dependencywheel,
#' networkgraph, wordcloud, venn, gauge and solidgauge series
#' types.
#' Since v7.2.0 colorAxis can also be an array of options objects.
#' See the Axis object for
#' programmatic access to the axis.
#'
#' @param hc A `highchart` `htmlwidget` object.
#' @param ... Arguments defined in \url{https://api.highcharts.com/highcharts/colorAxis}.
#'
#' @examples
#'
#' library(dplyr)
#'
#' data(mpg, package = "ggplot2")
#'
#' mpgman2 <- mpg |>
#' group_by(manufacturer, year) |>
#' dplyr::summarise(
#' n = dplyr::n(),
#' displ = mean(displ),
#' .groups = "drop"
#' )
#'
#' mpgman2
#'
#' hchart(
#' mpgman2, "column", hcaes(x = manufacturer, y = n, group = year),
#' colorKey = "displ",
#' # color = c("#FCA50A", "#FCFFA4"),
#' name = c("Year 1999", "Year 2008")
#' ) |>
#' hc_colorAxis(min = 0, max = 5)
#'
#'
#' # defaults to yAxis
#' hchart(iris, "point", hcaes(Sepal.Length, Sepal.Width)) |>
#' hc_colorAxis(
#' minColor = "red",
#' maxColor = "blue"
#' )
#'
#' # Ex2
#' n <- 5
#'
#' stops <- data.frame(
#' q = 0:n/n,
#' c = c("#440154", "#414487", "#2A788E", "#22A884", "#7AD151", "#FDE725"),
#' stringsAsFactors = FALSE
#' )
#'
#' stops <- list_parse2(stops)
#'
#' M <- round(matrix(rnorm(50*50), ncol = 50), 2)
#'
#' hchart(M) |>
#' hc_colorAxis(stops = stops)
#'
#' # Ex3
#' hchart(volcano) |>
#' hc_colorAxis(stops = stops, max = 200)
#'
#' @export
hc_colorAxis <- function(hc, ...) {
.hc_opt(hc, "colorAxis", ...)
}
#' Colors options for highcharter objects
#'
#' An array containing the default colors for the chart's series. When all
#' colors are used, new colors are pulled from the start again.
#'
#' @param hc A `highchart` `htmlwidget` object.
#' @param colors A vector of colors.
#'
#' @examples
#'
#' library(viridisLite)
#'
#' cols <- viridis(3)
#' cols <- substr(cols, 0, 7)
#'
#' highchart() |>
#' hc_add_series(data = sample(1:12)) |>
#' hc_add_series(data = sample(1:12) + 10) |>
#' hc_add_series(data = sample(1:12) + 20) |>
#' hc_colors(cols)
#'
#' @export
hc_colors <- function(hc, colors) {
assertthat::assert_that(is.vector(colors))
if (length(colors) == 1)
colors <- list(colors)
hc$x$hc_opts$colors <- colors
hc
}
#' Credits options for highcharter objects
#'
#' Highchart by default puts a credits label in the lower right corner
#' of the chart. This can be changed using these options.
#'
#' @param hc A `highchart` `htmlwidget` object.
#' @param ... Arguments defined in \url{https://api.highcharts.com/highcharts/credits}.
#'
#' @examples
#'
#' highchart() |>
#' hc_xAxis(categories = citytemp$month) |>
#' hc_add_series(name = "Tokyo", data = sample(1:12)) |>
#' hc_credits(
#' enabled = TRUE,
#' text = "htmlwidgets.org",
#' href = "http://www.htmlwidgets.org/"
#' )
#'
#' @export
hc_credits <- function(hc, ...) {
.hc_opt(hc, "credits", ...)
}
#' Drilldown options for highcharter objects
#'
#' Options for drill down, the concept of inspecting increasingly high
#' resolution data through clicking on chart items like columns or pie slices.
#' The drilldown feature requires the drilldown.js file to be loaded,
#' found in the modules directory of the download package, or online at
#' code.highcharts.com/modules/drilldown.js.
#'
#' @param hc A `highchart` `htmlwidget` object.
#' @param ... Arguments defined in \url{https://api.highcharts.com/highcharts/drilldown}.
#'
#' @examples
#'
#' library(highcharter)
#' library(dplyr)
#' library(purrr)
#'
#' df <- tibble(
#' name = c("Animals", "Fruits"),
#' y = c(5, 2),
#' drilldown = tolower(name)
#' )
#'
#' df
#'
#' hc <- highchart() |>
#' 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(
#' data = df,
#' type = "column",
#' hcaes(name = name, y = y),
#' name = "Things",
#' colorByPoint = TRUE
#' )
#'
#' 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)
#' )
#'
#'
#' dsan <- list_parse2(dfan)
#'
#' dsfru <- list_parse2(dffru)
#'
#' hc <- hc |>
#' hc_drilldown(
#' allowPointDrilldown = TRUE,
#' series = list(
#' list(
#' id = "animals",
#' data = dsan
#' ),
#' list(
#' id = "fruits",
#' data = dsfru
#' )
#' )
#' )
#'
#' hc
#'
#'
#'
#' @export
hc_drilldown <- function(hc, ...) {
.hc_opt(hc, "drilldown", ...)
}
#' Exporting options for highcharter objects
#'
#' Options for the exporting module. For an overview on the matter, see
#' the docs.
#'
#' @param hc A `highchart` `htmlwidget` object.
#' @param ... Arguments defined in \url{https://api.highcharts.com/highcharts/exporting}.
#'
#' @examples
#'
#' highchart() |>
#' hc_xAxis(categories = month.abb) |>
#' hc_add_series(name = "Tokyo", data = sample(1:12)) |>
#' hc_exporting(
#' enabled = TRUE, # always enabled
#' filename = "custom-file-name"
#' )
#'
#' @export
hc_exporting <- function(hc, ...) {
.hc_opt(hc, "exporting", ...)
}
#' Labels options for highcharter objects
#'
#' HTML labels that can be positioned anywhere in the chart area.
#' This option is deprecated since v7.1.2. Instead, use
#' annotations that support labels.
#'
#' @param hc A `highchart` `htmlwidget` object.
#' @param ... Arguments defined in \url{https://api.highcharts.com/highcharts/labels}.
#'
#' @examples
#'
#' highchart() |>
#' hc_add_series(data = sample(1:12)) |>
#' hc_labels(
#' items = list(
#' list(
#' html = "<p>Some <b>important</b><br>text</p>" ,
#' style = list(
#' left = "150%",
#' top = "150%"
#' )
#' )
#' )
#' )
#'
#'
#' @export
hc_labels <- function(hc, ...) {
.hc_opt(hc, "labels", ...)
}
#' Legend options for highcharter objects
#'
#' The legend is a box containing a symbol and name for each series
#' item or point item in the chart. Each series (or points in case
#' of pie charts) is represented by a symbol and its name in the legend.
#' It is possible to override the symbol creator function and create
#' custom legend symbols.
#'
#' A Highmaps legend by default contains one legend item per series, but if
#' a colorAxis is defined, the axis will be displayed in the legend.
#' Either as a gradient, or as multiple legend items for dataClasses.
#'
#' @param hc A `highchart` `htmlwidget` object.
#' @param ... Arguments defined in \url{https://api.highcharts.com/highcharts/legend}.
#'
#' @examples
#'
#' highchart() |>
#' hc_xAxis(categories = month.abb) |>
#' hc_add_series(name = "Tokyo", data = sample(1:12)) |>
#' hc_add_series(name = "London", data = sample(1:12) + 10) |>
#' hc_add_series(name = "Other City", data = sample(1:12) + 20) |>
#' hc_legend(
#' align = "left",
#' verticalAlign = "top",
#' layout = "vertical",
#' x = 0,
#' y = 100
#' )
#'
#' @export
hc_legend <- function(hc, ...) {
.hc_opt(hc, "legend", ...)
}
#' Loading options for highcharter objects
#'
#' The loading options control the appearance of the loading screen
#' that covers the plot area on chart operations. This screen only
#' appears after an explicit call to chart.showLoading(). It is a
#' utility for developers to communicate to the end user that something
#' is going on, for example while retrieving new data via an XHR connection.
#' The "Loading..." text itself is not part of this configuration
#' object, but part of the lang object.
#'
#' @param hc A `highchart` `htmlwidget` object.
#' @param ... Arguments defined in \url{https://api.highcharts.com/highcharts/loading}.
#'
#' @examples
#'
#' highcharts_demo() |>
#' hc_loading(
#' hideDuration = 1000,
#' showDuration = 1000
#' )
#'
#' @export
hc_loading <- function(hc, ...) {
.hc_opt(hc, "loading", ...)
}
#' Pane options for highcharter objects
#'
#' The pane serves as a container for axes and backgrounds for circular
#' gauges and polar charts.
#'
#' @param hc A `highchart` `htmlwidget` object.
#' @param ... Arguments defined in \url{https://api.highcharts.com/highcharts/pane}.
#'
#' @examples
#'
#' highchart() |>
#' hc_chart(
#' type = "gauge",
#' plotBackgroundColor = NULL,
#' plotBackgroundImage = NULL,
#' plotBorderWidth = 0,
#' plotShadow = FALSE
#' ) |>
#' hc_title(
#' text = "Speedometer"
#' ) |>
#' hc_pane(
#' startAngle = -150,
#' endAngle = 150,
#' background = list(list(
#' backgroundColor = list(
#' linearGradient = list( x1 = 0, y1 = 0, x2 = 0, y2 = 1),
#' stops = list(
#' list(0, "#FFF"),
#' list(1, "#333")
#' )
#' ),
#' borderWidth = 0,
#' outerRadius = "109%"
#' ), list(
#' backgroundColor = list(
#' linearGradient = list( x1 = 0, y1 = 0, x2 = 0, y2 = 1),
#' stops = list(
#' list(0, "#333"),
#' list(1, "#FFF")
#' )
#' ),
#' borderWidth = 1,
#' outerRadius = "107%"
#' ), list(
#' # default background
#' ), list(
#' backgroundColor = "#DDD",
#' borderWidth = 0,
#' outerRadius = "105%",
#' innerRadius = "103%"
#' ))
#' ) |>
#' hc_add_series(
#' data = list(80), name = "speed", tooltip = list(valueSuffix = " km/h")
#' ) |>
#'
#'
#' hc_yAxis(
#' min = 0,
#' max = 200,
#'
#' minorTickInterval = "auto",
#' minorTickWidth = 1,
#' minorTickLength = 10,
#' minorTickPosition = "inside",
#' minorTickColor = "#666",
#'
#' tickPixelInterval = 30,
#' tickWidth = 2,
#' tickPosition = "inside",
#' tickLength = 10,
#' tickColor = "#666",
#'
#' labels = list(
#' step = 2,
#' rotation = "auto"
#' ),
#' title = list(
#' text = "km/h"
#' ),
#'
#' plotBands = list(
#' list(from = 0, to = 120, color = "#55BF3B"),
#' list(from = 120, to = 160, color = "#DDDF0D"),
#' list(from = 160, to = 200, color = "#DF5353")
#' )
#'
#' )
#'
#'
#' @export
hc_pane <- function(hc, ...) {
.hc_opt(hc, "pane", ...)
}
#' Plotoptions options for highcharter objects
#'
#' The plotOptions is a wrapper object for config objects for each series
#' type. The config objects for each series can also be overridden for
#' each series item as given in the series array.
#' Configuration options for the series are given in three levels. Options
#' for all series in a chart are given in the plotOptions.series object. Then options for all series of a specific
#' type are given in the plotOptions of that type, for example
#' plotOptions.line. Next, options for one single series are given in
#' the series array.
#'
#' @param hc A `highchart` `htmlwidget` object.
#' @param ... Arguments defined in \url{https://api.highcharts.com/highcharts/plotOptions}.
#'
#' @examples
#'
#' highchart() |>
#' hc_add_series(
#' data = c(29.9, 71.5, 106.4, 129.2, 144.0, 176.0, 135.6, 148.5, 216.4, 194.1, 95.6, 54.4)
#' ) |>
#' hc_plotOptions(
#' line = list(
#' color = "blue",
#' marker = list(
#' fillColor = "white",
#' lineWidth = 2,
#' lineColor = NULL
#' )
#' )
#' )
#'
#' @export
hc_plotOptions <- function(hc, ...) {
.hc_opt(hc, "plotOptions", ...)
}
#' Responsive options for highcharter objects
#'
#' Allows setting a set of rules to apply for different screen or chart
#' sizes. Each rule specifies additional chart options.
#'
#' @param hc A `highchart` `htmlwidget` object.
#' @param ... Arguments defined in \url{https://api.highcharts.com/highcharts/responsive}.
#'
#' @examples
#'
#' leg_500_opts <- list(enabled = FALSE)
#' leg_900_opts <- list(align = "right", verticalAlign = "middle", layout = "vertical")
#'
#'
#' # change the with of the container/windows to see the effect
#' highchart() |>
#' hc_add_series(data = cumsum(rnorm(100))) |>
#' hc_responsive(
#' rules = list(
#' # remove legend if there is no much space
#' list(
#' condition = list(maxWidth = 500),
#' chartOptions = list(legend = leg_500_opts)
#' ),
#' # put legend on the right when there is much space
#' list(
#' condition = list(minWidth = 900),
#' chartOptions = list(legend = leg_900_opts)
#' )
#' )
#' )
#'
#' @export
hc_responsive <- function(hc, ...) {
.hc_opt(hc, "responsive", ...)
}
#' Series options for highcharter objects
#'
#' Series options for specific data and the data itself. In TypeScript you
#' have to cast the series options to specific series types, to get all
#' possible options for a series.
#'
#' @param hc A `highchart` `htmlwidget` object.
#' @param ... Arguments defined in \url{https://api.highcharts.com/highcharts/series}.
#'
#' @examples
#'
#' highchart() |>
#' hc_series(
#' list(
#' name = "Tokyo",
#' data = c(7.0, 6.9, 9.5, 14.5, 18.4, 21.5, 25.2, 26.5, 23.3, 18.3, 13.9, 9.6)
#' ),
#' list(
#' name = "London",
#' data = c(3.9, 4.2, 5.7, 8.5, 11.9, 15.2, 17.0, 16.6, 14.2, 10.3, 6.6, 4.8)
#' )
#' )
#'
#' @export
hc_series <- function(hc, ...) {
.hc_opt(hc, "series", ...)
}
#' Subtitle options for highcharter objects
#'
#' The chart's subtitle. This can be used both to display a subtitle below
#' the main title, and to display random text anywhere in the chart. The
#' subtitle can be updated after chart initialization through the
#' Chart.setTitle method.
#'
#' @param hc A `highchart` `htmlwidget` object.
#' @param ... Arguments defined in \url{https://api.highcharts.com/highcharts/subtitle}.
#'
#' @examples
#'
#' highchart() |>
#' hc_add_series(
#' data = c(7.0, 6.9, 9.5, 14.5, 18.2, 21.5, 25.2, 26.5, 23.3, 18.3, 13.9, 9.6),
#' type = "column"
#' ) |>
#' hc_subtitle(
#' text = "And this is a subtitle with more information",
#' align = "left",
#' style = list(color = "#2b908f", fontWeight = "bold")
#' )
#'
#' @export
hc_subtitle <- function(hc, ...) {
.hc_opt(hc, "subtitle", ...)
}
#' Title options for highcharter objects
#'
#' The chart's main title.
#'
#' @param hc A `highchart` `htmlwidget` object.
#' @param ... Arguments defined in \url{https://api.highcharts.com/highcharts/title}.
#'
#' @examples
#'
#' highchart() |>
#' hc_add_series(
#' data = c(7.0, 6.9, 9.5, 14.5, 18.2, 21.5, 25.2, 26.5, 23.3, 18.3, 13.9, 9.6),
#' type = "column"
#' ) |>
#' hc_title(
#' text = "This is a title with <i>margin</i> and <b>Strong or bold text</b>",
#' margin = 20,
#' align = "left",
#' style = list(color = "#22A884", useHTML = TRUE)
#' )
#'
#' @export
hc_title <- function(hc, ...) {
.hc_opt(hc, "title", ...)
}
#' Tooltip options for highcharter objects
#'
#' Options for the tooltip that appears when the user hovers over a
#' series or point.
#'
#' @param hc A `highchart` `htmlwidget` object.
#' @param ... Arguments defined in \url{https://api.highcharts.com/highcharts/tooltip}.
#' @param sort Logical value to implement sort according `this.point`
#' \url{http://stackoverflow.com/a/16954666/829971}.
#' @param table Logical value to implement table in tooltip:
#' \url{http://stackoverflow.com/a/22327749/829971}.
#'
#' @examples
#'
#' highchart() |>
#' hc_add_series(data = sample(1:12)) |>
#' hc_add_series(data = sample(1:12) + 10) |>
#' hc_tooltip(
#' crosshairs = TRUE,
#' borderWidth = 5,
#' sort = TRUE,
#' table = TRUE
#' )
#'
#'
#' @export
hc_tooltip <- function(hc, ..., sort = FALSE, table = FALSE) {
if (sort)
hc <- .hc_tooltip_sort(hc)
if (table)
hc <- .hc_tooltip_table(hc)
if (length(list(...)))
hc <- .hc_opt(hc, "tooltip", ...)
hc
}
#' Xaxis options for highcharter objects
#'
#' The X axis or category axis. Normally this is the horizontal axis,
#' though if the chart is inverted this is the vertical axis. In case of
#' multiple axes, the xAxis node is an array of configuration objects.
#' See the Axis class for programmatic
#' access to the axis.
#'
#' In Highmaps, the axis is hidden, but it is used behind the scenes to
#' control features like zooming and panning. Zooming is in effect the same
#' as setting the extremes of one of the exes.
#'
#' @param hc A `highchart` `htmlwidget` object.
#' @param ... Arguments defined in \url{https://api.highcharts.com/highcharts/xAxis}.
#'
#' @examples
#'
#' highchart() |>
#' hc_add_series(
#' data = c(7.0, 6.9, 9.5, 14.5, 18.2, 21.5, 25.2, 26.5, 23.3, 18.3, 13.9, 9.6),
#' type = "spline"
#' ) |>
#' hc_xAxis(
#' title = list(text = "x Axis at top"),
#' alternateGridColor = "#FDFFD5",
#' opposite = TRUE,
#' plotLines = list(
#' list(
#' label = list(text = "This is a plotLine"),
#' color = "#FF0000",
#' width = 2,
#' value = 5.5
#' )
#' )
#' )
#'
#' @export
hc_xAxis <- function(hc, ...) {
.hc_opt(hc, "xAxis", ...)
}
#' Yaxis options for highcharter objects
#'
#' The Y axis or value axis. Normally this is the vertical axis,
#' though if the chart is inverted this is the horizontal axis.
#' In case of multiple axes, the yAxis node is an array of
#' configuration objects.
#' See the Axis object for programmatic
#' access to the axis.
#'
#' @param hc A `highchart` `htmlwidget` object.
#' @param ... Arguments defined in \url{https://api.highcharts.com/highcharts/yAxis}.