-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
#' adjust_tableau_font_style | ||
#' | ||
#' Adjust the font style of a tableau file | ||
#' | ||
#' @param import_files selected tableau file or folder, to change its font style. If | ||
#' it is only a file, make sure it is a twb file. | ||
#' @param font_style the name of the font style you want to use (in quotation marks "") | ||
#' @param save_location The location to which the adjusted tableau file will be | ||
#' saved (this needs to be a .twb file). If empty, the adjusted tableau file will be overwritten. | ||
#' | ||
#' @return tableau file with the correct font style. | ||
#' @export | ||
#' | ||
adjust_tableau_font_style <- function (import_files, font_style = "Tableau Regular", save_location = NULL) | ||
{ | ||
# if the path gives a whole map instead of one file, make a file list. | ||
if (tools::file_ext(import_files) != "twb") { | ||
import_files = list.files(import_files, full.names = TRUE) | ||
} | ||
|
||
for (file in import_files) { | ||
#read xml file('s) | ||
data <- xml2::read_xml(file) | ||
|
||
# Find the font-style part | ||
style_part <- xml2::xml_find_all(data, "//formatted-text//run") | ||
|
||
for (type_section in style_part) { | ||
# change the style | ||
xml2::xml_set_attr(type_section, "fontname", font_style) | ||
} | ||
|
||
Ans_1 <- readline(prompt = "Do you want to save the adjustments in a new file? y/n: ") | ||
|
||
if (substr(Ans_1, 1, 1) == "y") { | ||
Ans_2 <- readline(prompt = "Yes, so did you give a new save file as input? y/n: ") | ||
if (substr(Ans_2, 1, 1) == "y") { | ||
cat("a new save file is given so this file will be used for saving \n") | ||
|
||
# check if the save_location file is .twb | ||
if (tools::file_ext(save_location) != "twb") { | ||
stop("save_location file is no .twb file") | ||
} | ||
# update and save the new file | ||
data <- XML::xmlParse(data) | ||
XML::saveXML(doc = data, file = save_location) | ||
} | ||
|
||
else { | ||
stop("stop the process, the user wants his file to be saved at onther file, | ||
however no new file as input is given.") | ||
} | ||
} | ||
|
||
else { | ||
cat("file can be overwritten \n") | ||
|
||
data <- XML::xmlParse(data) | ||
XML::saveXML(doc = data, file = file) | ||
|
||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
#' adjust_tableau_size | ||
#' | ||
#' Adjust the size of selected tableau file/files. | ||
#' | ||
#' @param import_files selected tableau file or folder, to change its size. If | ||
#' it is only one file, make sure it is a twb file. | ||
#' @param save_location The location to which the adjusted tableau file will be | ||
#' saved (this needs to be a .twb file). If empty, the adjusted tableau file will be overwritten. | ||
#' @param maxheight Max height for tableau file, if NULL use system variables. | ||
#' @param maxwidth Max width for tableau file, if NULL use system variables. | ||
#' @param minheight Min height for tableau file, if NULL use system variables. | ||
#' @param minwidth Min width for tableau file, if NULL use system variables. | ||
#' | ||
#' @return tableau file with the correct size. | ||
#' @export | ||
#' @family xml | ||
adjust_tableau_size <- function(import_files, save_location = NULL, maxheight = NULL, | ||
maxwidth = NULL, minheight = NULL, minwidth = NULL) { | ||
if (tools::file_ext(import_files) != "twb") { | ||
import_files = list.files(import_files, full.names = TRUE) | ||
} | ||
|
||
for (file in import_files) { | ||
data <- xml2::read_xml(file) | ||
|
||
# Find the size part | ||
style_part <- xml2::xml_find_all(data, "//style ") | ||
size_part <- xml2::xml_find_all(style_part, "//size[@minwidth]") | ||
|
||
## adjust the size part | ||
if (is.null(c(maxheight, maxwidth, minheight, minwidth))) { | ||
minheight <- maxheight <- Sys.getenv("TABLEAU_HEIGHT") | ||
minwidth <- maxwidth <- Sys.getenv("TABLEAU_WIDTH") | ||
} | ||
xml2::xml_set_attrs(size_part, c("maxheight" = maxheight, "maxwidth" = maxwidth, | ||
"minheight" = minheight, "minwidth" = minwidth)) | ||
## save adjusments | ||
Ans_1 <- | ||
readline(prompt = "Do you want to save the adjustments in a new file? y/n: ") | ||
if (substr(Ans_1, 1, 1) == "y") { | ||
Ans_2 <- | ||
readline(prompt = "Yes, so did you give a new save file as input? y/n: ") | ||
if (substr(Ans_2, 1, 1) == "y") { | ||
cat("a new save file is given so this file will be used for saving \n") | ||
# check if the save_location file is .twb | ||
if (tools::file_ext(save_location) != "twb") { | ||
stop("save_location file is no .twb file") | ||
} | ||
# update and save the new file | ||
data <- XML::xmlParse(data) | ||
XML::saveXML(doc = data, file = save_location) | ||
} | ||
else { | ||
stop( | ||
"stop the process, the user wants his file to be saved at onther file, | ||
however no new file as input is given." | ||
) | ||
} | ||
} | ||
|
||
else { | ||
cat("file can be overwritten \n") | ||
data <- XML::xmlParse(data) | ||
XML::saveXML(doc = data, file = file) | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
#' check_dashboard_names | ||
#' | ||
#' Check the names of dashboards in tableau, according to the style guide. | ||
#' The wrong dashboards will be returned together with the reason why it is a | ||
#' wrong name | ||
#' | ||
#' @param import_files selected tableau file or folder, | ||
#' to check the names of the dashboards. | ||
#' If it is only one file, make sure it is a twb file. | ||
#' | ||
#' @return the wrongly named dashboards | ||
#' @export | ||
#' @family xml | ||
check_dashboard_names <- function(import_files) { | ||
if (tools::file_ext(import_files) != "twb") { | ||
import_files = list.files(import_files, full.names = TRUE) | ||
} | ||
for (file in import_files) { | ||
data <- XML::xmlParse(file = file) | ||
|
||
## Extract de root node. | ||
rootnode <- XML::xmlRoot(data) | ||
|
||
## Find the dashboards part | ||
DB_part <- rootnode[["dashboards"]] | ||
|
||
## Find the amount of dashboards | ||
number_of_DB <- length(XML::xmlChildren(DB_part)) | ||
|
||
## while loop over all DB's to save each dashboards current name | ||
count <- 1 | ||
name_list <- list() | ||
|
||
while (count <= number_of_DB) { | ||
DB_names <- rootnode[["dashboards"]][[count]] | ||
name_list <- append(name_list, XML::xmlAttrs(DB_names)) | ||
count <- count + 1 | ||
} | ||
|
||
## check all conditions for a correct DB name | ||
names <- 1 | ||
while (names <= number_of_DB) { | ||
|
||
if (name_list[names] == "Filters" || name_list[names] == "Toelichting") { | ||
## do nothing, it is a correct name, so skip it. | ||
} | ||
|
||
else if (name_list[names] == "filters" || name_list[names] == "toelichting") { | ||
print(paste0("Wrong DB name: '", name_list[names], "', not starting with an capital letter")) | ||
} | ||
|
||
else if (stringr::str_detect(name_list[names], "^\\d.") == F) { | ||
print(paste0("Wrong DB name: '", name_list[names],"', not starting with a digit and a dot")) | ||
} | ||
|
||
else if (stringr::str_detect(name_list[names], "[A-Z]") == F) { | ||
print(paste0("Wrong DB name: '", name_list[names], "', not starting with an capital letter")) | ||
} | ||
|
||
else if (grepl("DB", name_list[names]) == T) { | ||
print(paste0("Wrong DB name: '", name_list[names], "', no 'DB' allowed in DB name")) | ||
} | ||
names <- names + 1 | ||
} | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.