From 445692f3bf62f31ca9543ec58b80ccf502fea5ba Mon Sep 17 00:00:00 2001 From: Richard Iannone Date: Fri, 22 Dec 2023 23:08:42 -0500 Subject: [PATCH 1/9] Modify `data_x_width` value --- R/utils_plots.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/R/utils_plots.R b/R/utils_plots.R index 5110f7452b..4caf3bde8f 100644 --- a/R/utils_plots.R +++ b/R/utils_plots.R @@ -223,7 +223,7 @@ generate_nanoplot <- function( # number of data points) if (!is.null(x_vals) || single_horizontal_bar) { - data_x_width <- 500 + data_x_width <- 600 } else { From 7b47eaefc94ce8e8ad386b0b92599d9d7b1af773 Mon Sep 17 00:00:00 2001 From: Richard Iannone Date: Fri, 22 Dec 2023 23:09:11 -0500 Subject: [PATCH 2/9] Add linebreaks to enhance readability of stmts --- R/utils_plots.R | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/R/utils_plots.R b/R/utils_plots.R index 4caf3bde8f..de52ef7e84 100644 --- a/R/utils_plots.R +++ b/R/utils_plots.R @@ -965,15 +965,20 @@ generate_nanoplot <- function( } else { if (y_vals[i] < 0) { + y_value_i <- data_y0_point y_height <- data_y_points[i] - data_y0_point data_bar_stroke_color_i <- data_bar_negative_stroke_color[1] data_bar_stroke_width_i <- data_bar_negative_stroke_width[1] data_bar_fill_color_i <- data_bar_negative_fill_color[1] + } else if (y_vals[i] > 0) { + y_value_i <- data_y_points[i] y_height <- data_y0_point - data_y_points[i] + } else if (y_vals[i] == 0) { + y_value_i <- data_y0_point - 1 y_height <- 2 data_bar_stroke_color_i <- "#808080" From 75e50b817f3db9d04873e49d51b73e758af873b4 Mon Sep 17 00:00:00 2001 From: Richard Iannone Date: Fri, 22 Dec 2023 23:09:20 -0500 Subject: [PATCH 3/9] Modify comment --- R/utils_plots.R | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/R/utils_plots.R b/R/utils_plots.R index de52ef7e84..fc50c06207 100644 --- a/R/utils_plots.R +++ b/R/utils_plots.R @@ -1009,7 +1009,9 @@ generate_nanoplot <- function( if (plot_type == "bar" && single_horizontal_bar) { - # TODO: This type of display assumes there is only a single `y` value + # This type of display assumes there is only a single `y` value and there + # are possibly several such horizontal bars across different rows that + # need to be on a common scale bar_thickness <- data_point_radius[1] * 2 From 0466eddb62b3fbee56c990e9164ad2182e59c887 Mon Sep 17 00:00:00 2001 From: Richard Iannone Date: Fri, 22 Dec 2023 23:09:34 -0500 Subject: [PATCH 4/9] Modify calculation of horizontal bar thickness --- R/utils_plots.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/R/utils_plots.R b/R/utils_plots.R index fc50c06207..ec14530f51 100644 --- a/R/utils_plots.R +++ b/R/utils_plots.R @@ -1013,7 +1013,7 @@ generate_nanoplot <- function( # are possibly several such horizontal bars across different rows that # need to be on a common scale - bar_thickness <- data_point_radius[1] * 2 + bar_thickness <- data_point_radius[1] * 4 # Scale to proportional values y_proportions_list <- From 29da2b4545677e919a702693efabe43af9471273 Mon Sep 17 00:00:00 2001 From: Richard Iannone Date: Fri, 22 Dec 2023 23:10:05 -0500 Subject: [PATCH 5/9] Scale bar widths across two distinct cases --- R/utils_plots.R | 29 +++++++++++++++++++---------- 1 file changed, 19 insertions(+), 10 deletions(-) diff --git a/R/utils_plots.R b/R/utils_plots.R index ec14530f51..396c60a5ef 100644 --- a/R/utils_plots.R +++ b/R/utils_plots.R @@ -1015,19 +1015,28 @@ generate_nanoplot <- function( bar_thickness <- data_point_radius[1] * 4 - # Scale to proportional values - y_proportions_list <- - normalize_to_list( - val = y_vals, - all_vals = all_single_y_vals, - zero = 0 - ) + if (all(all_single_y_vals == 0)) { - y_proportion <- y_proportions_list[["val"]] - y_proportion_zero <- y_proportions_list[["zero"]] + # Handle case where all values across rows are `0` - y0_width <- y_proportion_zero * data_x_width + y_proportion <- 0.5 + y_proportion_zero <- 0.5 + + } else { + + # Scale to proportional values + y_proportions_list <- + normalize_to_list( + val = y_vals, + all_vals = all_single_y_vals, + zero = 0 + ) + y_proportion <- y_proportions_list[["val"]] + y_proportion_zero <- y_proportions_list[["zero"]] + } + + y0_width <- y_proportion_zero * data_x_width y_width <- y_proportion * data_x_width if (y_vals[1] < 0) { From 0c97edbe54f4fb66452f7966c7ff9843642b0c34 Mon Sep 17 00:00:00 2001 From: Richard Iannone Date: Fri, 22 Dec 2023 23:10:47 -0500 Subject: [PATCH 6/9] Properly handle positive and negative bars --- R/utils_plots.R | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/R/utils_plots.R b/R/utils_plots.R index 396c60a5ef..94878e2b0b 100644 --- a/R/utils_plots.R +++ b/R/utils_plots.R @@ -1040,26 +1040,39 @@ generate_nanoplot <- function( y_width <- y_proportion * data_x_width if (y_vals[1] < 0) { + data_bar_stroke_color <- data_bar_negative_stroke_color[1] data_bar_stroke_width <- data_bar_negative_stroke_width[1] data_bar_fill_color <- data_bar_negative_fill_color[1] + + rect_x <- y_width + rect_width <- y0_width - y_width + } else if (y_vals[1] > 0) { + data_bar_stroke_color <- data_bar_stroke_color[1] data_bar_stroke_width <- data_bar_stroke_width[1] data_bar_fill_color <- data_bar_fill_color[1] + + rect_x <- y0_width + rect_width <- y_width - y0_width + } else if (y_vals[1] == 0) { - y_width <- 5 + data_bar_stroke_color <- "#808080" data_bar_stroke_width <- 4 data_bar_fill_color <- "#808080" + + rect_x <- y0_width - 2.5 + rect_width <- 5 } bar_tags <- paste0( " Date: Fri, 22 Dec 2023 23:11:30 -0500 Subject: [PATCH 7/9] Add a vertical 'zero' line scaled to bar thickness --- R/utils_plots.R | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/R/utils_plots.R b/R/utils_plots.R index 94878e2b0b..6e349c1865 100644 --- a/R/utils_plots.R +++ b/R/utils_plots.R @@ -1080,6 +1080,22 @@ generate_nanoplot <- function( ">", "" ) + + stroke <- "#BFBFBF" + stroke_width <- 5 + + zero_line_tags <- + paste0( + "", + "" + ) } # From 23d624768ce2243d973fdec43e1ba310027340ad Mon Sep 17 00:00:00 2001 From: Richard Iannone Date: Fri, 22 Dec 2023 23:11:49 -0500 Subject: [PATCH 8/9] Redefine the viewbox for horizontal bar plots --- R/utils_plots.R | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/R/utils_plots.R b/R/utils_plots.R index 6e349c1865..0f098bcbf2 100644 --- a/R/utils_plots.R +++ b/R/utils_plots.R @@ -1096,6 +1096,10 @@ generate_nanoplot <- function( ">", "" ) + + # Redefine the `viewbox` in terms of the `data_x_width` value; this ensures + # that the horizontal bars are centered about their extreme values + viewbox <- paste(left_x, top_y, data_x_width, bottom_y, collapse = " ") } # From 0e7f3a0457eb39fdde0ddf2c538c141aa15d5b04 Mon Sep 17 00:00:00 2001 From: Richard Iannone Date: Fri, 22 Dec 2023 23:12:02 -0500 Subject: [PATCH 9/9] Remove unneeded statements --- R/utils_plots.R | 4 ---- 1 file changed, 4 deletions(-) diff --git a/R/utils_plots.R b/R/utils_plots.R index 0f098bcbf2..2e08d4f5f0 100644 --- a/R/utils_plots.R +++ b/R/utils_plots.R @@ -1125,10 +1125,6 @@ generate_nanoplot <- function( ) } - if (plot_type == "bar" && single_horizontal_bar) { - zero_line_tags <- "" - } - # # Generate reference line #