Skip to content

Commit

Permalink
Merge pull request #1534 from rstudio/data-area-fill-color
Browse files Browse the repository at this point in the history
Add option to change fill color of nanoplot data area (bounded to data points)
  • Loading branch information
rich-iannone authored Jan 13, 2024
2 parents aff3462 + 2e277ad commit 0a19437
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 7 deletions.
24 changes: 18 additions & 6 deletions R/helpers.R
Original file line number Diff line number Diff line change
Expand Up @@ -597,6 +597,14 @@ currency <- function(
#' `data_line_stroke_width` option. By default, a value of `4` (as in '4px')
#' is used.
#'
#' @param data_area_fill_color *Fill color for the data-point-bounded area*
#'
#' `scalar<character>` // *default:* `NULL` (`optional`)
#'
#' The fill color for the area that bounds the data points in line plot. The
#' default is `"#FF0000"` (`"red"`) but can be changed by providing a color
#' value to `data_area_fill_color`.
#'
#' @param data_bar_stroke_color *Color of a data bar's outside line*
#'
#' `scalar<character>` // *default:* `NULL` (`optional`)
Expand Down Expand Up @@ -787,6 +795,7 @@ nanoplot_options <- function(
data_line_type = NULL,
data_line_stroke_color = NULL,
data_line_stroke_width = NULL,
data_area_fill_color = NULL,
data_bar_stroke_color = NULL,
data_bar_stroke_width = NULL,
data_bar_fill_color = NULL,
Expand All @@ -811,24 +820,26 @@ nanoplot_options <- function(
currency = NULL
) {

data_point_radius <- data_point_radius %||% 10
data_point_radius <- data_point_radius %||% 10
data_point_stroke_color <- data_point_stroke_color %||% "#FFFFFF"
data_point_stroke_width <- data_point_stroke_width %||% 4
data_point_fill_color <- data_point_fill_color %||% "#FF0000"
data_point_fill_color <- data_point_fill_color %||% "#FF0000"

data_line_type <- data_line_type %||% "curved"
data_line_type <- data_line_type %||% "curved"
data_line_stroke_color <- data_line_stroke_color %||% "#4682B4"
data_line_stroke_width <- data_line_stroke_width %||% 8

data_area_fill_color <- data_area_fill_color %||% "#FF0000"

data_bar_stroke_color <- data_bar_stroke_color %||% "#3290CC"
data_bar_stroke_width <- data_bar_stroke_width %||% 4
data_bar_fill_color <- data_bar_fill_color %||% "#3FB5FF"
data_bar_fill_color <- data_bar_fill_color %||% "#3FB5FF"

data_bar_negative_stroke_color <- data_bar_negative_stroke_color %||% "#CC3243"
data_bar_negative_stroke_width <- data_bar_negative_stroke_width %||% 4
data_bar_negative_fill_color <- data_bar_negative_fill_color %||% "#D75A68"
data_bar_negative_fill_color <- data_bar_negative_fill_color %||% "#D75A68"

reference_line_color <- reference_line_color %||% "#75A8B0"
reference_line_color <- reference_line_color %||% "#75A8B0"
reference_area_fill_color <- reference_area_fill_color %||% "#A6E6F2"

vertical_guide_stroke_color <- vertical_guide_stroke_color %||% "#911EB4"
Expand Down Expand Up @@ -858,6 +869,7 @@ nanoplot_options <- function(
data_line_type = data_line_type,
data_line_stroke_color = data_line_stroke_color,
data_line_stroke_width = data_line_stroke_width,
data_area_fill_color = data_area_fill_color,
data_bar_stroke_color = data_bar_stroke_color,
data_bar_stroke_width = data_bar_stroke_width,
data_bar_fill_color = data_bar_fill_color,
Expand Down
1 change: 1 addition & 0 deletions R/modify_columns.R
Original file line number Diff line number Diff line change
Expand Up @@ -2887,6 +2887,7 @@ cols_nanoplot <- function(
data_point_fill_color = options_plots$data_point_fill_color,
data_line_stroke_color = options_plots$data_line_stroke_color,
data_line_stroke_width = options_plots$data_line_stroke_width,
data_area_fill_color = options_plots$data_area_fill_color,
data_bar_stroke_color = options_plots$data_bar_stroke_color,
data_bar_stroke_width = options_plots$data_bar_stroke_width,
data_bar_fill_color = options_plots$data_bar_fill_color,
Expand Down
3 changes: 2 additions & 1 deletion R/utils_plots.R
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ generate_nanoplot <- function(
data_point_fill_color = "#FF0000",
data_line_stroke_color = "#4682B4",
data_line_stroke_width = 8,
data_area_fill_color = "#FF0000",
data_bar_stroke_color = "#3290CC",
data_bar_stroke_width = 4,
data_bar_fill_color = "#3FB5FF",
Expand Down Expand Up @@ -1856,7 +1857,7 @@ generate_nanoplot <- function(
paste0(
"<path class=\"pattern-line\" ",
"d=\"M 0,8 l 8,-8 M -1,1 l 4,-4 M 6,10 l 4,-4\" ",
"stroke=\"red\" ",
"stroke=\"", data_area_fill_color, "\" ",
"stroke-width=\"1.5\" ",
"stroke-linecap=\"round\" ",
"shape-rendering=\"geometricPrecision\"",
Expand Down
9 changes: 9 additions & 0 deletions man/nanoplot_options.Rd

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

3 comments on commit 0a19437

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.