diff --git a/DESCRIPTION b/DESCRIPTION
index 9ebce3e..823056a 100644
--- a/DESCRIPTION
+++ b/DESCRIPTION
@@ -1,7 +1,7 @@
Package: mschart
Type: Package
Title: Chart Generation for 'Microsoft Word' and 'Microsoft PowerPoint' Documents
-Version: 0.4.0.003
+Version: 0.4.0.004
Authors@R: c(
person("David", "Gohel", role = c("aut", "cre"),
email = "david.gohel@ardata.fr"),
diff --git a/NEWS.md b/NEWS.md
index 9885198..15de806 100644
--- a/NEWS.md
+++ b/NEWS.md
@@ -5,6 +5,10 @@
* Support for openxlsx2 by Jan Marvin Garbuszus
* option to add table of data below corresponding levels by Marlon Molina
+## Issues
+
+* fix issue with % in labels of the graphic
+
# mschart 0.3.1
## New features
diff --git a/R/axis_codes.R b/R/axis_codes.R
index cabfc23..6e2571a 100644
--- a/R/axis_codes.R
+++ b/R/axis_codes.R
@@ -27,15 +27,14 @@ get_axis_tag <- function(x){
#' @param is_x if TRUE, generate xml for x axis, else for y axis
#' @param lab label for the axis
#' @param rot rotation of title
-axis_content_xml <- function(x, id, cross_id, theme, is_x = TRUE, lab = NULL, rot = 0 ){
-
+axis_content_xml <- function(x, id, cross_id, theme, is_x = TRUE, lab = NULL, rot = 0) {
x_title_id <- paste0("axis_title_", ifelse(is_x, "x", "y"))
- if( is.null(lab)) {
+ if (is.null(lab)) {
title_ <- ""
} else {
title_ <- "%s%s"
- title_ <- sprintf(title_, rot * 60000 , format(theme[[x_title_id]], type = "pml" ), lab )
+ title_ <- sprintf(title_, rot * 60000, format(theme[[x_title_id]], type = "pml"), lab)
}
major_tm <- ""
@@ -46,38 +45,44 @@ axis_content_xml <- function(x, id, cross_id, theme, is_x = TRUE, lab = NULL, ro
grid_major_id <- paste0("grid_major_line_", ifelse(is_x, "x", "y"))
major_gl <- ooxml_fp_border(theme[[grid_major_id]],
- in_tags = c("c:majorGridlines", "c:spPr"))
+ in_tags = c("c:majorGridlines", "c:spPr")
+ )
grid_minor_id <- paste0("grid_minor_line_", ifelse(is_x, "x", "y"))
minor_gl <- ooxml_fp_border(theme[[grid_minor_id]],
- in_tags = c("c:minorGridlines", "c:spPr"))
+ in_tags = c("c:minorGridlines", "c:spPr")
+ )
lim_max <- ""
- if( !is.null(x$limit_max) )
- lim_max <- sprintf("", x$limit_max )
+ if (!is.null(x$limit_max)) {
+ lim_max <- sprintf("", x$limit_max)
+ }
lim_min <- ""
- if( !is.null(x$limit_min) )
- lim_min <- sprintf("", x$limit_min )
+ if (!is.null(x$limit_min)) {
+ lim_min <- sprintf("", x$limit_min)
+ }
- scaling_str <- sprintf("%s%s", x$orientation, lim_max, lim_min )
- delete <- sprintf("", x$delete )
- position <- sprintf("", x$axis_position )
- crosses <- sprintf("", x$crosses )
+ scaling_str <- sprintf("%s%s", x$orientation, lim_max, lim_min)
+ delete <- sprintf("", x$delete)
+ position <- sprintf("", x$axis_position)
+ crosses <- sprintf("", x$crosses)
lim_max <- ""
- if( !is.null(x$limit_max) )
- lim_max <- sprintf("", x$limit_max )
+ if (!is.null(x$limit_max)) {
+ lim_max <- sprintf("", x$limit_max)
+ }
lim_min <- ""
- if( !is.null(x$limit_min) )
- lim_min <- sprintf("", x$limit_min )
+ if (!is.null(x$limit_min)) {
+ lim_min <- sprintf("", x$limit_min)
+ }
cross_at <- ""
- if( !is.null(x$position) ){
- cross_at <- sprintf("", x$position )
+ if (!is.null(x$position)) {
+ cross_at <- sprintf("", x$position)
crosses <- ""
}
num_fmt <- ""
- if( !is.null(x$num_fmt) ){
+ if (!is.null(x$num_fmt)) {
num_fmt <- sprintf("", x$num_fmt)
}
@@ -88,27 +93,28 @@ axis_content_xml <- function(x, id, cross_id, theme, is_x = TRUE, lab = NULL, ro
axis_major_ticks_id <- paste0("axis_ticks_", ifelse(is_x, "x", "y"))
axis_ticks <- ooxml_fp_border(theme[[axis_major_ticks_id]],
- in_tags = c("c:spPr"))
+ in_tags = c("c:spPr")
+ )
labels_text_id <- paste0("axis_text_", ifelse(is_x, "x", "y"))
rpr <- format(theme[[labels_text_id]], type = "pml")
rpr <- gsub("a:rPr", "a:defRPr", rpr)
labels_text_pr <- "%s"
- labels_text_pr <- sprintf(labels_text_pr, x$rotation * 60000, rpr )
-
- str_ <- paste0( "",
- scaling_str, delete, position,
- major_gl, minor_gl,
- title_,
- major_tm, minor_tm, tl_pos,
- labels_text_pr,
- axis_ticks, num_fmt,
- "",
- cross_at,
- crosses)
- str_ <- sprintf(str_, id, cross_id)
+ labels_text_pr <- sprintf(labels_text_pr, x$rotation * 60000, rpr)
+
+ str_ <- paste0(
+ sprintf("", id),
+ scaling_str, delete, position,
+ major_gl, minor_gl,
+ title_,
+ major_tm, minor_tm, tl_pos,
+ labels_text_pr,
+ axis_ticks, num_fmt,
+ sprintf("", cross_id),
+ cross_at,
+ crosses
+ )
str_
-
}
diff --git a/R/chart_labels.R b/R/chart_labels.R
index 8871beb..6ede2d1 100644
--- a/R/chart_labels.R
+++ b/R/chart_labels.R
@@ -10,13 +10,13 @@
#' mylc <- chart_labels(mylc, title = "my title", xlab = "my x label",
#' ylab = "my y label")
chart_labels <- function( x, title = NULL, xlab = NULL, ylab = NULL){
- if( !is.null(title) ) x$labels[["title"]] <- htmlEscape(title)
+ if( !is.null(title) ) x$labels[["title"]] <- title
else x$labels[["title"]] <- NULL
- if( !is.null(xlab) ) x$labels[["x"]] <- htmlEscape(xlab)
+ if( !is.null(xlab) ) x$labels[["x"]] <- xlab
else x$labels[["x"]] <- NULL
- if( !is.null(ylab) ) x$labels[["y"]] <- htmlEscape(ylab)
+ if( !is.null(ylab) ) x$labels[["y"]] <- ylab
else x$labels[["y"]] <- NULL
x
}
diff --git a/R/ms_chart.R b/R/ms_chart.R
index 2cacb60..5e56c71 100644
--- a/R/ms_chart.R
+++ b/R/ms_chart.R
@@ -415,7 +415,7 @@ format.ms_chart <- function(x, id_x, id_y, sheetname = "sheet1", drop_ext_data =
if (!is.null(x$labels[["title"]])) {
chartnode <- xml_find_first(xml_doc, "//c:chart")
title_ <- "%s%s"
- title_ <- sprintf(title_, ns, format(x$theme[["main_title"]], type = "pml"), x$labels[["title"]])
+ title_ <- sprintf(title_, ns, format(x$theme[["main_title"]], type = "pml"), htmlEscape(x$labels[["title"]]))
xml_add_child(chartnode, as_xml_document(title_), .where = 0)
} else { # null is not enough
atd_node <- xml_find_first(xml_doc, "//c:chart/c:autoTitleDeleted")