Skip to content

Commit

Permalink
Fix. Account for style="none" Closes ardata-fr#91
Browse files Browse the repository at this point in the history
* Add none_as_empty= argument to ooxml_fp_border
* Add wrap_in_tags helper
  • Loading branch information
trekonom committed Nov 9, 2024
1 parent b69fbf6 commit f4c60ef
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 10 deletions.
2 changes: 1 addition & 1 deletion R/to_pml.R
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ to_pml.ms_linechart <- function(x, id_x, id_y, sheetname = "sheet1", add_ns = FA
line_str <- "<c:spPr><a:ln><a:noFill/></a:ln></c:spPr>"
} else {
line_properties <- fp_border(color = serie$stroke, style = serie$line_style, width = serie$line_width)
line_str <- ooxml_fp_border(line_properties, in_tags = c("c:spPr"))
line_str <- ooxml_fp_border(line_properties, in_tags = c("c:spPr"), none_as_empty = FALSE)
}
if( !has_marker )
marker_str <- "<c:marker><c:symbol val=\"none\"/></c:marker>"
Expand Down
26 changes: 17 additions & 9 deletions R/utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -40,16 +40,29 @@ pretty_num_axes <- function(x, data_x, data_y){
x
}

wrap_in_tags <- function(out, in_tags = NULL) {
if( !is.null(in_tags) ){
begin <- paste0("<", in_tags, ">", collapse = "")
end <- paste0("</", rev(in_tags), ">", collapse = "")
out <- paste0(begin, out, end)
}
out
}

#' @importFrom grDevices rgb
ooxml_fp_border <- function(x, in_tags = NULL ){
ooxml_fp_border <- function(x, in_tags = NULL, none_as_empty = TRUE ){
stopifnot(inherits(x, "fp_border"))
colspecs <- as.list(col2rgb( x$color, alpha = TRUE )[,1] / 255)

alpha <- colspecs$alpha
is_transparent <- alpha < .0001

if( is_transparent || x$width < 0.001 || x$style %in% "none" ){
return("")
if( is_transparent || x$width < 0.001 || x$style %in% "none" ) {
if (none_as_empty) {
return("")
} else {
return(wrap_in_tags("<a:ln><a:noFill/></a:ln>", in_tags = in_tags))
}
}

colspecs$alpha <- NULL
Expand All @@ -71,12 +84,7 @@ ooxml_fp_border <- function(x, in_tags = NULL ){
out <- sprintf("<a:ln algn=\"ctr\" w=\"%.0f\">", x$width * 12700)
out <- paste0(out, solidfill, presetdash, "</a:ln>")

if( !is.null(in_tags) ){
begin <- paste0("<", in_tags, ">", collapse = "")
end <- paste0("</", rev(in_tags), ">", collapse = "")
out <- paste0(begin, out, end)
}
out
wrap_in_tags(out, in_tags = in_tags)
}


Expand Down

0 comments on commit f4c60ef

Please sign in to comment.