Skip to content

Commit

Permalink
enable linechart with only markers
Browse files Browse the repository at this point in the history
  • Loading branch information
davidgohel committed Apr 20, 2021
1 parent d11e880 commit 26835b6
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 23 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
@@ -1,7 +1,7 @@
Package: mschart
Type: Package
Title: Chart Generation for 'Microsoft Word' and 'Microsoft PowerPoint' Documents
Version: 0.3.1.001
Version: 0.3.1.002
Authors@R: c(
person("David", "Gohel", role = c("aut", "cre"),
email = "david.gohel@ardata.fr"),
Expand Down
7 changes: 7 additions & 0 deletions NEWS.md
@@ -1,3 +1,10 @@
# mschart 0.3.1

## New features

* Support for linechart with or without lines and with or without markers


# mschart 0.3.0

## Issues
Expand Down
26 changes: 18 additions & 8 deletions R/chart_settings.R
Expand Up @@ -105,9 +105,20 @@ linechart_options <- function( vary_colors = FALSE ){

#' @export
#' @describeIn chart_settings linechart settings
chart_settings.ms_linechart <- function( x, vary_colors, ... ){
#' @param style Style for the linechart or scatterchart type of markers. One
#' of 'none', 'line', 'lineMarker', 'marker', 'smooth', 'smoothMarker'.
chart_settings.ms_linechart <- function( x, vary_colors, style = "lineMarker", ... ){

options <- linechart_options(
vary_colors = ifelse(missing(vary_colors), x$options$vary_colors, vary_colors)
)

if( !style %in% st_scatterstyle ){
stop("style should be one of ", paste0(shQuote(st_scatterstyle), collapse = ", " ))
}


options <- linechart_options( vary_colors = ifelse(missing(vary_colors), x$options$vary_colors, vary_colors) )
options$linestyle <- style
x$options <- options
x
}
Expand All @@ -130,14 +141,13 @@ chart_settings.ms_areachart <- function( x, vary_colors = FALSE, grouping = "sta

#' @export
#' @describeIn chart_settings linechart settings
#' @param scatterstyle The Style for the scatter chart. One
#' of 'none', 'line', 'lineMarker', 'marker', 'smooth', 'smoothMarker'.
chart_settings.ms_scatterchart <- function( x, vary_colors = FALSE, scatterstyle = "lineMarker", ... ){
chart_settings.ms_scatterchart <- function( x, vary_colors = FALSE, style = "marker", ... ){

if( !scatterstyle %in% st_scatterstyle ){
stop("scatterstyle should be one of ", paste0(shQuote(st_scatterstyle), collapse = ", " ))
if( !style %in% st_scatterstyle ){
stop("style should be one of ",
paste0(shQuote(st_scatterstyle), collapse = ", " ))
}
options <- list(vary_colors = vary_colors, scatterstyle = scatterstyle )
options <- list(vary_colors = vary_colors, scatterstyle = style )
class(options) <- "scatterchart_options"

x$options <- options
Expand Down
8 changes: 2 additions & 6 deletions R/ms_chart.R
Expand Up @@ -45,13 +45,9 @@ ms_linechart <- function(data, x, y, group = NULL, labels = NULL){
if(!is.numeric(data[[y]])){
stop("y column should be numeric.")
}
out <- chart_settings(out)

out$axis_tag <- list(x = xtag,
y = "c:valAx")

serie_names <- names(out$series_settings$symbol)
values <- setNames( rep( "none", length(serie_names)), serie_names )
out <- chart_data_symbol(out, values = values)
out$axis_tag <- list(x = xtag, y = "c:valAx")

out
}
Expand Down
21 changes: 16 additions & 5 deletions R/to_pml.R
Expand Up @@ -76,9 +76,17 @@ to_pml.ms_linechart <- function(x, id_x, id_y, sheetname = "sheet1", add_ns = FA
y_class = serie_builtin_class(x$data[[x$y]]), sheetname = sheetname )

# sapply linec-----
str_series_ <- sapply( series, function(serie, template ){
marker_str <- get_marker_xml(serie$fill, serie$stroke, serie$symbol, serie$size )
sppr_str <- get_sppr_xml_line_chart(fill = serie$fill, stroke = serie$stroke, style = serie$line_style, width = serie$line_width)
str_series_ <- sapply( series, function(serie, has_line, has_marker ){
if( !has_line ){
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"))
}
if( !has_marker )
marker_str <- "<c:marker><c:symbol val=\"none\"/></c:marker>"
else marker_str <- get_marker_xml(serie$fill, serie$stroke, serie$symbol, serie$size )


label_settings <- x$label_settings
label_settings$labels_fp <- serie$labels_fp
Expand All @@ -92,15 +100,18 @@ to_pml.ms_linechart <- function(x, id_x, id_y, sheetname = "sheet1", add_ns = FA
sprintf("<c:idx val=\"%.0f\"/>", serie$idx),
sprintf("<c:order val=\"%.0f\"/>", serie$order),
sprintf("<c:tx>%s</c:tx>", to_pml(serie$tx)),
sppr_str, marker_str,
line_str, marker_str,
to_pml(label_settings, show_label = !is.null(x$label_cols)),
"<c:cat>", to_pml(serie$x), "</c:cat>",
"<c:val>", to_pml(serie$y), "</c:val>",
label_pml,
sprintf("<c:smooth val=\"%.0f\"/>", serie$smooth),
"</c:ser>"
)
})
},
has_line = has_lines[x$options$linestyle],
has_marker = has_markers[x$options$linestyle])

str_series_ <- paste(str_series_, collapse = "")

x_ax_id <- sprintf("<c:axId val=\"%s\"/>", id_x)
Expand Down
6 changes: 3 additions & 3 deletions man/chart_settings.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 26835b6

Please sign in to comment.