forked from jbkunst/highcharter
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdownload-highcharts-code.R
104 lines (82 loc) · 3.35 KB
/
download-highcharts-code.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
# packages ----------------------------------------------------------------
library(purrr)
library(rvest)
library(stringr)
library(yaml)
library(stringr)
# settings ----------------------------------------------------------------
version <- "5.0.14"
hccodeurl <- "http://code.highcharts.com"
path <- sprintf("inst/htmlwidgets/lib/highcharts-%s", version)
yml <- system.file("htmlwidgets/highchart.yaml", package = "highcharter")
yml <- yaml.load_file(yml)[[1]]
version_old <- map_chr(yml, c("version"))[map_chr(yml, c("name")) == "highcharts"]
path_old <- str_replace(path, version, version_old)
# creating folder structure
folders <- c("", "modules", "plugins", "css", "custom")
try(map(file.path(path, folders), dir.create))
# main files --------------------------------------------------------------
hchtml <- read_html(hccodeurl)
hclnks <- hchtml %>%
html_node("ul") %>% # first list
html_nodes("li") %>%
html_text() %>%
.[!str_detect(., "src.js")] %>%
str_replace("^.*com\\/", "")
map2(
file.path(hccodeurl, hclnks),
file.path(path, hclnks),
download.file
)
# stock & map
hclnks <- c("http://code.highcharts.com/stock/highstock.js",
"http://code.highcharts.com/maps/modules/map.js") %>%
str_replace("^.*com\\/", "")
map2(
file.path(hccodeurl, hclnks),
str_replace(file.path(path, hclnks), "stock/|maps/", ""),
download.file
)
# plugins -----------------------------------------------------------------
files <- c(
"https://raw.githubusercontent.com/blacklabel/annotations/master/js/annotations.js",
"http://blacklabel.github.io/multicolor_series/js/multicolor_series.js",
"https://raw.githubusercontent.com/larsac07/Motion-Highcharts-Plugin/master/motion.js",
"https://raw.githubusercontent.com/highcharts/pattern-fill/master/pattern-fill-v2.js",
"https://raw.githubusercontent.com/highcharts/draggable-points/master/draggable-points.js",
"https://raw.githubusercontent.com/highcharts/draggable-legend/master/draggable-legend.js",
"https://raw.githubusercontent.com/highcharts/export-csv/master/export-csv.js",
"https://raw.githubusercontent.com/rudovjan/highcharts-tooltip-delay/master/tooltip-delay.js",
"https://raw.githubusercontent.com/blacklabel/grouped_categories/master/grouped-categories.js",
"https://raw.githubusercontent.com/streamlinesocial/highcharts-regression/master/highcharts-regression.js"
)
#
# map2(
# files,
# file.path(path, "plugins", basename(files)),
# download.file
# )
file.copy(
file.path(path_old, "plugins", basename(files)),
file.path(path, "plugins", basename(files)),
overwrite = TRUE
)
# for yaml ----------------------------------------------------------------
# path %>%
# dir(recursive = TRUE, full.names = TRUE, pattern = ".js$") %>%
# setdiff(file.path(path, "modules", c("accessibility.js", "boost.js", "canvas-tools.js"))) %>%
# str_replace(path, " - ") %>%
# str_replace("/", "") %>%
# paste0(collapse = "\n") %>%
# cat()
# my customs --------------------------------------------------------------
file.copy(
dir(file.path(path_old, "custom"), full.names = TRUE),
str_replace(dir(file.path(path_old, "custom"), full.names = TRUE), version_old, version),
overwrite = TRUE
)
file.copy(
dir(file.path(path_old, "css"), full.names = TRUE),
str_replace(dir(file.path(path_old, "css"), full.names = TRUE), version_old, version),
overwrite = TRUE
)