diff --git a/DESCRIPTION b/DESCRIPTION index 771a1ca..3d8ca98 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,7 +1,7 @@ Package: flipChart Type: Package Title: Single function for calling charts - CChart -Version: 1.12.11 +Version: 1.12.12 Author: Displayr Maintainer: Displayr Description: Wrapper for other chart functions, such that they can be access via a @@ -23,7 +23,7 @@ Imports: flipChartBasics, flipData (>= 1.2.7), flipFormat, - flipStandardCharts (>= 1.30.2), + flipStandardCharts (>= 1.32.12), flipStatistics, flipTables (>= 2.8.8), flipTime, diff --git a/R/cchart.R b/R/cchart.R index aec2f1c..03d6cf4 100644 --- a/R/cchart.R +++ b/R/cchart.R @@ -845,7 +845,7 @@ getPPTSettings <- function(chart.type, args, data) Crosses = categories.axis.line$crosses, MajorGridLine = list(Color = args$categories.grid.color, Width = px2pt(args$categories.grid.width), - Style = if (isTRUE(args$categories.grid.width == 0)) "None" else "Solid"), + Style = getGridLineStyle(args$categories.grid.width, args$categories.grid.dash)), RotateLabels = isTRUE(args$categories.tick.angle == 90), LabelPosition = "Low") if (any(nzchar(args$categories.bounds.maximum))) @@ -866,7 +866,7 @@ getPPTSettings <- function(chart.type, args, data) Crosses = values.axis.line$crosses, MajorGridLine = list(Color = args$values.grid.color, Width = px2pt(args$values.grid.width), - Style = if (isTRUE(args$values.grid.width == 0)) "None" else "Solid")) + Style = getGridLineStyle(args$values.grid.width, args$values.grid.dash))) if (any(nzchar(args$values.bounds.maximum))) res$ValueAxis$Maximum <- args$values.bounds.maximum if (any(nzchar(args$values.bounds.minimum))) @@ -934,6 +934,19 @@ getLineStyle <- function (line) { return (line$dash) } +# Grid line style for PPT/Excel export. Unlike getLineStyle(), a missing width +# does NOT mean "no line" here: getPPTSettings() sees the raw user args before +# the chart-function defaults are applied, so an omitted grid.width just means +# "use the chart default" (the grid is typically shown). Only an explicit width +# of 0 hides the grid. isTRUE() keeps this NA-safe. +getGridLineStyle <- function (width, dash) { + if (isTRUE(width == 0)) + return ("None") + if (is.null(dash)) + return ("Solid") + return (dash) +} + # Fix minimum axes bounds if they are not already set # This is performed only because PPT will set the minimum to 0 if not specified diff --git a/tests/testthat/test-chartsettings.R b/tests/testthat/test-chartsettings.R index d79dacf..c4248e3 100644 --- a/tests/testthat/test-chartsettings.R +++ b/tests/testthat/test-chartsettings.R @@ -341,3 +341,43 @@ test_that("Color opacity", expect_equal(attr(viz, "ChartSettings")$TemplateSeries[[3]]$OutlineColor, "#22222280") expect_equal(attr(viz, "ChartSettings")$TemplateSeries[[3]]$OutlineWidth, 1.500, tol = 1e-3) }) + +test_that("Grid line type is exported to PowerPoint settings (RS-22447)", +{ + res <- suppressWarnings(CChart("Column", dat.1d, append.data = TRUE, + values.grid.width = 1, values.grid.dash = "Dot", + categories.grid.width = 1, categories.grid.dash = "Dash")) + expect_equal(attr(res, "ChartSettings")$ValueAxis$MajorGridLine$Style, "Dot") + expect_equal(attr(res, "ChartSettings")$PrimaryAxis$MajorGridLine$Style, "Dash") + + # A zero-width grid is still "None" regardless of the dash setting. + res0 <- suppressWarnings(CChart("Column", dat.1d, append.data = TRUE, + values.grid.width = 0, values.grid.dash = "Dot")) + expect_equal(attr(res0, "ChartSettings")$ValueAxis$MajorGridLine$Style, "None") + + # Backwards compatible: no dash supplied still exports as "Solid". + res1 <- suppressWarnings(CChart("Column", dat.1d, append.data = TRUE, + values.grid.width = 1)) + expect_equal(attr(res1, "ChartSettings")$ValueAxis$MajorGridLine$Style, "Solid") + + # Backwards compatible: grid.width omitted entirely (NULL in the raw user + # args seen by getPPTSettings) must keep the previous "Solid" default, not + # collapse to "None". + res2 <- suppressWarnings(CChart("Column", dat.1d, append.data = TRUE)) + expect_equal(attr(res2, "ChartSettings")$ValueAxis$MajorGridLine$Style, "Solid") +}) + +test_that("getGridLineStyle handles missing/NA widths (RS-22447)", +{ + # Only an explicit width of 0 hides the grid. + expect_equal(getGridLineStyle(0, "Dot"), "None") + expect_equal(getGridLineStyle(0, NULL), "None") + # A visible grid uses the dash if given, otherwise "Solid". + expect_equal(getGridLineStyle(1, "Dash"), "Dash") + expect_equal(getGridLineStyle(1, NULL), "Solid") + # Missing/NA width must not hide the grid or error - it keeps "Solid" + # (the previous default) unless an explicit dash is supplied. + expect_equal(getGridLineStyle(NULL, NULL), "Solid") + expect_equal(getGridLineStyle(NA, NULL), "Solid") + expect_equal(getGridLineStyle(NULL, "Dot"), "Dot") +})