Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions R/pricesensitivitymeter.R
Original file line number Diff line number Diff line change
Expand Up @@ -367,6 +367,17 @@ PriceSensitivityMeter <- function(x,
edits = list(annotationPosition = FALSE, annotationText = FALSE,
axisTitleText = FALSE, titleText = FALSE, legendText = FALSE))
attr(pp, "ChartData") <- psm.dat
# Expose the chart title (forwarded to Line via ...) as a ChartLabels$ChartTitle
# attribute so downstream consumers can label the chart's data. Merge into any
# ChartLabels already set by Line rather than overwriting it.
chart.title <- list(...)[["title"]]
if (!is.null(chart.title) && any(nzchar(chart.title))) {
chart.labels <- attr(pp, "ChartLabels")
if (is.null(chart.labels))
chart.labels <- list()
chart.labels$ChartTitle <- chart.title
attr(pp, "ChartLabels") <- chart.labels
}
return(pp)
}

Expand Down
12 changes: 12 additions & 0 deletions tests/testthat/test-pricesensitivitymeter.R
Original file line number Diff line number Diff line change
Expand Up @@ -231,3 +231,15 @@ test_that("PSM with two axes",
y2.title.font.family = "Courier New", y2.title.font.color = "#0000FF",
y2.bounds.minimum = 0.5, y2.bounds.maximum = 5, y2.title = "R"), NA)
})

test_that("Chart title exposed as ChartLabels$ChartTitle",
{
psm <- PriceSensitivityMeter(dat, title = "My price sensitivity meter")
expect_equal(attr(psm, "ChartLabels")$ChartTitle, "My price sensitivity meter")
# ChartData is still attached alongside the title
expect_false(is.null(attr(psm, "ChartData")))

# No ChartTitle is exposed when the title is empty
psm.no.title <- PriceSensitivityMeter(dat)
expect_null(attr(psm.no.title, "ChartLabels")$ChartTitle)
})
Loading